1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/pipeline/env/env_test.go
Carlos Alexandro Becker 1ed299a6d7 refactor: defaulter interface
Right now the code looks weird because the defaults
of a pipe are far away of the implementation of the pipe.

the intend of this PR is to bring them closer by having a
Defaulter interface.

I also renamed the Pipe interface to Piper, and removed
the Description method in favor for fmt.Stringer.
2017-12-03 13:00:01 -02:00

66 lines
1.3 KiB
Go

package env
import (
"fmt"
"os"
"testing"
"github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/context"
"github.com/goreleaser/goreleaser/internal/testlib"
"github.com/stretchr/testify/assert"
)
func TestDescription(t *testing.T) {
assert.NotEmpty(t, Pipe{}.String())
}
func TestValidEnv(t *testing.T) {
assert.NoError(t, os.Setenv("GITHUB_TOKEN", "asdf"))
var ctx = &context.Context{
Config: config.Project{},
Validate: true,
Publish: true,
}
assert.NoError(t, Pipe{}.Run(ctx))
}
func TestInvalidEnv(t *testing.T) {
assert.NoError(t, os.Unsetenv("GITHUB_TOKEN"))
var ctx = &context.Context{
Config: config.Project{},
Validate: true,
Publish: true,
}
assert.Error(t, Pipe{}.Run(ctx))
}
type flags struct {
Validate, Publish, Snapshot bool
}
func TestInvalidEnvChecksSkipped(t *testing.T) {
for _, flag := range []flags{
{
Validate: false,
Publish: true,
}, {
Validate: true,
Publish: false,
}, {
Validate: true,
},
} {
t.Run(fmt.Sprintf("%v", flag), func(t *testing.T) {
assert.NoError(t, os.Unsetenv("GITHUB_TOKEN"))
var ctx = &context.Context{
Config: config.Project{},
Validate: flag.Validate,
Publish: flag.Publish,
Snapshot: flag.Snapshot,
}
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
})
}
}