-
-
Notifications
You must be signed in to change notification settings - Fork 202
/
Copy pathuser_test.go
67 lines (58 loc) · 1.43 KB
/
user_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
// Copyright © 2019 Martin Tournoij – This file is part of GoatCounter and
// published under the terms of a slightly modified EUPL v1.2 license, which can
// be found in the LICENSE file or at https://license.goatcounter.com
package handlers
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"zgo.at/goatcounter"
)
func TestUserNew(t *testing.T) {
tests := []handlerTest{
{
name: "basic",
router: newBackend,
setup: func(ctx context.Context, t *testing.T) {
u := goatcounter.User{Site: 1, Email: "[email protected]", Password: []byte("coconuts")}
err := u.Insert(ctx)
if err != nil {
t.Fatal(err)
}
},
path: "/user/new",
wantCode: 200,
wantFormCode: 200,
},
}
for _, tt := range tests {
runTest(t, tt, nil)
}
}
func TestUserLogin(t *testing.T) {
tests := []handlerTest{}
for _, tt := range tests {
runTest(t, tt, func(t *testing.T, rr *httptest.ResponseRecorder, r *http.Request) {
// TODO: ensure we're actually logged in.
})
}
}
func TestUserLogout(t *testing.T) {
tests := []handlerTest{
{
name: "basic",
method: "POST",
router: newBackend,
path: "/user/logout",
auth: true,
wantCode: 303,
wantFormCode: 303,
},
}
for _, tt := range tests {
runTest(t, tt, func(t *testing.T, rr *httptest.ResponseRecorder, r *http.Request) {
// TODO: ensure we're actually logged out.
})
}
}