2021-05-25 00:19:06 -03:00
package twitter
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-05-25 00:19:06 -03:00
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/stretchr/testify/require"
)
func TestStringer ( t * testing . T ) {
require . Equal ( t , Pipe { } . String ( ) , "twitter" )
}
func TestDefault ( t * testing . T ) {
2023-03-02 00:01:11 -03:00
ctx := testctx . New ( )
2021-05-25 00:19:06 -03:00
require . NoError ( t , Pipe { } . Default ( ctx ) )
require . Equal ( t , ctx . Config . Announce . Twitter . MessageTemplate , defaultMessageTemplate )
}
func TestAnnounceInvalidTemplate ( t * testing . T ) {
2023-03-02 00:01:11 -03:00
ctx := testctx . NewWithCfg ( config . Project {
2021-05-25 00:19:06 -03:00
Announce : config . Announce {
Twitter : config . Twitter {
MessageTemplate : "{{ .Foo }" ,
} ,
} ,
} )
2023-08-24 22:06:12 -03:00
testlib . RequireTemplateError ( t , Pipe { } . Announce ( ctx ) )
2021-05-25 00:19:06 -03:00
}
func TestAnnounceMissingEnv ( t * testing . T ) {
2023-03-02 00:01:11 -03:00
ctx := testctx . NewWithCfg ( config . Project {
2021-05-25 00:19:06 -03:00
Announce : config . Announce {
2021-09-18 10:21:29 -03:00
Twitter : config . Twitter { } ,
2021-05-25 00:19:06 -03:00
} ,
} )
require . NoError ( t , Pipe { } . Default ( ctx ) )
2022-12-28 12:24:21 -03:00
require . EqualError ( t , Pipe { } . Announce ( ctx ) , ` twitter: env: environment variable "TWITTER_CONSUMER_KEY" should not be empty; environment variable "TWITTER_CONSUMER_SECRET" should not be empty; environment variable "TWITTER_ACCESS_TOKEN" should not be empty; environment variable "TWITTER_ACCESS_TOKEN_SECRET" should not be empty ` )
2021-05-25 00:19:06 -03:00
}
2021-05-25 00:45:59 -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 {
Twitter : config . Twitter {
Enabled : true ,
} ,
2021-05-25 00:45:59 -03:00
} ,
2021-09-18 10:21:29 -03:00
} )
require . False ( t , Pipe { } . Skip ( ctx ) )
2021-05-25 00:45:59 -03:00
} )
}