2017-04-14 17:15:51 +02:00
|
|
|
package context
|
|
|
|
|
|
|
|
import (
|
2019-03-03 19:12:22 +02:00
|
|
|
"os"
|
2022-02-01 03:36:22 +02:00
|
|
|
"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
|
|
|
|
2018-08-15 04:50:20 +02:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
2020-10-06 14:48:04 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
2017-04-14 17:15:51 +02:00
|
|
|
)
|
|
|
|
|
2017-12-17 19:18:46 +02:00
|
|
|
func TestNew(t *testing.T) {
|
2020-10-06 14:48:04 +02:00
|
|
|
require.NoError(t, os.Setenv("FOO", "NOT BAR"))
|
|
|
|
require.NoError(t, os.Setenv("BAR", "1"))
|
2021-04-25 19:20:49 +02:00
|
|
|
ctx := New(config.Project{
|
2019-03-03 19:12:22 +02:00
|
|
|
Env: []string{
|
|
|
|
"FOO=BAR",
|
|
|
|
},
|
|
|
|
})
|
2020-10-06 14:48:04 +02:00
|
|
|
require.Equal(t, "BAR", ctx.Env["FOO"])
|
|
|
|
require.Equal(t, "1", ctx.Env["BAR"])
|
|
|
|
require.Equal(t, 4, ctx.Parallelism)
|
2022-02-01 03:36:22 +02:00
|
|
|
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)
|
2020-10-06 14:48:04 +02:00
|
|
|
require.NotEmpty(t, ctx.Env)
|
|
|
|
require.Equal(t, 4, ctx.Parallelism)
|
2017-12-30 03:01:17 +02:00
|
|
|
cancel()
|
|
|
|
<-ctx.Done()
|
2020-10-06 14:48:04 +02:00
|
|
|
require.EqualError(t, ctx.Err(), `context canceled`)
|
2017-12-30 03:01:17 +02:00
|
|
|
}
|
2021-11-12 03:56:03 +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"}))
|
|
|
|
}
|