forked from goreleaser/goreleaser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil_test.go
83 lines (68 loc) · 1.53 KB
/
util_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
71
72
73
74
75
76
77
78
79
80
81
82
83
package cmd
import (
"os"
"testing"
"github.com/goreleaser/goreleaser/v2/internal/testlib"
"github.com/stretchr/testify/require"
)
type exitMemento struct {
code int
}
func (e *exitMemento) Exit(i int) {
e.code = i
}
func setup(tb testing.TB) string {
tb.Helper()
_ = os.Unsetenv("GITHUB_TOKEN")
_ = os.Unsetenv("GITLAB_TOKEN")
_ = os.Unsetenv("GITEA_TOKEN")
previous, err := os.Getwd()
require.NoError(tb, err)
folder := tb.TempDir()
require.NoError(tb, os.Chdir(folder))
tb.Cleanup(func() {
require.NoError(tb, os.Chdir(previous))
})
createGoReleaserYaml(tb)
createMainGo(tb)
goModInit(tb)
testlib.GitInit(tb)
testlib.GitAdd(tb)
testlib.GitCommit(tb, "asdf")
testlib.GitTag(tb, "v0.0.1")
testlib.GitCommit(tb, "asas89d")
testlib.GitCommit(tb, "assssf")
testlib.GitCommit(tb, "assd")
testlib.GitTag(tb, "v0.0.2")
testlib.GitRemoteAdd(tb, "git@github.com:goreleaser/fake.git")
return folder
}
func createFile(tb testing.TB, filename, contents string) {
tb.Helper()
require.NoError(tb, os.WriteFile(filename, []byte(contents), 0o644))
}
func createMainGo(tb testing.TB) {
tb.Helper()
createFile(tb, "main.go", "package main\nfunc main() {println(0)}")
}
func goModInit(tb testing.TB) {
tb.Helper()
createFile(tb, "go.mod", `module foo
go 1.23
`)
}
func createGoReleaserYaml(tb testing.TB) {
tb.Helper()
yaml := `builds:
- binary: 'fake{{if .IsSnapshot}}_snapshot{{end}}'
goos:
- linux
goarch:
- amd64
release:
github:
owner: goreleaser
name: fake
`
createFile(tb, "goreleaser.yml", yaml)
}