/
metadata_test.go
70 lines (63 loc) · 1.64 KB
/
metadata_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package metadata
import (
"os"
"path/filepath"
"testing"
"time"
"github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/golden"
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context"
"github.com/stretchr/testify/require"
)
func TestRunWithError(t *testing.T) {
ctx := context.New(config.Project{
Dist: "testadata/nope",
ProjectName: "foo",
})
require.EqualError(t, Pipe{}.Run(ctx), `open testadata/nope/artifacts.json: no such file or directory`)
}
func TestRun(t *testing.T) {
tmp := t.TempDir()
ctx := context.New(config.Project{
Dist: tmp,
ProjectName: "name",
})
ctx.Runtime = context.Runtime{
Goos: "fakeos",
Goarch: "fakearch",
}
ctx.Version = "1.2.3"
ctx.Git = context.GitInfo{
CurrentTag: "v1.2.3",
PreviousTag: "v1.2.2",
Commit: "aef34a",
}
ctx.Date = time.Date(2022, 0o1, 22, 10, 12, 13, 0, time.UTC)
ctx.Artifacts.Add(&artifact.Artifact{
Name: "foo",
Path: "foo.txt",
Type: artifact.Binary,
Goos: "darwin",
Goarch: "amd64",
Goarm: "7",
Extra: map[string]interface{}{
"foo": "bar",
},
})
require.NoError(t, Pipe{}.Run(ctx))
t.Run("artifacts", func(t *testing.T) {
requireEqualJSONFile(t, tmp, "artifacts.json")
})
t.Run("metadata", func(t *testing.T) {
requireEqualJSONFile(t, tmp, "metadata.json")
})
}
func requireEqualJSONFile(tb testing.TB, tmp, s string) {
tb.Helper()
path := filepath.Join(tmp, s)
golden.RequireEqualJSON(tb, golden.RequireReadFile(tb, path))
info, err := os.Stat(path)
require.NoError(tb, err)
require.Equal(tb, "-rw-r--r--", info.Mode().String())
}