mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-21 21:07:19 +02:00
test: fix sign pipe tests (hopefully)
This commit is contained in:
parent
5ff07c38ea
commit
35e92aa0f4
@ -6,6 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/goreleaser/goreleaser/internal/artifact"
|
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||||
@ -91,7 +92,8 @@ func testSign(t *testing.T, ctx *context.Context, signatures []string) {
|
|||||||
ctx.Config.Dist = tmpdir
|
ctx.Config.Dist = tmpdir
|
||||||
|
|
||||||
// create some fake artifacts
|
// create some fake artifacts
|
||||||
for _, f := range []string{"artifact1", "artifact2", "checksum"} {
|
var artifacts = []string{"artifact1", "artifact2", "checksum"}
|
||||||
|
for _, f := range artifacts {
|
||||||
file := filepath.Join(tmpdir, f)
|
file := filepath.Join(tmpdir, f)
|
||||||
assert.NoError(t, ioutil.WriteFile(file, []byte("foo"), 0644))
|
assert.NoError(t, ioutil.WriteFile(file, []byte("foo"), 0644))
|
||||||
}
|
}
|
||||||
@ -126,13 +128,21 @@ func testSign(t *testing.T, ctx *context.Context, signatures []string) {
|
|||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
gotFiles = append(gotFiles, f.Name())
|
gotFiles = append(gotFiles, f.Name())
|
||||||
}
|
}
|
||||||
|
wantFiles := append(artifacts, signatures...)
|
||||||
assert.Contains(t, gotFiles, signatures)
|
sort.Strings(wantFiles)
|
||||||
|
assert.Equal(t, wantFiles, gotFiles)
|
||||||
|
|
||||||
// verify the signatures
|
// verify the signatures
|
||||||
for _, sig := range signatures {
|
for _, sig := range signatures {
|
||||||
verifySignature(t, ctx, sig)
|
verifySignature(t, ctx, sig)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var signArtifacts []string
|
||||||
|
for _, sig := range ctx.Artifacts.Filter(artifact.ByType(artifact.Signature)).List() {
|
||||||
|
signArtifacts = append(signArtifacts, sig.Name)
|
||||||
|
}
|
||||||
|
// check signature is an artifact
|
||||||
|
assert.Equal(t, signArtifacts, signatures)
|
||||||
}
|
}
|
||||||
|
|
||||||
func verifySignature(t *testing.T, ctx *context.Context, sig string) {
|
func verifySignature(t *testing.T, ctx *context.Context, sig string) {
|
||||||
@ -141,10 +151,7 @@ func verifySignature(t *testing.T, ctx *context.Context, sig string) {
|
|||||||
// verify signature was made with key for usesr 'nopass'
|
// verify signature was made with key for usesr 'nopass'
|
||||||
cmd := exec.Command("gpg", "--homedir", keyring, "--verify", filepath.Join(ctx.Config.Dist, sig), filepath.Join(ctx.Config.Dist, artifact))
|
cmd := exec.Command("gpg", "--homedir", keyring, "--verify", filepath.Join(ctx.Config.Dist, sig), filepath.Join(ctx.Config.Dist, artifact))
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
if err != nil {
|
assert.NoError(t, err)
|
||||||
t.Log(string(out))
|
|
||||||
t.Fatal("verify: ", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if the signature matches the user we expect to do this properly we
|
// check if the signature matches the user we expect to do this properly we
|
||||||
// might need to have either separate keyrings or export the key from the
|
// might need to have either separate keyrings or export the key from the
|
||||||
|
Loading…
x
Reference in New Issue
Block a user