diff --git a/auth_test.go b/auth_test.go index 1c3680b..88bfd68 100644 --- a/auth_test.go +++ b/auth_test.go @@ -9,14 +9,15 @@ import ( ) var ( - username = os.Getenv("TWITTER_USERNAME") - password = os.Getenv("TWITTER_PASSWORD") - email = os.Getenv("TWITTER_EMAIL") - testScraper = twitterscraper.New() + username = os.Getenv("TWITTER_USERNAME") + password = os.Getenv("TWITTER_PASSWORD") + email = os.Getenv("TWITTER_EMAIL") + skipAuthTest = os.Getenv("SKIP_AUTH_TEST") != "" + testScraper = twitterscraper.New() ) func init() { - if username != "" && password != "" { + if username != "" && password != "" && !skipAuthTest { err := testScraper.Login(username, password, email) if err != nil { panic(fmt.Sprintf("Login() error = %v", err)) @@ -25,7 +26,7 @@ func init() { } func TestAuth(t *testing.T) { - if os.Getenv("SKIP_AUTH_TEST") != "" { + if skipAuthTest { t.Skip("Skipping test due to environment variable") } scraper := twitterscraper.New() diff --git a/search_test.go b/search_test.go index b75eb01..36c61bc 100644 --- a/search_test.go +++ b/search_test.go @@ -2,14 +2,13 @@ package twitterscraper_test import ( "context" - "os" "testing" twitterscraper "github.com/n0madic/twitter-scraper" ) func TestFetchSearchCursor(t *testing.T) { - if os.Getenv("SKIP_AUTH_TEST") != "" { + if skipAuthTest { t.Skip("Skipping test due to environment variable") } @@ -30,7 +29,7 @@ func TestFetchSearchCursor(t *testing.T) { } func TestGetSearchProfiles(t *testing.T) { - if os.Getenv("SKIP_AUTH_TEST") != "" { + if skipAuthTest { t.Skip("Skipping test due to environment variable") } count := 0 @@ -59,7 +58,7 @@ func TestGetSearchProfiles(t *testing.T) { } } func TestGetSearchTweets(t *testing.T) { - if os.Getenv("SKIP_AUTH_TEST") != "" { + if skipAuthTest { t.Skip("Skipping test due to environment variable") } count := 0 diff --git a/tweets_test.go b/tweets_test.go index 1c0df01..71960c1 100644 --- a/tweets_test.go +++ b/tweets_test.go @@ -2,7 +2,6 @@ package twitterscraper_test import ( "context" - "os" "testing" "time" @@ -128,7 +127,7 @@ func TestGetTweetWithMultiplePhotos(t *testing.T) { } func TestGetTweetWithGIF(t *testing.T) { - if os.Getenv("SKIP_AUTH_TEST") != "" { + if skipAuthTest { t.Skip("Skipping test due to environment variable") } expectedTweet := twitterscraper.Tweet{ @@ -155,7 +154,7 @@ func TestGetTweetWithGIF(t *testing.T) { } func TestGetTweetWithPhotoAndGIF(t *testing.T) { - if os.Getenv("SKIP_AUTH_TEST") != "" { + if skipAuthTest { t.Skip("Skipping test due to environment variable") } expectedTweet := twitterscraper.Tweet{ @@ -299,7 +298,7 @@ func TestTweetViews(t *testing.T) { } func TestTweetThread(t *testing.T) { - if os.Getenv("SKIP_AUTH_TEST") != "" { + if skipAuthTest { t.Skip("Skipping test due to environment variable") } tweet, err := testScraper.GetTweet("1665602315745673217")