-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelper_test.go
50 lines (40 loc) · 1.17 KB
/
helper_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
package auth
import (
"io"
"net/http"
"net/http/httptest"
"github.com/stretchr/testify/mock"
)
func httpTest(handle http.HandlerFunc, method string, body io.Reader, contentType string) *httptest.ResponseRecorder {
r, _ := http.NewRequest(method, "", body)
r.Header.Add("Content-Type", contentType)
w := httptest.NewRecorder()
handle.ServeHTTP(w, r)
return w
}
type userHelper struct {
mock.Mock
}
func (h *userHelper) PasswordByEmail(email string) (string, bool) {
args := h.Called(email)
return args.String(0), args.Bool(1)
}
func (h *userHelper) FindUserDataByEmail(email string) (string, bool) {
args := h.Called(email)
return args.String(0), args.Bool(1)
}
func (h *userHelper) FindUserByToken(token string) (string, bool) {
args := h.Called(token)
return args.String(0), args.Bool(1)
}
func (h *userHelper) FindUserFromOAuth(provider string, user *User, r *http.Response) (string, error) {
args := h.Called(provider, user, r)
return args.String(0), args.Error(1)
}
func mockUserHelper() *userHelper {
return new(userHelper)
}
func mockHTTP(handler http.HandlerFunc) *httptest.Server {
server := httptest.NewServer(http.HandlerFunc(handler))
return server
}