-
Notifications
You must be signed in to change notification settings - Fork 7
/
websocket_push_session_mock_test.go
62 lines (51 loc) · 1.74 KB
/
websocket_push_session_mock_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
package bahamut
import (
"context"
"crypto/tls"
"net/http"
"testing"
// nolint:revive // Allow dot imports for readability in tests
. "github.com/smartystreets/goconvey/convey"
"go.aporeto.io/elemental"
)
func TestMockSession(t *testing.T) {
Convey("MockSession should work", t, func() {
s := NewMockSession()
So(s.MockClaimsMap, ShouldNotBeNil)
So(s.MockCookies, ShouldNotBeNil)
So(s.MockHeaders, ShouldNotBeNil)
So(s.MockParameters, ShouldNotBeNil)
s.MockClaimsMap = map[string]string{"k": "v"}
s.MockClientIP = "1.1.1.1"
s.MockCookies = map[string]*http.Cookie{"c": {}}
s.MockHeaders = map[string]string{"k": "v"}
s.MockIdentifier = "id"
s.MockParameters = map[string]string{"k": "v"}
s.MockPushConfig = &elemental.PushConfig{}
s.MockTLSConnectionState = &tls.ConnectionState{}
s.MockToken = "token"
var calledDirectPush bool
s.MockDirectPush = func(evts ...*elemental.Event) { calledDirectPush = true }
s.SetClaims([]string{"k=v"})
s.SetMetadata("mischief") // A beer to the one who gets the reference.
So(s.Identifier(), ShouldEqual, "id")
So(s.Parameter("k"), ShouldEqual, "v")
So(s.Header("k"), ShouldEqual, "v")
So(s.PushConfig(), ShouldNotBeNil)
So(s.Claims(), ShouldResemble, []string{"k=v"})
So(s.ClaimsMap(), ShouldResemble, map[string]string{"k": "v"})
So(s.Token(), ShouldEqual, "token")
So(s.TLSConnectionState(), ShouldNotBeNil)
So(s.Metadata(), ShouldEqual, "mischief")
So(s.Context(), ShouldResemble, context.Background())
So(s.ClientIP(), ShouldEqual, "1.1.1.1")
cc, err := s.Cookie("c")
So(cc, ShouldNotBeNil)
So(err, ShouldBeNil)
cc, err = s.Cookie("d")
So(cc, ShouldBeNil)
So(err, ShouldEqual, http.ErrNoCookie)
s.DirectPush()
So(calledDirectPush, ShouldBeTrue)
})
}