-
Notifications
You must be signed in to change notification settings - Fork 96
/
httptest.go
95 lines (77 loc) · 2.2 KB
/
httptest.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
package db
import (
"database/sql/driver"
"encoding/json"
"github.com/jinzhu/gorm"
)
type (
HttpTestCollection struct {
gorm.Model
CreatedBy uint `json:"created_by"` // 创建人ID
AppName string `json:"app_name"`
Name string `json:"name"`
TestCases []HttpTestCase `gorm:"foreignKey:CollectionID" json:"-"`
}
HttpTestCase struct {
gorm.Model
CollectionID uint `json:"collection_id"`
Name string `json:"name"`
URL string `json:"url"`
Method string `json:"method"`
Query HttpTestParam `gorm:"type:json" json:"query"`
Headers HttpTestParam `gorm:"type:json" json:"headers"`
ContentType string `json:"content_type"`
Body string `json:"body"`
Script string `gorm:"type:longtext;" json:"script"`
Collection HttpTestCollection `gorm:"foreignKey:CollectionID" json:"-"`
}
HttpTestLog struct {
gorm.Model
OperatorType string // 执行人类型
OperatorID uint // 执行人ID
AppName string
Name string
// Request
URL string
Method string
Query HttpTestParam `gorm:"type:json"`
Headers HttpTestParam `gorm:"type:json"`
ContentType string
Body string `gorm:"type:longtext"`
// Response
ResponseBody string `gorm:"type:longtext"`
ResponseHeaders MapStringArray `gorm:"type:json"`
Size int64
Cost int64
Code int
Status string
Error string
TestLogs MapStringString `gorm:"type:json"` // 测试脚本产生的Log
}
HttpTestParam []HttpTestParamItem
HttpTestParamItem struct {
Key string `json:"key"`
Value string `json:"value"`
Description string `json:"description"`
}
)
func (h *HttpTestParam) Scan(val interface{}) error {
return json.Unmarshal(val.([]byte), h)
}
func (h HttpTestParam) Value() (val driver.Value, err error) {
if h == nil {
val = "[]"
return
}
val, err = json.Marshal(&h)
return
}
func (HttpTestCollection) TableName() string {
return "http_test_collection"
}
func (HttpTestCase) TableName() string {
return "http_test_case"
}
func (HttpTestLog) TableName() string {
return "http_test_log"
}