-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathutils_test.go
More file actions
52 lines (47 loc) · 1.2 KB
/
utils_test.go
File metadata and controls
52 lines (47 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package utils
import (
"os"
"strings"
"testing"
"github.com/joho/godotenv"
)
// TestMain loads environment variables for utils package tests.
func TestMain(m *testing.M) {
// Load .env vars for testing
godotenv.Load("../.env")
// Run tests
os.Exit(m.Run())
}
// TestInitChromeDp ensures chromedp contexts initialize in both headed and headless modes.
func TestInitChromeDp(t *testing.T) {
// Test with head
Headless = false
ctx, cancel := InitChromeDp()
if ctx.Err() != nil {
t.Errorf("Failed to initialize chromedp with head")
}
cancel()
// Test headless
Headless = true
ctx, cancel = InitChromeDp()
if ctx.Err() != nil {
t.Errorf("Failed to initialize chromedp headlessly")
}
cancel()
}
// TestRefreshToken confirms coursebook tokens refresh under both headless settings.
func TestRefreshToken(t *testing.T) {
// Get a chromedp context
ctx, cancel := InitChromeDp()
defer cancel()
// Try refreshing token
headers := RefreshToken(ctx)
// Make sure we successfully got a PTGSESSID cookie
for _, cookie := range headers["Cookie"] {
if strings.HasPrefix(cookie, "PTGSESSID") {
return
}
}
// Fail if no PTGSESSID cookie found
t.Fatalf("Failed to get PTGSESSID cookie from RefreshToken!")
}