diff --git a/internal/testlib/skip.go b/internal/testlib/skip.go new file mode 100644 index 000000000..1acef2a21 --- /dev/null +++ b/internal/testlib/skip.go @@ -0,0 +1,14 @@ +package testlib + +import ( + "testing" + + "github.com/goreleaser/goreleaser/pipeline" + "github.com/stretchr/testify/assert" +) + +// AssertSkipped asserts that a pipe was skipped +func AssertSkipped(t *testing.T, err error) { + _, ok := err.(pipeline.ErrSkip) + assert.True(t, ok) +} diff --git a/internal/testlib/skip_test.go b/internal/testlib/skip_test.go new file mode 100644 index 000000000..7cb9936b8 --- /dev/null +++ b/internal/testlib/skip_test.go @@ -0,0 +1,11 @@ +package testlib + +import ( + "testing" + + "github.com/goreleaser/goreleaser/pipeline" +) + +func TestAssertSkipped(t *testing.T) { + AssertSkipped(t, pipeline.Skip("skip")) +} diff --git a/pipeline/brew/brew_test.go b/pipeline/brew/brew_test.go index 29ea4ee2b..e1961db77 100644 --- a/pipeline/brew/brew_test.go +++ b/pipeline/brew/brew_test.go @@ -9,6 +9,7 @@ import ( "github.com/goreleaser/goreleaser/config" "github.com/goreleaser/goreleaser/context" + "github.com/goreleaser/goreleaser/internal/testlib" "github.com/stretchr/testify/assert" ) @@ -202,7 +203,7 @@ func TestRunPipeBrewNotSetup(t *testing.T) { Publish: true, } client := &DummyClient{} - assert.NoError(doRun(ctx, client)) + testlib.AssertSkipped(t, doRun(ctx, client)) assert.False(client.CreatedFile) } @@ -224,7 +225,7 @@ func TestRunPipeBinaryRelease(t *testing.T) { } ctx.AddBinary("darwinamd64", "foo", "bar", "baz") client := &DummyClient{} - assert.NoError(doRun(ctx, client)) + testlib.AssertSkipped(t, doRun(ctx, client)) assert.False(client.CreatedFile) } @@ -234,7 +235,7 @@ func TestRunPipeNoPublish(t *testing.T) { Publish: false, } client := &DummyClient{} - assert.NoError(doRun(ctx, client)) + testlib.AssertSkipped(t, doRun(ctx, client)) assert.False(client.CreatedFile) } @@ -255,7 +256,7 @@ func TestRunPipeDraftRelease(t *testing.T) { }, } client := &DummyClient{} - assert.NoError(doRun(ctx, client)) + testlib.AssertSkipped(t, doRun(ctx, client)) assert.False(client.CreatedFile) } @@ -269,7 +270,7 @@ func TestRunPipeFormatBinary(t *testing.T) { }, } client := &DummyClient{} - assert.NoError(doRun(ctx, client)) + testlib.AssertSkipped(t, doRun(ctx, client)) assert.False(client.CreatedFile) } diff --git a/pipeline/env/env_test.go b/pipeline/env/env_test.go index fe8d6f732..f4ba0cacf 100644 --- a/pipeline/env/env_test.go +++ b/pipeline/env/env_test.go @@ -7,6 +7,7 @@ import ( "github.com/goreleaser/goreleaser/config" "github.com/goreleaser/goreleaser/context" + "github.com/goreleaser/goreleaser/internal/testlib" "github.com/stretchr/testify/assert" ) @@ -61,7 +62,7 @@ func TestInvalidEnvChecksSkipped(t *testing.T) { Publish: flag.Publish, Snapshot: flag.Snapshot, } - assert.NoError(Pipe{}.Run(ctx)) + testlib.AssertSkipped(t, Pipe{}.Run(ctx)) }) } } diff --git a/pipeline/fpm/fpm_test.go b/pipeline/fpm/fpm_test.go index 2e8c0251b..b19e116b0 100644 --- a/pipeline/fpm/fpm_test.go +++ b/pipeline/fpm/fpm_test.go @@ -8,6 +8,7 @@ import ( "github.com/goreleaser/goreleaser/config" "github.com/goreleaser/goreleaser/context" + "github.com/goreleaser/goreleaser/internal/testlib" "github.com/stretchr/testify/assert" ) @@ -16,12 +17,11 @@ func TestDescription(t *testing.T) { } func TestRunPipeNoFormats(t *testing.T) { - var assert = assert.New(t) var ctx = &context.Context{ Version: "1.0.0", Config: config.Project{}, } - assert.NoError(Pipe{}.Run(ctx)) + testlib.AssertSkipped(t, Pipe{}.Run(ctx)) } func TestRunPipe(t *testing.T) { diff --git a/pipeline/git/git_test.go b/pipeline/git/git_test.go index 94af888ec..66d20b1cf 100644 --- a/pipeline/git/git_test.go +++ b/pipeline/git/git_test.go @@ -37,7 +37,7 @@ func TestSingleCommit(t *testing.T) { var ctx = &context.Context{ Config: config.Project{}, } - assert.NoError(Pipe{}.Run(ctx)) + testlib.AssertSkipped(t, Pipe{}.Run(ctx)) assert.Equal("v0.0.1", ctx.Git.CurrentTag) } @@ -67,7 +67,7 @@ func TestNoTagsSnapshot(t *testing.T) { Snapshot: true, Publish: false, } - assert.NoError(Pipe{}.Run(ctx)) + testlib.AssertSkipped(t, Pipe{}.Run(ctx)) assert.Contains(ctx.Version, "SNAPSHOT-") } @@ -182,7 +182,6 @@ func TestValidState(t *testing.T) { } func TestNoValidate(t *testing.T) { - var assert = assert.New(t) _, back := testlib.Mktmp(t) defer back() testlib.GitInit(t) @@ -194,7 +193,7 @@ func TestNoValidate(t *testing.T) { Config: config.Project{}, Validate: false, } - assert.NoError(Pipe{}.Run(ctx)) + testlib.AssertSkipped(t, Pipe{}.Run(ctx)) } func TestChangelog(t *testing.T) { @@ -210,7 +209,7 @@ func TestChangelog(t *testing.T) { var ctx = &context.Context{ Config: config.Project{}, } - assert.NoError(Pipe{}.Run(ctx)) + testlib.AssertSkipped(t, Pipe{}.Run(ctx)) assert.Equal("v0.0.2", ctx.Git.CurrentTag) assert.Contains(ctx.ReleaseNotes, "## Changelog") assert.NotContains(ctx.ReleaseNotes, "first") @@ -236,7 +235,7 @@ func TestChangelogOfFirstRelease(t *testing.T) { var ctx = &context.Context{ Config: config.Project{}, } - assert.NoError(Pipe{}.Run(ctx)) + testlib.AssertSkipped(t, Pipe{}.Run(ctx)) assert.Equal("v0.0.1", ctx.Git.CurrentTag) assert.Contains(ctx.ReleaseNotes, "## Changelog") for _, msg := range msgs { @@ -255,7 +254,7 @@ func TestCustomReleaseNotes(t *testing.T) { Config: config.Project{}, ReleaseNotes: "custom", } - assert.NoError(Pipe{}.Run(ctx)) + testlib.AssertSkipped(t, Pipe{}.Run(ctx)) assert.Equal("v0.0.1", ctx.Git.CurrentTag) assert.Equal(ctx.ReleaseNotes, "custom") } diff --git a/pipeline/release/release_test.go b/pipeline/release/release_test.go index ff06a191e..8b48a1dc4 100644 --- a/pipeline/release/release_test.go +++ b/pipeline/release/release_test.go @@ -10,6 +10,7 @@ import ( "github.com/goreleaser/goreleaser/config" "github.com/goreleaser/goreleaser/context" + "github.com/goreleaser/goreleaser/internal/testlib" "github.com/stretchr/testify/assert" ) @@ -121,7 +122,7 @@ func TestSkipPublish(t *testing.T) { Parallelism: 1, } client := &DummyClient{} - assert.NoError(doRun(ctx, client)) + testlib.AssertSkipped(t, doRun(ctx, client)) assert.False(client.CreatedRelease) assert.False(client.UploadedFile) }