github.com/triarius/goreleaser@v1.12.5/internal/pipe/announce/announce_test.go (about) 1 package announce 2 3 import ( 4 "testing" 5 6 "github.com/triarius/goreleaser/pkg/config" 7 "github.com/triarius/goreleaser/pkg/context" 8 "github.com/stretchr/testify/require" 9 ) 10 11 func TestDescription(t *testing.T) { 12 require.NotEmpty(t, Pipe{}.String()) 13 } 14 15 func TestAnnounce(t *testing.T) { 16 ctx := context.New(config.Project{ 17 Announce: config.Announce{ 18 Twitter: config.Twitter{ 19 Enabled: true, 20 }, 21 }, 22 }) 23 require.Error(t, Pipe{}.Run(ctx)) 24 } 25 26 func TestAnnounceAllDisabled(t *testing.T) { 27 ctx := context.New(config.Project{}) 28 require.NoError(t, Pipe{}.Run(ctx)) 29 } 30 31 func TestSkip(t *testing.T) { 32 t.Run("skip", func(t *testing.T) { 33 ctx := context.New(config.Project{}) 34 ctx.SkipAnnounce = true 35 require.True(t, Pipe{}.Skip(ctx)) 36 }) 37 38 t.Run("skip on patches", func(t *testing.T) { 39 ctx := context.New(config.Project{ 40 Announce: config.Announce{ 41 Skip: "{{gt .Patch 0}}", 42 }, 43 }) 44 ctx.Semver.Patch = 1 45 require.True(t, Pipe{}.Skip(ctx)) 46 }) 47 48 t.Run("skip on invalid template", func(t *testing.T) { 49 ctx := context.New(config.Project{ 50 Announce: config.Announce{ 51 Skip: "{{if eq .Patch 123}", 52 }, 53 }) 54 ctx.Semver.Patch = 1 55 require.True(t, Pipe{}.Skip(ctx)) 56 }) 57 58 t.Run("dont skip", func(t *testing.T) { 59 require.False(t, Pipe{}.Skip(context.New(config.Project{}))) 60 }) 61 62 t.Run("dont skip based on template", func(t *testing.T) { 63 ctx := context.New(config.Project{ 64 Announce: config.Announce{ 65 Skip: "{{gt .Patch 0}}", 66 }, 67 }) 68 ctx.Semver.Patch = 0 69 require.False(t, Pipe{}.Skip(ctx)) 70 }) 71 }