-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwebsocket_push_session_mock.go
94 lines (72 loc) · 2.89 KB
/
websocket_push_session_mock.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package bahamut
import (
"context"
"crypto/tls"
"net/http"
"go.aporeto.io/elemental"
)
var _ PushSession = &MockSession{}
// A MockSession can be used to mock a bahamut.Session.
type MockSession struct {
MockMetadata any
MockClaimsMap map[string]string
MockCookies map[string]*http.Cookie
MockHeaders map[string]string
MockParameters map[string]string
MockPushConfig *elemental.PushConfig
MockTLSConnectionState *tls.ConnectionState
MockDirectPush func(...*elemental.Event)
MockClientIP string
MockIdentifier string
MockToken string
MockClaims []string
}
// NewMockSession returns a new MockSession.
func NewMockSession() *MockSession {
return &MockSession{
MockClaimsMap: map[string]string{},
MockCookies: map[string]*http.Cookie{},
MockHeaders: map[string]string{},
MockParameters: map[string]string{},
}
}
// Cookie is part of the Session interface.
func (s *MockSession) Cookie(c string) (*http.Cookie, error) {
v, ok := s.MockCookies[c]
if !ok {
return nil, http.ErrNoCookie
}
return v, nil
}
// DirectPush is part of the PushSession interface
func (s *MockSession) DirectPush(evts ...*elemental.Event) {
if s.MockDirectPush != nil {
s.MockDirectPush(evts...)
}
}
// Identifier is part of the PushSession interface.
func (s *MockSession) Identifier() string { return s.MockIdentifier }
// Parameter is part of the PushSession interface.
func (s *MockSession) Parameter(k string) string { return s.MockParameters[k] }
// Header is part of the PushSession interface.
func (s *MockSession) Header(k string) string { return s.MockHeaders[k] }
// PushConfig is part of the PushSession interface.
func (s *MockSession) PushConfig() *elemental.PushConfig { return s.MockPushConfig }
// SetClaims is part of the PushSession interface.
func (s *MockSession) SetClaims(claims []string) { s.MockClaims = claims }
// Claims is part of the PushSession interface.
func (s *MockSession) Claims() []string { return s.MockClaims }
// ClaimsMap is part of the PushSession interface.
func (s *MockSession) ClaimsMap() map[string]string { return s.MockClaimsMap }
// Token is part of the PushSession interface.
func (s *MockSession) Token() string { return s.MockToken }
// TLSConnectionState is part of the PushSession interface.
func (s *MockSession) TLSConnectionState() *tls.ConnectionState { return s.MockTLSConnectionState }
// Metadata is part of the PushSession interface.
func (s *MockSession) Metadata() any { return s.MockMetadata }
// SetMetadata is part of the PushSession interface.
func (s *MockSession) SetMetadata(m any) { s.MockMetadata = m }
// Context is part of the PushSession interface.
func (s *MockSession) Context() context.Context { return context.Background() }
// ClientIP is part of the PushSession interface.
func (s *MockSession) ClientIP() string { return s.MockClientIP }