2017-03-25 20:40:45 -03:00
|
|
|
package env
|
|
|
|
|
|
|
|
import (
|
2017-05-01 10:23:28 -03:00
|
|
|
"fmt"
|
2017-03-25 20:40:45 -03:00
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/goreleaser/goreleaser/config"
|
|
|
|
"github.com/goreleaser/goreleaser/context"
|
2017-08-20 16:50:34 -03:00
|
|
|
"github.com/goreleaser/goreleaser/internal/testlib"
|
2017-03-25 20:40:45 -03:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDescription(t *testing.T) {
|
|
|
|
assert.NotEmpty(t, Pipe{}.Description())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestValidEnv(t *testing.T) {
|
2017-09-26 19:24:49 -03:00
|
|
|
assert.NoError(t, os.Setenv("GITHUB_TOKEN", "asdf"))
|
2017-03-25 20:40:45 -03:00
|
|
|
var ctx = &context.Context{
|
2017-04-18 13:10:13 -03:00
|
|
|
Config: config.Project{},
|
|
|
|
Validate: true,
|
2017-04-29 12:49:22 +02:00
|
|
|
Publish: true,
|
2017-03-25 20:40:45 -03:00
|
|
|
}
|
2017-09-26 19:24:49 -03:00
|
|
|
assert.NoError(t, Pipe{}.Run(ctx))
|
2017-03-25 20:40:45 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestInvalidEnv(t *testing.T) {
|
2017-09-26 19:24:49 -03:00
|
|
|
assert.NoError(t, os.Unsetenv("GITHUB_TOKEN"))
|
2017-03-25 20:40:45 -03:00
|
|
|
var ctx = &context.Context{
|
2017-04-18 13:10:13 -03:00
|
|
|
Config: config.Project{},
|
|
|
|
Validate: true,
|
2017-04-29 12:49:22 +02:00
|
|
|
Publish: true,
|
2017-03-25 20:40:45 -03:00
|
|
|
}
|
2017-09-26 19:24:49 -03:00
|
|
|
assert.Error(t, Pipe{}.Run(ctx))
|
2017-03-25 20:40:45 -03:00
|
|
|
}
|
2017-04-18 13:10:13 -03:00
|
|
|
|
2017-05-01 10:23:28 -03:00
|
|
|
type flags struct {
|
|
|
|
Validate, Publish, Snapshot bool
|
2017-04-29 12:49:22 +02:00
|
|
|
}
|
|
|
|
|
2017-05-01 10:23:28 -03:00
|
|
|
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) {
|
2017-09-26 19:24:49 -03:00
|
|
|
assert.NoError(t, os.Unsetenv("GITHUB_TOKEN"))
|
2017-05-01 10:23:28 -03:00
|
|
|
var ctx = &context.Context{
|
|
|
|
Config: config.Project{},
|
|
|
|
Validate: flag.Validate,
|
|
|
|
Publish: flag.Publish,
|
|
|
|
Snapshot: flag.Snapshot,
|
|
|
|
}
|
2017-08-20 16:50:34 -03:00
|
|
|
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
2017-05-01 10:23:28 -03:00
|
|
|
})
|
2017-04-18 13:10:13 -03:00
|
|
|
}
|
|
|
|
}
|