forked from statping/statping
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusers_test.go
92 lines (87 loc) · 2.34 KB
/
users_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
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
package handlers
import (
"github.com/stretchr/testify/require"
"net/url"
"testing"
)
func TestApiUsersRoutes(t *testing.T) {
form := url.Values{}
form.Add("username", "adminupdated")
form.Add("password", "password12345")
badForm := url.Values{}
badForm.Add("username", "adminupdated")
badForm.Add("password", "wrongpassword")
tests := []HTTPTest{
{
Name: "Statping All Users",
URL: "/api/users",
Method: "GET",
ExpectedStatus: 200,
ResponseLen: 1,
}, {
Name: "Statping Create User",
URL: "/api/users",
HttpHeaders: []string{"Content-Type=application/json"},
Method: "POST",
Body: `{
"username": "adminuser2",
"email": "[email protected]",
"password": "passsword123",
"admin": true
}`,
ExpectedStatus: 200,
}, {
Name: "Statping View User",
URL: "/api/users/1",
Method: "GET",
ExpectedStatus: 200,
}, {
Name: "Statping Missing User",
URL: "/api/users/9393939393",
Method: "GET",
ExpectedStatus: 404,
}, {
Name: "Statping Update User",
URL: "/api/users/1",
Method: "POST",
Body: `{
"username": "adminupdated",
"email": "[email protected]",
"password": "password12345",
"admin": true
}`,
ExpectedStatus: 200,
}, {
Name: "Statping Delete User",
URL: "/api/users/2",
Method: "DELETE",
ExpectedStatus: 200,
}, {
Name: "Statping Login User",
URL: "/api/login",
Method: "POST",
Body: form.Encode(),
ExpectedContains: []string{`"token"`},
ExpectedStatus: 200,
HttpHeaders: []string{"Content-Type=application/x-www-form-urlencoded"},
}, {
Name: "Statping Bad Login User",
URL: "/api/login",
Method: "POST",
Body: badForm.Encode(),
ExpectedContains: []string{`incorrect authentication`},
ExpectedStatus: 200,
HttpHeaders: []string{"Content-Type=application/x-www-form-urlencoded"},
}, {
Name: "Statping Logout",
URL: "/api/logout",
Method: "GET",
ExpectedStatus: 303,
}}
for _, v := range tests {
t.Run(v.Name, func(t *testing.T) {
_, t, err := RunHTTPTest(v, t)
require.Nil(t, err)
})
}
}