2021-09-13 00:57:58 +02:00
|
|
|
package teams
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-03-02 00:01:11 -03:00
|
|
|
"github.com/goreleaser/goreleaser/internal/testctx"
|
2023-08-24 22:06:12 -03:00
|
|
|
"github.com/goreleaser/goreleaser/internal/testlib"
|
2021-09-13 00:57:58 +02:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestStringer(t *testing.T) {
|
|
|
|
require.Equal(t, Pipe{}.String(), "teams")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefault(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.New()
|
2021-09-13 00:57:58 +02:00
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
require.Equal(t, ctx.Config.Announce.Teams.MessageTemplate, defaultMessageTemplate)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAnnounceInvalidTemplate(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2021-09-13 00:57:58 +02:00
|
|
|
Announce: config.Announce{
|
|
|
|
Teams: config.Teams{
|
|
|
|
Enabled: true,
|
|
|
|
MessageTemplate: "{{ .Foo }",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2023-08-24 22:06:12 -03:00
|
|
|
testlib.RequireTemplateError(t, Pipe{}.Announce(ctx))
|
2021-09-13 00:57:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAnnounceMissingEnv(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2021-09-13 00:57:58 +02:00
|
|
|
Announce: config.Announce{
|
|
|
|
Teams: config.Teams{
|
|
|
|
Enabled: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
2022-12-28 12:24:21 -03:00
|
|
|
require.EqualError(t, Pipe{}.Announce(ctx), `teams: env: environment variable "TEAMS_WEBHOOK" should not be empty`)
|
2021-09-13 00:57:58 +02:00
|
|
|
}
|
|
|
|
|
2021-09-18 10:21:29 -03:00
|
|
|
func TestSkip(t *testing.T) {
|
|
|
|
t.Run("skip", func(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
require.True(t, Pipe{}.Skip(testctx.New()))
|
2021-09-18 10:21:29 -03:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("dont skip", func(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2021-09-18 10:21:29 -03:00
|
|
|
Announce: config.Announce{
|
|
|
|
Teams: config.Teams{
|
|
|
|
Enabled: true,
|
|
|
|
},
|
2021-09-13 00:57:58 +02:00
|
|
|
},
|
2021-09-18 10:21:29 -03:00
|
|
|
})
|
|
|
|
require.False(t, Pipe{}.Skip(ctx))
|
2021-09-13 00:57:58 +02:00
|
|
|
})
|
|
|
|
}
|