mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-06 03:13:48 +02:00
73e59160de
We have been using `t.Setenv` is most of our tests. This PR replaces the remaining `os.Setenv` with `t.Setenv`. Reference: https://pkg.go.dev/testing#T.Setenv ```go func TestFoo(t *testing.T) { // before os.Setenv(key, "new value") defer os.Unsetenv(key) // after t.Setenv(key, "new value") } ``` --------- Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
45 lines
857 B
Go
45 lines
857 B
Go
package testlib
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestCheckPath(t *testing.T) {
|
|
requireSkipped := func(tb testing.TB, skipped bool) {
|
|
tb.Helper()
|
|
t.Cleanup(func() {
|
|
require.Equalf(tb, skipped, tb.Skipped(), "expected skipped to be %v", skipped)
|
|
})
|
|
}
|
|
|
|
t.Run("local", func(t *testing.T) {
|
|
t.Setenv("CI", "false")
|
|
|
|
t.Run("in path", func(t *testing.T) {
|
|
requireSkipped(t, false)
|
|
CheckPath(t, "echo")
|
|
})
|
|
|
|
t.Run("not in path", func(t *testing.T) {
|
|
requireSkipped(t, true)
|
|
CheckPath(t, "do-not-exist")
|
|
})
|
|
})
|
|
|
|
t.Run("CI", func(t *testing.T) {
|
|
t.Setenv("CI", "true")
|
|
|
|
t.Run("in path on CI", func(t *testing.T) {
|
|
requireSkipped(t, false)
|
|
CheckPath(t, "echo")
|
|
})
|
|
|
|
t.Run("not in path on CI", func(t *testing.T) {
|
|
requireSkipped(t, false)
|
|
CheckPath(t, "do-not-exist")
|
|
})
|
|
})
|
|
}
|