From 19cde27da9cce80d5c286738167ad83d8c82791c Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Tue, 30 Oct 2018 22:04:52 -0300 Subject: [PATCH] test: gpg: fixed local execution --- internal/pipe/sign/sign.go | 2 ++ internal/pipe/sign/sign_test.go | 28 +++++++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/internal/pipe/sign/sign.go b/internal/pipe/sign/sign.go index 9ed5922e0..96e068425 100644 --- a/internal/pipe/sign/sign.go +++ b/internal/pipe/sign/sign.go @@ -6,6 +6,7 @@ import ( "os/exec" "path/filepath" + "github.com/apex/log" "github.com/goreleaser/goreleaser/internal/artifact" "github.com/goreleaser/goreleaser/internal/pipe" "github.com/goreleaser/goreleaser/pkg/context" @@ -99,6 +100,7 @@ func signone(ctx *context.Context, artifact artifact.Artifact) (string, error) { // tells the scanner to ignore this. // #nosec cmd := exec.CommandContext(ctx, cfg.Cmd, args...) + log.WithField("cmd", cmd.Args).Info("running") output, err := cmd.CombinedOutput() if err != nil { return "", fmt.Errorf("sign: %s failed with %q", cfg.Cmd, string(output)) diff --git a/internal/pipe/sign/sign_test.go b/internal/pipe/sign/sign_test.go index 8df7ff1f8..ec6301063 100644 --- a/internal/pipe/sign/sign_test.go +++ b/internal/pipe/sign/sign_test.go @@ -2,12 +2,15 @@ package sign import ( "bytes" + "fmt" "io/ioutil" + "math/rand" "os" "os/exec" "path/filepath" "sort" "testing" + "time" "github.com/goreleaser/goreleaser/internal/artifact" "github.com/goreleaser/goreleaser/pkg/config" @@ -15,6 +18,21 @@ import ( "github.com/stretchr/testify/assert" ) +var originKeyring = "testdata/gnupg" +var keyring string + +func TestMain(m *testing.M) { + rand.Seed(time.Now().UnixNano()) + keyring = fmt.Sprintf("/tmp/gorel_gpg_test.%d", rand.Int()) + fmt.Println("copying", originKeyring, "to", keyring) + if _, err := exec.Command("cp", "-Rf", originKeyring, keyring).CombinedOutput(); err != nil { + fmt.Printf("failed to copy %s to %s: %s", originKeyring, keyring, err) + os.Exit(1) + } + defer os.RemoveAll(keyring) + os.Exit(m.Run()) +} + func TestDescription(t *testing.T) { assert.NotEmpty(t, Pipe{}.String()) } @@ -50,9 +68,6 @@ func TestSignInvalidArtifacts(t *testing.T) { } func TestSignArtifacts(t *testing.T) { - // fix permission on keyring dir to suppress warning about insecure permissions - assert.NoError(t, os.Chmod(keyring, 0700)) - tests := []struct { desc string ctx *context.Context @@ -78,14 +93,13 @@ func TestSignArtifacts(t *testing.T) { }, } - for _, tt := range tests { - t.Run(tt.desc, func(t *testing.T) { - testSign(t, tt.ctx, tt.signatures) + for _, test := range tests { + t.Run(test.desc, func(tt *testing.T) { + testSign(tt, test.ctx, test.signatures) }) } } -const keyring = "testdata/gnupg" const user = "nopass" func testSign(t *testing.T, ctx *context.Context, signatures []string) {