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