1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/internal/pipe/publish/publish_test.go
Carlos Alexandro Becker 72cf8404c1
feat: continue on error (#4127)
closes #3989

Basically, when some of these pipes fail, the error will be memorized,
and all errors will be thrown in the end.

Meaning: the exit code will still be 1, but it'll not have stopped in
the first error.

Thinking of maybe adding a `--fail-fast` flag to disable this behavior
as well 🤔

---------

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
2023-06-20 09:33:59 -03:00

103 lines
2.3 KiB
Go

package publish
import (
"fmt"
"testing"
"github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/internal/testctx"
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context"
"github.com/hashicorp/go-multierror"
"github.com/stretchr/testify/require"
)
func TestDescription(t *testing.T) {
require.NotEmpty(t, Pipe{}.String())
}
func TestPublish(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
Release: config.Release{Disable: "true"},
}, testctx.GitHubTokenType)
require.NoError(t, New().Run(ctx))
}
func TestPublishSuccess(t *testing.T) {
ctx := testctx.New()
lastStep := &testPublisher{}
err := Pipe{
pipeline: []Publisher{
&testPublisher{},
&testPublisher{shouldSkip: true},
&testPublisher{
shouldErr: true,
continuable: true,
},
&testPublisher{shouldSkip: true},
&testPublisher{},
&testPublisher{shouldSkip: true},
lastStep,
},
}.Run(ctx)
require.Error(t, err)
merr := &multierror.Error{}
require.ErrorAs(t, err, &merr)
require.Equal(t, merr.Len(), 1)
require.True(t, lastStep.ran)
}
func TestPublishError(t *testing.T) {
ctx := testctx.New()
lastStep := &testPublisher{}
err := Pipe{
pipeline: []Publisher{
&testPublisher{},
&testPublisher{shouldSkip: true},
&testPublisher{
shouldErr: true,
continuable: true,
},
&testPublisher{},
&testPublisher{shouldSkip: true},
&testPublisher{},
&testPublisher{shouldErr: true},
lastStep,
},
}.Run(ctx)
require.Error(t, err)
require.EqualError(t, err, "test: failed to publish artifacts: errored")
require.False(t, lastStep.ran)
}
func TestSkip(t *testing.T) {
t.Run("skip", func(t *testing.T) {
ctx := testctx.New(testctx.SkipPublish)
require.True(t, Pipe{}.Skip(ctx))
})
t.Run("dont skip", func(t *testing.T) {
require.False(t, Pipe{}.Skip(testctx.New()))
})
}
type testPublisher struct {
shouldErr bool
shouldSkip bool
continuable bool
ran bool
}
func (t *testPublisher) ContinueOnError() bool { return t.continuable }
func (t *testPublisher) String() string { return "test" }
func (t *testPublisher) Publish(_ *context.Context) error {
if t.shouldSkip {
return pipe.Skip("skipped")
}
if t.shouldErr {
return fmt.Errorf("errored")
}
t.ran = true
return nil
}