1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/pkg/context/context_test.go

42 lines
1.1 KiB
Go
Raw Normal View History

2017-04-14 17:15:51 +02:00
package context
import (
"os"
"runtime"
2017-04-14 17:15:51 +02:00
"testing"
2017-12-30 03:01:17 +02:00
"time"
2017-04-14 17:15:51 +02:00
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/stretchr/testify/require"
2017-04-14 17:15:51 +02:00
)
func TestNew(t *testing.T) {
require.NoError(t, os.Setenv("FOO", "NOT BAR"))
require.NoError(t, os.Setenv("BAR", "1"))
ctx := New(config.Project{
Env: []string{
"FOO=BAR",
},
})
require.Equal(t, "BAR", ctx.Env["FOO"])
require.Equal(t, "1", ctx.Env["BAR"])
require.Equal(t, 4, ctx.Parallelism)
require.Equal(t, runtime.GOOS, ctx.Runtime.Goos)
require.Equal(t, runtime.GOARCH, ctx.Runtime.Goarch)
2017-07-02 02:34:32 +02:00
}
2017-12-30 03:01:17 +02:00
func TestNewWithTimeout(t *testing.T) {
ctx, cancel := NewWithTimeout(config.Project{}, time.Second)
require.NotEmpty(t, ctx.Env)
require.Equal(t, 4, ctx.Parallelism)
2017-12-30 03:01:17 +02:00
cancel()
<-ctx.Done()
require.EqualError(t, ctx.Err(), `context canceled`)
2017-12-30 03:01:17 +02:00
}
func TestToEnv(t *testing.T) {
require.Equal(t, Env{"FOO": "BAR"}, ToEnv([]string{"=nope", "FOO=BAR"}))
require.Equal(t, Env{"FOO": "BAR"}, ToEnv([]string{"nope", "FOO=BAR"}))
require.Equal(t, Env{"FOO": "BAR", "nope": ""}, ToEnv([]string{"nope=", "FOO=BAR"}))
}