-
Notifications
You must be signed in to change notification settings - Fork 2
/
fakeAuthStore.go
126 lines (105 loc) · 4.11 KB
/
fakeAuthStore.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package auth
import (
"net/http"
)
// FakeStorer is a fake AuthStorer for testing and includes MethodsCalled to track what was called
type FakeStorer interface {
AuthStorer
MethodsCalled() []string
}
// NewFakeStorer returns a fake AuthStorer that can be used for testing
func NewFakeStorer(config FakeStorerConfig) FakeStorer {
return &fakeAuthStore{FakeStorerConfig: config}
}
// FakeStorerConfig stores the config for a Fake AuthStorer
type FakeStorerConfig struct {
GetSessionVal *LoginSession
GetSessionErr error
GetBasicAuthVal *LoginSession
GetBasicAuthErr error
OAuthLoginVal string
OAuthLoginErr error
LoginVal *LoginSession
LoginErr error
RegisterErr error
RequestPasswordResetErr error
LogoutErr error
CreateProfileVal *LoginSession
CreateProfileErr error
VerifyEmailVal string
VerifyEmailVal2 *User
VerifyEmailErr error
VerifyPasswordResetVal string
VerifyPasswordResetVal2 *User
VerifyPasswordResetErr error
CreateSecondaryEmailErr error
SetPrimaryEmailErr error
UpdatePasswordVal *LoginSession
UpdatePasswordErr error
UpdateInfoErr error
}
type fakeAuthStore struct {
AuthStorer
FakeStorerConfig
Called []string
}
func (a *fakeAuthStore) MethodsCalled() []string {
return a.Called
}
func (a *fakeAuthStore) GetSession(w http.ResponseWriter, r *http.Request) (*LoginSession, error) {
a.Called = append(a.Called, "GetSession")
return a.GetSessionVal, a.GetSessionErr
}
func (a *fakeAuthStore) GetBasicAuth(w http.ResponseWriter, r *http.Request) (*LoginSession, error) {
a.Called = append(a.Called, "GetBasicAuth")
return a.GetBasicAuthVal, a.GetBasicAuthErr
}
func (a *fakeAuthStore) OAuthLogin(w http.ResponseWriter, r *http.Request) (string, error) {
a.Called = append(a.Called, "OAuthLogin")
return a.OAuthLoginVal, a.OAuthLoginErr
}
func (a *fakeAuthStore) Login(w http.ResponseWriter, r *http.Request) (*LoginSession, error) {
a.Called = append(a.Called, "Login")
return a.LoginVal, a.LoginErr
}
func (a *fakeAuthStore) Register(w http.ResponseWriter, r *http.Request, params EmailSendParams, password string) error {
a.Called = append(a.Called, "Register")
return a.RegisterErr
}
func (a *fakeAuthStore) RequestPasswordReset(w http.ResponseWriter, r *http.Request, params EmailSendParams) error {
a.Called = append(a.Called, "RequestPasswordReset")
return a.RequestPasswordResetErr
}
func (a *fakeAuthStore) CreateProfile(w http.ResponseWriter, r *http.Request) (*LoginSession, error) {
a.Called = append(a.Called, "CreateProfile")
return a.CreateProfileVal, a.CreateProfileErr
}
func (a *fakeAuthStore) VerifyEmail(w http.ResponseWriter, r *http.Request, params EmailSendParams) (string, *User, error) {
a.Called = append(a.Called, "VerifyEmail")
return a.VerifyEmailVal, a.VerifyEmailVal2, a.VerifyEmailErr
}
func (a *fakeAuthStore) VerifyPasswordReset(w http.ResponseWriter, r *http.Request, emailVerificationCode string) (string, *User, error) {
a.Called = append(a.Called, "VerifyPasswordReset")
return a.VerifyPasswordResetVal, a.VerifyPasswordResetVal2, a.VerifyPasswordResetErr
}
func (a *fakeAuthStore) CreateSecondaryEmail(w http.ResponseWriter, r *http.Request, templateName, emailSubject string) error {
a.Called = append(a.Called, "CreateSecondaryEmail")
return a.CreateSecondaryEmailErr
}
func (a *fakeAuthStore) SetPrimaryEmail(w http.ResponseWriter, r *http.Request, templateName, emailSubject string) error {
a.Called = append(a.Called, "SetPrimaryEmail")
return a.SetPrimaryEmailErr
}
func (a *fakeAuthStore) UpdatePassword(w http.ResponseWriter, r *http.Request) (*LoginSession, error) {
a.Called = append(a.Called, "UpdatePassword")
return a.UpdatePasswordVal, a.UpdatePasswordErr
}
func (a *fakeAuthStore) Logout(w http.ResponseWriter, r *http.Request) error {
a.Called = append(a.Called, "Logout")
return a.LogoutErr
}
func (a *fakeAuthStore) UpdateInfo(userID string, info map[string]interface{}) error {
a.Called = append(a.Called, "UpdateInfo")
return a.UpdateInfoErr
}
var _ AuthStorer = &fakeAuthStore{}