You've already forked goreleaser
mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-07-17 01:42:37 +02:00
test: wip fixing sign tests
This commit is contained in:
@ -46,6 +46,7 @@ func (Pipe) Run(ctx *context.Context) error {
|
|||||||
artifact.Or(
|
artifact.Or(
|
||||||
artifact.ByType(artifact.UploadableArchive),
|
artifact.ByType(artifact.UploadableArchive),
|
||||||
artifact.ByType(artifact.UploadableBinary),
|
artifact.ByType(artifact.UploadableBinary),
|
||||||
|
artifact.ByType(artifact.Checksum),
|
||||||
artifact.ByType(artifact.LinuxPackage),
|
artifact.ByType(artifact.LinuxPackage),
|
||||||
)).List())
|
)).List())
|
||||||
case "none":
|
case "none":
|
||||||
|
@ -6,9 +6,10 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||||
|
|
||||||
"github.com/goreleaser/goreleaser/config"
|
"github.com/goreleaser/goreleaser/config"
|
||||||
"github.com/goreleaser/goreleaser/context"
|
"github.com/goreleaser/goreleaser/context"
|
||||||
|
|
||||||
@ -44,9 +45,7 @@ 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
|
// fix permission on keyring dir to suppress warning about insecure permissions
|
||||||
if err := os.Chmod(keyring, 0700); err != nil {
|
assert.NoError(t, os.Chmod(keyring, 0700))
|
||||||
t.Fatal("Chmod: ", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
desc string
|
desc string
|
||||||
@ -55,24 +54,20 @@ func TestSignArtifacts(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
desc: "sign all artifacts",
|
desc: "sign all artifacts",
|
||||||
ctx: &context.Context{
|
ctx: context.New(
|
||||||
Config: config.Project{
|
config.Project{
|
||||||
Sign: config.Sign{Artifacts: "all"},
|
Sign: config.Sign{Artifacts: "all"},
|
||||||
},
|
},
|
||||||
Artifacts: []string{"artifact1", "artifact2", "checksum"},
|
),
|
||||||
Checksums: []string{"checksum"},
|
|
||||||
},
|
|
||||||
signatures: []string{"artifact1.sig", "artifact2.sig", "checksum.sig"},
|
signatures: []string{"artifact1.sig", "artifact2.sig", "checksum.sig"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "sign only checksums",
|
desc: "sign only checksums",
|
||||||
ctx: &context.Context{
|
ctx: context.New(
|
||||||
Config: config.Project{
|
config.Project{
|
||||||
Sign: config.Sign{Artifacts: "checksum"},
|
Sign: config.Sign{Artifacts: "checksum"},
|
||||||
},
|
},
|
||||||
Artifacts: []string{"artifact1", "artifact2", "checksum"},
|
),
|
||||||
Checksums: []string{"checksum"},
|
|
||||||
},
|
|
||||||
signatures: []string{"checksum.sig"},
|
signatures: []string{"checksum.sig"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -90,58 +85,54 @@ const user = "nopass"
|
|||||||
func testSign(t *testing.T, ctx *context.Context, signatures []string) {
|
func testSign(t *testing.T, ctx *context.Context, signatures []string) {
|
||||||
// create temp dir for file and signature
|
// create temp dir for file and signature
|
||||||
tmpdir, err := ioutil.TempDir("", "goreleaser")
|
tmpdir, err := ioutil.TempDir("", "goreleaser")
|
||||||
if err != nil {
|
assert.NoError(t, err)
|
||||||
t.Fatal("TempDir: ", err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(tmpdir)
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
ctx.Config.Dist = tmpdir
|
ctx.Config.Dist = tmpdir
|
||||||
|
|
||||||
// create some fake artifacts
|
// create some fake artifacts
|
||||||
artifacts := ctx.Artifacts
|
for _, f := range []string{"artifact1", "artifact2", "checksum"} {
|
||||||
for _, f := range artifacts {
|
|
||||||
file := filepath.Join(tmpdir, f)
|
file := filepath.Join(tmpdir, f)
|
||||||
if err2 := ioutil.WriteFile(file, []byte("foo"), 0644); err2 != nil {
|
assert.NoError(t, ioutil.WriteFile(file, []byte("foo"), 0644))
|
||||||
t.Fatal("WriteFile: ", err2)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
ctx.Artifacts.Add(artifact.Artifact{
|
||||||
|
Name: "artifact1",
|
||||||
|
Path: filepath.Join(tmpdir, "artifact1"),
|
||||||
|
Type: artifact.UploadableArchive,
|
||||||
|
})
|
||||||
|
ctx.Artifacts.Add(artifact.Artifact{
|
||||||
|
Name: "artifact2",
|
||||||
|
Path: filepath.Join(tmpdir, "artifact2"),
|
||||||
|
Type: artifact.UploadableArchive,
|
||||||
|
})
|
||||||
|
ctx.Artifacts.Add(artifact.Artifact{
|
||||||
|
Name: "checksum",
|
||||||
|
Path: filepath.Join(tmpdir, "checksum"),
|
||||||
|
Type: artifact.Checksum,
|
||||||
|
})
|
||||||
|
|
||||||
// configure the pipeline
|
// configure the pipeline
|
||||||
// make sure we are using the test keyring
|
// make sure we are using the test keyring
|
||||||
err = Pipe{}.Default(ctx)
|
assert.NoError(t, Pipe{}.Default(ctx))
|
||||||
if err != nil {
|
|
||||||
t.Fatal("Default: ", err)
|
|
||||||
}
|
|
||||||
ctx.Config.Sign.Args = append([]string{"--homedir", keyring}, ctx.Config.Sign.Args...)
|
ctx.Config.Sign.Args = append([]string{"--homedir", keyring}, ctx.Config.Sign.Args...)
|
||||||
|
|
||||||
// run the pipeline
|
// run the pipeline
|
||||||
err = Pipe{}.Run(ctx)
|
assert.NoError(t, Pipe{}.Run(ctx))
|
||||||
if err != nil {
|
|
||||||
t.Fatal("Run: ", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// verify that only the artifacts and the signatures are in the dist dir
|
// verify that only the artifacts and the signatures are in the dist dir
|
||||||
files, err := ioutil.ReadDir(tmpdir)
|
files, err := ioutil.ReadDir(tmpdir)
|
||||||
if err != nil {
|
assert.NoError(t, err)
|
||||||
t.Fatal("ReadDir: ", err)
|
|
||||||
}
|
|
||||||
gotFiles := []string{}
|
gotFiles := []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)
|
||||||
}
|
}
|
||||||
|
|
||||||
// check signature is an artifact
|
|
||||||
assert.Equal(t, ctx.Artifacts, append(artifacts, signatures...))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func verifySignature(t *testing.T, ctx *context.Context, sig string) {
|
func verifySignature(t *testing.T, ctx *context.Context, sig string) {
|
||||||
|
Reference in New Issue
Block a user