-
Notifications
You must be signed in to change notification settings - Fork 96
/
base.go
97 lines (81 loc) · 2.47 KB
/
base.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
93
94
95
96
97
package install
import (
"io/ioutil"
"net/http/httptest"
"strings"
"github.com/douyu/juno/api/apiv1/confgo"
"github.com/douyu/juno/api/apiv1/resource"
"github.com/douyu/juno/api/apiv1/system"
"github.com/douyu/juno/api/apiv1/user"
"github.com/labstack/echo/v4"
)
func MockData() {
router := echo.New()
var (
urlAppPut = "/app/put"
urlAppNodePut = "/app_node/put"
urlConfigTplCreate = "/config/tpl/create"
//urlConfigFileCreate := "/config/file/create"
//urlConfigContentUpdate := "/config/content/update"
//urlConfigGeneratorParse := "/config/parse"
urlSystemSetUpdate = "/system/setting/create"
urlUserCreate = "/user/create"
)
router.POST(urlAppPut, resource.AppPut)
router.POST(urlAppNodePut, resource.AppNodePut)
router.POST(urlConfigTplCreate, confgo.TplCreate)
router.POST(urlUserCreate, user.Create)
router.POST(urlSystemSetUpdate, system.SettingCreate)
mockApp(urlAppPut, router)
mockAppNode(urlAppNodePut, router)
//mockTplCreate(urlConfigTplCreate, router)
mockSystemSet(urlSystemSetUpdate, router)
// mockParse(urlConfigGeneratorParse, router)
mockCreateUser(urlUserCreate, router)
}
func MustMockSysTemSetData() {
router := echo.New()
urlSystemSetUpdate := "/system/setting/create"
router.POST(urlSystemSetUpdate, system.SettingCreate)
mockSystemSet(urlSystemSetUpdate, router)
mockGrafanaSetting(urlSystemSetUpdate, router)
mockAdminUser()
}
func MustMockData() {
router := echo.New()
urlSystemSetUpdate := "/system/setting/create"
router.POST(urlSystemSetUpdate, system.SettingCreate)
mockSystemSet(urlSystemSetUpdate, router)
mockGrafanaSetting(urlSystemSetUpdate, router)
mockAdminUser()
mockPermission()
}
func PostForm(uri string, param string, router *echo.Echo) []byte {
// 构造post请求
req := httptest.NewRequest("POST", uri, strings.NewReader(param))
req.Header.Set("Content-Type", "application/json")
// 初始化响应
w := httptest.NewRecorder()
// 调用相应handler接口
router.ServeHTTP(w, req)
// 提取响应
result := w.Result()
defer result.Body.Close()
// 读取响应body
body, _ := ioutil.ReadAll(result.Body)
return body
}
func Get(uri string, router *echo.Echo) []byte {
// 构造get请求
req := httptest.NewRequest("GET", uri, nil)
// 初始化响应
w := httptest.NewRecorder()
// 调用相应的handler接口
router.ServeHTTP(w, req)
// 提取响应
result := w.Result()
defer result.Body.Close()
// 读取响应body
body, _ := ioutil.ReadAll(result.Body)
return body
}