github.com/triarius/goreleaser@v1.12.5/internal/pipe/reddit/reddit_test.go (about)

     1  package reddit
     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 TestStringer(t *testing.T) {
    12  	require.Equal(t, Pipe{}.String(), "reddit")
    13  }
    14  
    15  func TestDefault(t *testing.T) {
    16  	ctx := context.New(config.Project{})
    17  	require.NoError(t, Pipe{}.Default(ctx))
    18  	require.Equal(t, ctx.Config.Announce.Reddit.TitleTemplate, defaultTitleTemplate)
    19  }
    20  
    21  func TestAnnounceInvalidURLTemplate(t *testing.T) {
    22  	ctx := context.New(config.Project{
    23  		Announce: config.Announce{
    24  			Reddit: config.Reddit{
    25  				URLTemplate: "{{ .Foo }",
    26  			},
    27  		},
    28  	})
    29  	require.EqualError(t, Pipe{}.Announce(ctx), `announce: failed to announce to reddit: template: tmpl:1: unexpected "}" in operand`)
    30  }
    31  
    32  func TestAnnounceInvalidTitleTemplate(t *testing.T) {
    33  	ctx := context.New(config.Project{
    34  		Announce: config.Announce{
    35  			Reddit: config.Reddit{
    36  				TitleTemplate: "{{ .Foo }",
    37  			},
    38  		},
    39  	})
    40  	require.EqualError(t, Pipe{}.Announce(ctx), `announce: failed to announce to reddit: template: tmpl:1: unexpected "}" in operand`)
    41  }
    42  
    43  func TestAnnounceMissingEnv(t *testing.T) {
    44  	ctx := context.New(config.Project{
    45  		Announce: config.Announce{
    46  			Reddit: config.Reddit{},
    47  		},
    48  	})
    49  	require.NoError(t, Pipe{}.Default(ctx))
    50  	require.EqualError(t, Pipe{}.Announce(ctx), `announce: failed to announce to reddit: env: environment variable "REDDIT_SECRET" should not be empty; environment variable "REDDIT_PASSWORD" should not be empty`)
    51  }
    52  
    53  func TestSkip(t *testing.T) {
    54  	t.Run("skip", func(t *testing.T) {
    55  		require.True(t, Pipe{}.Skip(context.New(config.Project{})))
    56  	})
    57  
    58  	t.Run("dont skip", func(t *testing.T) {
    59  		ctx := context.New(config.Project{
    60  			Announce: config.Announce{
    61  				Reddit: config.Reddit{
    62  					Enabled: true,
    63  				},
    64  			},
    65  		})
    66  		require.False(t, Pipe{}.Skip(ctx))
    67  	})
    68  }