gitee.com/mirrors_opencollective/goreleaser@v0.45.0/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/goreleaser/goreleaser/internal/testlib" 11 "github.com/stretchr/testify/assert" 12 ) 13 14 func TestDescription(t *testing.T) { 15 assert.NotEmpty(t, Pipe{}.String()) 16 } 17 18 func TestValidEnv(t *testing.T) { 19 assert.NoError(t, os.Setenv("GITHUB_TOKEN", "asdf")) 20 var ctx = &context.Context{ 21 Config: config.Project{}, 22 Validate: true, 23 Publish: true, 24 } 25 assert.NoError(t, Pipe{}.Run(ctx)) 26 } 27 28 func TestInvalidEnv(t *testing.T) { 29 assert.NoError(t, os.Unsetenv("GITHUB_TOKEN")) 30 var ctx = &context.Context{ 31 Config: config.Project{}, 32 Validate: true, 33 Publish: true, 34 } 35 assert.Error(t, Pipe{}.Run(ctx)) 36 } 37 38 type flags struct { 39 Validate, Publish, Snapshot bool 40 } 41 42 func TestInvalidEnvChecksSkipped(t *testing.T) { 43 for _, flag := range []flags{ 44 { 45 Validate: false, 46 Publish: true, 47 }, { 48 Validate: true, 49 Publish: false, 50 }, { 51 Validate: true, 52 }, 53 } { 54 t.Run(fmt.Sprintf("%v", flag), func(t *testing.T) { 55 assert.NoError(t, os.Unsetenv("GITHUB_TOKEN")) 56 var ctx = &context.Context{ 57 Config: config.Project{}, 58 Validate: flag.Validate, 59 Publish: flag.Publish, 60 Snapshot: flag.Snapshot, 61 } 62 testlib.AssertSkipped(t, Pipe{}.Run(ctx)) 63 }) 64 } 65 }