1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-08 03:31:59 +02:00
goreleaser/cmd/util_test.go
Carlos Alexandro Becker 7186e5b93e
chore(deps): remove tj/assert
Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
2020-06-01 09:43:18 -03:00

75 lines
1.4 KiB
Go

package cmd
import (
"io/ioutil"
"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(t *testing.T) (current string, back func()) {
_ = os.Unsetenv("GITHUB_TOKEN")
_ = os.Unsetenv("GITLAB_TOKEN")
folder, err := ioutil.TempDir("", "")
require.NoError(t, err)
previous, err := os.Getwd()
require.NoError(t, err)
require.NoError(t, os.Chdir(folder))
createGoreleaserYaml(t)
createMainGo(t)
goModInit(t)
testlib.GitInit(t)
testlib.GitAdd(t)
testlib.GitCommit(t, "asdf")
testlib.GitTag(t, "v0.0.1")
testlib.GitCommit(t, "asas89d")
testlib.GitCommit(t, "assssf")
testlib.GitCommit(t, "assd")
testlib.GitTag(t, "v0.0.2")
testlib.GitRemoteAdd(t, "git@github.com:goreleaser/fake.git")
return folder, func() {
require.NoError(t, os.Chdir(previous))
}
}
func createFile(t *testing.T, filename, contents string) {
require.NoError(t, ioutil.WriteFile(filename, []byte(contents), 0644))
}
func createMainGo(t *testing.T) {
createFile(t, "main.go", "package main\nfunc main() {println(0)}")
}
func goModInit(t *testing.T) {
createFile(t, "go.mod", `module foo
go 1.14
`)
}
func createGoreleaserYaml(t *testing.T) {
var yaml = `build:
binary: fake
goos:
- linux
goarch:
- amd64
release:
github:
owner: goreleaser
name: fake
`
createFile(t, "goreleaser.yml", yaml)
}