1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-22 04:08:49 +02:00
goreleaser/pkg/context/context_test.go
Carlos Alexandro Becker ec2db4a727
feat!: rename module to /v2 (#4894)
<!--

Hi, thanks for contributing!

Please make sure you read our CONTRIBUTING guide.

Also, add tests and the respective documentation changes as well.

-->


<!-- If applied, this commit will... -->

...

<!-- Why is this change being made? -->

...

<!-- # Provide links to any relevant tickets, URLs or other resources
-->

...

---------

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
2024-05-26 15:02:57 -03:00

41 lines
1.0 KiB
Go

package context
import (
"runtime"
"testing"
"time"
"github.com/goreleaser/goreleaser/v2/pkg/config"
"github.com/stretchr/testify/require"
)
func TestNew(t *testing.T) {
t.Setenv("FOO", "NOT BAR")
t.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)
}
func TestNewWithTimeout(t *testing.T) {
ctx, cancel := NewWithTimeout(config.Project{}, time.Second)
require.NotEmpty(t, ctx.Env)
require.Equal(t, 4, ctx.Parallelism)
cancel()
<-ctx.Done()
require.EqualError(t, ctx.Err(), `context canceled`)
}
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"}))
}