This repository has been archived by the owner on May 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
genericSessionInfo_test.go
77 lines (62 loc) · 1.98 KB
/
genericSessionInfo_test.go
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 webwire
import (
"testing"
"github.com/stretchr/testify/require"
)
// TestGenericSessionInfoCopy tests the Copy method
// of the generic session info implementation
func TestGenericSessionInfoCopy(t *testing.T) {
original := SessionInfo(&GenericSessionInfo{
data: map[string]interface{}{
"field1": "value1",
"field2": "value2",
},
})
copied := original.Copy()
check := func() {
require.ElementsMatch(t, []string{"field1", "field2"}, copied.Fields())
require.Equal(t, "value1", copied.Value("field1"))
require.Equal(t, "value2", copied.Value("field2"))
}
// Verify consistency
check()
// Verify immutability
delete(original.(*GenericSessionInfo).data, "field1")
original.(*GenericSessionInfo).data["field2"] = "another_value"
original.(*GenericSessionInfo).data["field3"] = "another_value"
check()
}
// TestGenericSessionInfoValue tests the Value getter method
// of the generic session info implementation
func TestGenericSessionInfoValue(t *testing.T) {
info := SessionInfo(&GenericSessionInfo{
data: map[string]interface{}{
"string": "stringValue",
"float": 12.5,
"arrayOfStrings": []string{"item1", "item2"},
},
})
// Check types
require.IsType(t, float64(12.5), info.Value("float"))
require.IsType(t, []string{}, info.Value("arrayOfStrings"))
// Check values
require.Equal(t, "stringValue", info.Value("string"))
require.Equal(t, 12.5, info.Value("float"))
require.Equal(t, []string{"item1", "item2"}, info.Value("arrayOfStrings"))
// Check value of inexistent field
require.Nil(t, info.Value("inexistent"))
}
// TestGenericSessionInfoEmpty tests working with an empty
// generic session info instance
func TestGenericSessionInfoEmpty(t *testing.T) {
info := SessionInfo(&GenericSessionInfo{})
check := func(info SessionInfo) {
require.Equal(t, nil, info.Value("inexistent"))
require.Equal(t, make([]string, 0), info.Fields())
}
// Check values
check(info)
copied := info.Copy()
require.NotNil(t, copied)
check(copied)
}