@@ -566,42 +566,52 @@ func Test_SetSelectedAuth(t *testing.T) {
566566}
567567
568568func Test_IsAPIHostSlackDev (t * testing.T ) {
569-
570- var setup = func (t * testing.T ) (context.Context , * Client ) {
571- ctx := slackcontext .MockContext (t .Context ())
572- fsMock := slackdeps .NewFsMock ()
573- osMock := slackdeps .NewOsMock ()
574- osMock .AddDefaultMocks ()
575- config := config .NewConfig (fsMock , osMock )
576- ioMock := iostreams .NewIOStreamsMock (config , fsMock , osMock )
577- ioMock .AddDefaultMocks ()
578- authClient := NewClient (nil , nil , config , ioMock , fsMock )
579- return ctx , authClient
569+ tests := map [string ]struct {
570+ hostname string
571+ expected bool
572+ }{
573+ "blank host is false" : {
574+ hostname : "" ,
575+ expected : false ,
576+ },
577+ "not a url is false" : {
578+ hostname : "notAURL" ,
579+ expected : false ,
580+ },
581+ "unprefixed url is false" : {
582+ hostname : "https://doesnothaveprefix.com" ,
583+ expected : false ,
584+ },
585+ "production url is false" : {
586+ hostname : "https://slack.com" ,
587+ expected : false ,
588+ },
589+ "qa url is false" : {
590+ hostname : "https://qa.slack.com" ,
591+ expected : false ,
592+ },
593+ "numbered dev is true" : {
594+ hostname : "https://dev1234.slack.com" ,
595+ expected : true ,
596+ },
597+ "unnumbered dev is true" : {
598+ hostname : "https://dev.slack.com" ,
599+ expected : true ,
600+ },
601+ }
602+ for name , tt := range tests {
603+ t .Run (name , func (t * testing.T ) {
604+ fsMock := slackdeps .NewFsMock ()
605+ osMock := slackdeps .NewOsMock ()
606+ osMock .AddDefaultMocks ()
607+ config := config .NewConfig (fsMock , osMock )
608+ ioMock := iostreams .NewIOStreamsMock (config , fsMock , osMock )
609+ ioMock .AddDefaultMocks ()
610+ authClient := NewClient (nil , nil , config , ioMock , fsMock )
611+ actual := authClient .IsAPIHostSlackDev (tt .hostname )
612+ assert .Equal (t , tt .expected , actual )
613+ })
580614 }
581- _ , authClient := setup (t )
582-
583- mockHostName := ""
584- mockHostName1 := "notAURL"
585- mockHostName2 := "https://doesnothaveprefix.com"
586- mockHostName3 := "https://dev1234.slack.com"
587- mockHostName4 := "https://dev.slack.com"
588-
589- t .Run ("Should validate api host slack dev" , func (t * testing.T ) {
590- res := authClient .IsAPIHostSlackDev (mockHostName )
591- require .False (t , res )
592-
593- res = authClient .IsAPIHostSlackDev (mockHostName1 )
594- require .False (t , res )
595-
596- res = authClient .IsAPIHostSlackDev (mockHostName2 )
597- require .False (t , res )
598-
599- res = authClient .IsAPIHostSlackDev (mockHostName3 )
600- require .True (t , res )
601-
602- res = authClient .IsAPIHostSlackDev (mockHostName4 )
603- require .True (t , res )
604- })
605615}
606616
607617func Test_FilterKnownAuthErrors (t * testing.T ) {
0 commit comments