2021-08-31 16:48:45 +03:00
package reddit
import (
"testing"
2024-05-26 15:02:57 -03:00
"github.com/goreleaser/goreleaser/v2/internal/testctx"
"github.com/goreleaser/goreleaser/v2/internal/testlib"
"github.com/goreleaser/goreleaser/v2/pkg/config"
2021-08-31 16:48:45 +03:00
"github.com/stretchr/testify/require"
)
func TestStringer ( t * testing . T ) {
2023-12-17 15:34:28 -03:00
require . Equal ( t , "reddit" , Pipe { } . String ( ) )
2021-08-31 16:48:45 +03:00
}
func TestDefault ( t * testing . T ) {
2023-03-02 00:01:11 -03:00
ctx := testctx . New ( )
2021-08-31 16:48:45 +03:00
require . NoError ( t , Pipe { } . Default ( ctx ) )
2023-12-17 15:34:28 -03:00
require . Equal ( t , defaultTitleTemplate , ctx . Config . Announce . Reddit . TitleTemplate )
2021-08-31 16:48:45 +03:00
}
func TestAnnounceInvalidURLTemplate ( t * testing . T ) {
2023-03-02 00:01:11 -03:00
ctx := testctx . NewWithCfg ( config . Project {
2021-08-31 16:48:45 +03:00
Announce : config . Announce {
Reddit : config . Reddit {
URLTemplate : "{{ .Foo }" ,
} ,
} ,
} )
2023-08-24 22:06:12 -03:00
testlib . RequireTemplateError ( t , Pipe { } . Announce ( ctx ) )
2021-08-31 16:48:45 +03:00
}
func TestAnnounceInvalidTitleTemplate ( t * testing . T ) {
2023-03-02 00:01:11 -03:00
ctx := testctx . NewWithCfg ( config . Project {
2021-08-31 16:48:45 +03:00
Announce : config . Announce {
Reddit : config . Reddit {
TitleTemplate : "{{ .Foo }" ,
} ,
} ,
} )
2023-08-24 22:06:12 -03:00
testlib . RequireTemplateError ( t , Pipe { } . Announce ( ctx ) )
2021-08-31 16:48:45 +03:00
}
func TestAnnounceMissingEnv ( t * testing . T ) {
2023-03-02 00:01:11 -03:00
ctx := testctx . NewWithCfg ( config . Project {
2021-08-31 16:48:45 +03:00
Announce : config . Announce {
2021-09-18 10:21:29 -03:00
Reddit : config . Reddit { } ,
2021-08-31 16:48:45 +03:00
} ,
} )
require . NoError ( t , Pipe { } . Default ( ctx ) )
2022-12-28 12:24:21 -03:00
require . EqualError ( t , Pipe { } . Announce ( ctx ) , ` reddit: env: environment variable "REDDIT_SECRET" should not be empty; environment variable "REDDIT_PASSWORD" should not be empty ` )
2021-08-31 16:48:45 +03: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 {
Reddit : config . Reddit {
Enabled : true ,
} ,
2021-08-31 16:48:45 +03:00
} ,
2021-09-18 10:21:29 -03:00
} )
require . False ( t , Pipe { } . Skip ( ctx ) )
2021-08-31 16:48:45 +03:00
} )
}