-
Notifications
You must be signed in to change notification settings - Fork 0
/
app_test.go
48 lines (35 loc) · 906 Bytes
/
app_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
package main
import (
"bytes"
"encoding/json"
"net/http/httptest"
"testing"
"github.com/zhaokefei/aiplatform/api"
)
func init() {
router = api.Routers()
}
func loginGetCookie(t *testing.T, username string, password string) string {
// 准备数据
data := map[string]string{
"username": username,
"password": password,
}
requestBody, _ := json.Marshal(data)
w := httptest.NewRecorder()
req := httptest.NewRequest("POST", "/login", bytes.NewBuffer(requestBody))
req.Header.Set("Content-Type", "application/json")
router.ServeHTTP(w, req)
if w.Code != 200 {
t.Fatalf("handler returned wrong status code: got %v want %v", w.Code, 200)
}
cookies := w.Result().Cookies()
if len(cookies) == 0 {
t.Fatalf("handler not get cookies")
}
return cookies[0].Value
}
func TestAppRoute_Fail(t *testing.T) {
// 准备数据
// loginCookie := loginGetCookie(t, "admin", "admin")
}