Add GetCookies and SetCookies
This commit is contained in:
parent
deb946cf22
commit
f0d7735a76
6 changed files with 97 additions and 7 deletions
33
auth_test.go
Normal file
33
auth_test.go
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package twitterscraper_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
twitterscraper "github.com/n0madic/twitter-scraper"
|
||||
)
|
||||
|
||||
var (
|
||||
username = os.Getenv("TWITTER_USERNAME")
|
||||
password = os.Getenv("TWITTER_PASSWORD")
|
||||
)
|
||||
|
||||
func TestAuth(t *testing.T) {
|
||||
scraper := twitterscraper.New()
|
||||
if err := scraper.Login(username, password); err != nil {
|
||||
t.Fatalf("Login() error = %v", err)
|
||||
}
|
||||
if !scraper.IsLoggedIn() {
|
||||
t.Error("Expected IsLoggedIn() = true")
|
||||
}
|
||||
cookies := scraper.GetCookies()
|
||||
scraper.Logout()
|
||||
if scraper.IsLoggedIn() {
|
||||
t.Error("Expected IsLoggedIn() = false")
|
||||
}
|
||||
scraper2 := twitterscraper.New()
|
||||
scraper2.SetCookies(cookies)
|
||||
if !scraper2.IsLoggedIn() {
|
||||
t.Error("Expected restored IsLoggedIn() = true")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue