1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-19 20:57:53 +02:00

test: gpg: fixed local execution

This commit is contained in:
Carlos Alexandro Becker 2018-10-30 22:04:52 -03:00 committed by Carlos Alexandro Becker
parent b92acb3996
commit 19cde27da9
2 changed files with 23 additions and 7 deletions

View File

@ -6,6 +6,7 @@ import (
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"github.com/apex/log"
"github.com/goreleaser/goreleaser/internal/artifact" "github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/pipe" "github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/pkg/context" "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. // tells the scanner to ignore this.
// #nosec // #nosec
cmd := exec.CommandContext(ctx, cfg.Cmd, args...) cmd := exec.CommandContext(ctx, cfg.Cmd, args...)
log.WithField("cmd", cmd.Args).Info("running")
output, err := cmd.CombinedOutput() output, err := cmd.CombinedOutput()
if err != nil { if err != nil {
return "", fmt.Errorf("sign: %s failed with %q", cfg.Cmd, string(output)) return "", fmt.Errorf("sign: %s failed with %q", cfg.Cmd, string(output))

View File

@ -2,12 +2,15 @@ package sign
import ( import (
"bytes" "bytes"
"fmt"
"io/ioutil" "io/ioutil"
"math/rand"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"sort" "sort"
"testing" "testing"
"time"
"github.com/goreleaser/goreleaser/internal/artifact" "github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/pkg/config" "github.com/goreleaser/goreleaser/pkg/config"
@ -15,6 +18,21 @@ import (
"github.com/stretchr/testify/assert" "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) { func TestDescription(t *testing.T) {
assert.NotEmpty(t, Pipe{}.String()) assert.NotEmpty(t, Pipe{}.String())
} }
@ -50,9 +68,6 @@ func TestSignInvalidArtifacts(t *testing.T) {
} }
func TestSignArtifacts(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 { tests := []struct {
desc string desc string
ctx *context.Context ctx *context.Context
@ -78,14 +93,13 @@ func TestSignArtifacts(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, test := range tests {
t.Run(tt.desc, func(t *testing.T) { t.Run(test.desc, func(tt *testing.T) {
testSign(t, tt.ctx, tt.signatures) testSign(tt, test.ctx, test.signatures)
}) })
} }
} }
const keyring = "testdata/gnupg"
const user = "nopass" const user = "nopass"
func testSign(t *testing.T, ctx *context.Context, signatures []string) { func testSign(t *testing.T, ctx *context.Context, signatures []string) {