github.com/marianogappa/goreleaser@v0.26.2-0.20170715090149-96acd0a9fc46/pipeline/env/env_test.go (about) 1 package env 2 3 import ( 4 "fmt" 5 "os" 6 "testing" 7 8 "github.com/goreleaser/goreleaser/config" 9 "github.com/goreleaser/goreleaser/context" 10 "github.com/stretchr/testify/assert" 11 ) 12 13 func TestDescription(t *testing.T) { 14 assert.NotEmpty(t, Pipe{}.Description()) 15 } 16 17 func TestValidEnv(t *testing.T) { 18 assert := assert.New(t) 19 assert.NoError(os.Setenv("GITHUB_TOKEN", "asdf")) 20 var ctx = &context.Context{ 21 Config: config.Project{}, 22 Validate: true, 23 Publish: true, 24 } 25 assert.NoError(Pipe{}.Run(ctx)) 26 } 27 28 func TestInvalidEnv(t *testing.T) { 29 assert := assert.New(t) 30 assert.NoError(os.Unsetenv("GITHUB_TOKEN")) 31 var ctx = &context.Context{ 32 Config: config.Project{}, 33 Validate: true, 34 Publish: true, 35 } 36 assert.Error(Pipe{}.Run(ctx)) 37 } 38 39 type flags struct { 40 Validate, Publish, Snapshot bool 41 } 42 43 func TestInvalidEnvChecksSkipped(t *testing.T) { 44 for _, flag := range []flags{ 45 { 46 Validate: false, 47 Publish: true, 48 }, { 49 Validate: true, 50 Publish: false, 51 }, { 52 Validate: true, 53 }, 54 } { 55 t.Run(fmt.Sprintf("%v", flag), func(t *testing.T) { 56 var assert = assert.New(t) 57 assert.NoError(os.Unsetenv("GITHUB_TOKEN")) 58 var ctx = &context.Context{ 59 Config: config.Project{}, 60 Validate: flag.Validate, 61 Publish: flag.Publish, 62 Snapshot: flag.Snapshot, 63 } 64 assert.NoError(Pipe{}.Run(ctx)) 65 }) 66 } 67 }