2021-05-25 05:19:06 +02:00
|
|
|
package announce
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-09-16 22:01:20 +02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/skips"
|
2023-03-02 05:01:11 +02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/testctx"
|
2021-05-25 05:19:06 +02:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
2022-12-28 17:24:21 +02:00
|
|
|
"github.com/hashicorp/go-multierror"
|
2021-05-25 05:19:06 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDescription(t *testing.T) {
|
|
|
|
require.NotEmpty(t, Pipe{}.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAnnounce(t *testing.T) {
|
2023-03-02 05:01:11 +02:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2021-09-18 15:21:29 +02:00
|
|
|
Announce: config.Announce{
|
|
|
|
Twitter: config.Twitter{
|
|
|
|
Enabled: true,
|
|
|
|
},
|
2022-12-28 17:24:21 +02:00
|
|
|
Mastodon: config.Mastodon{
|
|
|
|
Enabled: true,
|
|
|
|
Server: "https://localhost:1234/",
|
|
|
|
},
|
2021-09-18 15:21:29 +02:00
|
|
|
},
|
|
|
|
})
|
2022-12-28 17:24:21 +02:00
|
|
|
err := Pipe{}.Run(ctx)
|
|
|
|
require.Error(t, err)
|
|
|
|
merr := &multierror.Error{}
|
2023-12-17 20:34:28 +02:00
|
|
|
require.ErrorAs(t, err, &merr, "must be a multierror")
|
2022-12-28 17:24:21 +02:00
|
|
|
require.Len(t, merr.Errors, 2)
|
2021-09-18 15:21:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAnnounceAllDisabled(t *testing.T) {
|
2023-03-02 05:01:11 +02:00
|
|
|
ctx := testctx.New()
|
2021-05-25 05:19:06 +02:00
|
|
|
require.NoError(t, Pipe{}.Run(ctx))
|
|
|
|
}
|
2021-09-18 15:21:29 +02:00
|
|
|
|
|
|
|
func TestSkip(t *testing.T) {
|
|
|
|
t.Run("skip", func(t *testing.T) {
|
2023-09-16 22:01:20 +02:00
|
|
|
ctx := testctx.New(testctx.Skip(skips.Announce))
|
2023-01-29 04:21:43 +02:00
|
|
|
b, err := Pipe{}.Skip(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, b)
|
2021-09-18 15:21:29 +02:00
|
|
|
})
|
|
|
|
|
2021-09-29 03:33:04 +02:00
|
|
|
t.Run("skip on patches", func(t *testing.T) {
|
2023-03-02 05:01:11 +02:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2021-09-29 03:33:04 +02:00
|
|
|
Announce: config.Announce{
|
|
|
|
Skip: "{{gt .Patch 0}}",
|
|
|
|
},
|
2023-03-02 05:01:11 +02:00
|
|
|
}, testctx.WithSemver(0, 0, 1, ""))
|
2023-01-29 04:21:43 +02:00
|
|
|
b, err := Pipe{}.Skip(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, b)
|
2021-09-29 03:33:04 +02:00
|
|
|
})
|
|
|
|
|
2023-01-29 04:21:43 +02:00
|
|
|
t.Run("invalid template", func(t *testing.T) {
|
2023-03-02 05:01:11 +02:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2021-09-29 03:33:04 +02:00
|
|
|
Announce: config.Announce{
|
|
|
|
Skip: "{{if eq .Patch 123}",
|
|
|
|
},
|
2023-03-02 05:01:11 +02:00
|
|
|
}, testctx.WithSemver(0, 0, 1, ""))
|
2023-01-29 04:21:43 +02:00
|
|
|
_, err := Pipe{}.Skip(ctx)
|
|
|
|
require.Error(t, err)
|
2021-09-29 03:33:04 +02:00
|
|
|
})
|
|
|
|
|
2021-09-18 15:21:29 +02:00
|
|
|
t.Run("dont skip", func(t *testing.T) {
|
2023-03-02 05:01:11 +02:00
|
|
|
b, err := Pipe{}.Skip(testctx.New())
|
2023-01-29 04:21:43 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.False(t, b)
|
2021-09-18 15:21:29 +02:00
|
|
|
})
|
2021-09-29 03:33:04 +02:00
|
|
|
|
|
|
|
t.Run("dont skip based on template", func(t *testing.T) {
|
2023-03-02 05:01:11 +02:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2021-09-29 03:33:04 +02:00
|
|
|
Announce: config.Announce{
|
|
|
|
Skip: "{{gt .Patch 0}}",
|
|
|
|
},
|
|
|
|
})
|
2023-01-29 04:21:43 +02:00
|
|
|
b, err := Pipe{}.Skip(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.False(t, b)
|
2021-09-29 03:33:04 +02:00
|
|
|
})
|
2021-09-18 15:21:29 +02:00
|
|
|
}
|