Repository navigation
Expand file tree
/
Copy pathtype_helpers_test.go
More file actions
47 lines (40 loc) · 1.5 KB
/
Copy pathtype_helpers_test.go
File metadata and controls
47 lines (40 loc) · 1.5 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
package playwright
import (
"testing"
"github.com/stretchr/testify/require"
)
func Test_assignFloatIfPresent(t *testing.T) {
t.Run("overrides target when key holds a float64", func(t *testing.T) {
target := -1.0
assignFloatIfPresent(map[string]any{"startTime": 123.0}, "startTime", &target)
require.Equal(t, 123.0, target)
})
t.Run("leaves target untouched when key is missing", func(t *testing.T) {
target := -1.0
assignFloatIfPresent(map[string]any{}, "startTime", &target)
require.Equal(t, -1.0, target)
})
t.Run("leaves target untouched when value is nil", func(t *testing.T) {
target := -1.0
assignFloatIfPresent(map[string]any{"startTime": nil}, "startTime", &target)
require.Equal(t, -1.0, target)
})
t.Run("leaves target untouched when value is not a float64", func(t *testing.T) {
target := -1.0
assignFloatIfPresent(map[string]any{"startTime": "not-a-float"}, "startTime", &target)
require.Equal(t, -1.0, target)
})
}
func TestToOptionalStorageStatePreservesCredentials(t *testing.T) {
state := StorageState{
Cookies: []Cookie{{Name: "a", Value: "b", Domain: "ex.com", Path: "/"}},
Origins: []Origin{{Origin: "https://ex.com", LocalStorage: []NameValue{{Name: "k", Value: "v"}}}},
Credentials: []VirtualCredential{{
Id: "id1", RpId: "ex.com", UserHandle: "u", PrivateKey: "pk", PublicKey: "pub",
}},
}
opt := state.ToOptionalStorageState()
require.Len(t, opt.Credentials, 1)
require.Equal(t, "id1", opt.Credentials[0].Id)
require.Equal(t, "a", opt.Cookies[0].Name)
}