Improve skip auth test

This commit is contained in:
Alexander Sheiko 2023-07-07 13:19:37 +03:00
parent 7393ab5136
commit 41b7e80ee8
3 changed files with 13 additions and 14 deletions

View file

@ -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()

View file

@ -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

View file

@ -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")