-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcoverage_remaining_test.go
More file actions
77 lines (70 loc) · 2.16 KB
/
coverage_remaining_test.go
File metadata and controls
77 lines (70 loc) · 2.16 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package sweetcookie
import (
"context"
"os"
"path/filepath"
"runtime"
"testing"
)
func TestReadFromBrowser_InlineAndUnknown(t *testing.T) {
// Inline is handled separately; browser dispatch should be a no-op.
if cookies, warnings, err := readFromBrowser(context.Background(), BrowserInline, nil, Options{}); err != nil || len(warnings) != 0 || len(cookies) != 0 {
t.Fatalf("unexpected: %v %v %v", cookies, warnings, err)
}
_, warnings, _ := readFromBrowser(context.Background(), Browser("nope"), nil, Options{})
if len(warnings) == 0 {
t.Fatal("expected warning")
}
}
func TestFirefoxRowToCookie_SetsDefaultPath(t *testing.T) {
c, ok := firefoxRowToCookie(firefoxDB{path: "x", profile: "p"}, firefoxRow{
host: ".example.com",
name: "a",
value: "b",
path: "",
})
if !ok {
t.Fatal("expected ok")
}
if c.Path != "/" {
t.Fatalf("want / got %q", c.Path)
}
if c.Expires != nil {
t.Fatal("expected nil expires")
}
}
func TestChromiumHostWhereClause_EmptyHosts(t *testing.T) {
where, args := chromiumHostWhereClause(nil)
if where != "1=1" || len(args) != 0 {
t.Fatalf("unexpected: %q %v", where, args)
}
}
func TestFirefoxHostWhereClause_EmptyHosts(t *testing.T) {
where, args := firefoxHostWhereClause(nil)
if where != "1=1" || len(args) != 0 {
t.Fatalf("unexpected: %q %v", where, args)
}
}
func TestChromiumResolveStoreFromOverride_MissingProfileName(t *testing.T) {
if runtime.GOOS == "darwin" {
t.Setenv("HOME", t.TempDir())
}
stores, warnings := chromiumResolveStoreFromOverride(BrowserChrome, "NoSuchProfile")
if len(stores) != 0 || len(warnings) == 0 {
t.Fatalf("expected warnings: %v %v", stores, warnings)
}
}
func TestChromiumResolveStoreFromOverride_ProfileDir(t *testing.T) {
dir := t.TempDir()
profileDir := filepath.Join(dir, "Default")
if err := os.MkdirAll(filepath.Join(profileDir, "Network"), 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(profileDir, "Network", "Cookies"), []byte{}, 0o644); err != nil {
t.Fatal(err)
}
stores, warnings := chromiumResolveStoreFromOverride(BrowserChrome, profileDir)
if len(warnings) != 0 || len(stores) == 0 {
t.Fatalf("unexpected: %v %v", stores, warnings)
}
}