1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-06 03:13:48 +02:00
goreleaser/cmd/util_test.go
Carlos Alexandro Becker 2bf08f11a6
ci: run build/test workflow on windows too (#5263)
Maybe 3rd time is the charm!

This makes the CI build run on windows too, and fix broken tests/featuers on Windows.

Most of the changes are related to ignoring certain tests on windows, or making sure to use the right path separators.

More work to do in the future, probably!

#4293

---------

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
2024-11-16 10:30:39 -03:00

84 lines
1.5 KiB
Go

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)
}