-
Notifications
You must be signed in to change notification settings - Fork 3
/
sd_test.go
60 lines (51 loc) · 2.06 KB
/
sd_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
// 健康检查,cpu,memory,disk状态获取api测试文件
package main
import (
"github.com/kataras/iris/httptest"
"github.com/muxiyun/Mae/model"
"testing"
//"fmt"
"time"
)
func TestSystemCheck(t *testing.T) {
e := httptest.New(t, newApp(), httptest.URL("http://127.0.0.1:8080"))
defer model.DB.RWdb.DropTableIfExists("users")
defer model.DB.RWdb.DropTableIfExists("casbin_rule")
//anonymous
e.GET("/api/v1.0/sd/health").Expect().Status(httptest.StatusOK)
time.Sleep(2*time.Second)
e.GET("/api/v1.0/sd/cpu").Expect().Status(httptest.StatusForbidden)
time.Sleep(2*time.Second)
e.GET("/api/v1.0/sd/mem").Expect().Status(httptest.StatusForbidden)
time.Sleep(2*time.Second)
e.GET("/api/v1.0/sd/disk").Expect().Status(httptest.StatusForbidden)
time.Sleep(2*time.Second)
//user, first to register a user
CreateUserForTest(e, "andrew", "123456", "3480437308@qq.com")
andrew_token := GetTokenForTest(e, "andrew", "123456", 60*60)
e.GET("/api/v1.0/sd/health").WithBasicAuth(andrew_token, "").
Expect().Status(httptest.StatusOK)
time.Sleep(2*time.Second)
e.GET("/api/v1.0/sd/cpu").WithBasicAuth(andrew_token, "").
Expect().Status(httptest.StatusForbidden)
time.Sleep(2*time.Second)
e.GET("/api/v1.0/sd/mem").WithBasicAuth(andrew_token, "").
Expect().Status(httptest.StatusForbidden)
time.Sleep(2*time.Second)
e.GET("/api/v1.0/sd/disk").WithBasicAuth(andrew_token, "").
Expect().Status(httptest.StatusForbidden)
time.Sleep(2*time.Second)
CreateAdminForTest(e, "andrewadmin", "123456", "admin@qq.com")
andrewadmin_token := GetTokenForTest(e, "andrewadmin", "123456", 60*60)
e.GET("/api/v1.0/sd/health").WithBasicAuth(andrewadmin_token, "").
Expect().Status(httptest.StatusOK)
time.Sleep(2*time.Second)
e.GET("/api/v1.0/sd/cpu").WithBasicAuth(andrewadmin_token, "").
Expect().Status(httptest.StatusOK)
time.Sleep(2*time.Second)
e.GET("/api/v1.0/sd/mem").WithBasicAuth(andrewadmin_token, "").
Expect().Status(httptest.StatusOK)
time.Sleep(2*time.Second)
e.GET("/api/v1.0/sd/disk").WithBasicAuth(andrewadmin_token, "").
Expect().Status(httptest.StatusOK)
}