1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2024-12-31 01:53:50 +02:00
goreleaser/cmd/util_test.go
Carlos Alexandro Becker a33a1871b0
refactor: improve method name
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
2023-04-30 00:03:03 +00:00

84 lines
1.5 KiB
Go

package cmd
import (
"os"
"testing"
"github.com/goreleaser/goreleaser/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")
previous, err := os.Getwd()
require.NoError(tb, err)
tb.Cleanup(func() {
require.NoError(tb, os.Chdir(previous))
})
folder := tb.TempDir()
require.NoError(tb, os.Chdir(folder))
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.20
`)
}
func createGoReleaserYaml(tb testing.TB) {
tb.Helper()
yaml := `build:
binary: fake
goos:
- linux
goarch:
- amd64
release:
github:
owner: goreleaser
name: fake
`
createFile(tb, "goreleaser.yml", yaml)
}