-
Notifications
You must be signed in to change notification settings - Fork 66
/
script.go
166 lines (134 loc) · 4.32 KB
/
script.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package scriptHelper
import (
"fmt"
"github.com/aaronchen2k/deeptest"
"github.com/aaronchen2k/deeptest/internal/pkg/consts"
"github.com/aaronchen2k/deeptest/internal/pkg/domain"
_i118Utils "github.com/aaronchen2k/deeptest/pkg/lib/i118"
"path"
)
func GetScript(name ScriptType) string {
if name == ScriptDeepTest {
if DeepTestScript == "" {
bytes, _ := deeptest.ReadResData(path.Join("res", "goja", "export", "deeptest.js"))
DeepTestScript = string(bytes)
}
return DeepTestScript
} else if name == DeclareDeepTest {
if DeepTestDeclare == "" {
bytes, _ := deeptest.ReadResData(path.Join("res", "goja", "export", "deeptest.d.ts"))
DeepTestDeclare = string(bytes)
}
return DeepTestDeclare
} else if name == DeclareDeepTestPost {
if DeepTestDeclarePost == "" {
bytes, _ := deeptest.ReadResData(path.Join("res", "goja", "export", "deeptest-post.d.ts"))
DeepTestDeclarePost = string(bytes)
}
return DeepTestDeclarePost
} else if name == DeclareDeepTestScenarioCustomCode {
if DeepTestScenarioCustomCode == "" {
bytes, _ := deeptest.ReadResData(path.Join("res", "goja", "export", "deeptest-scenario-custom-code.d.ts"))
DeepTestScenarioCustomCode = string(bytes)
}
return DeepTestScenarioCustomCode
} else if name == DeclareChai {
if DeepTestDeclareChai == "" {
bytes, _ := deeptest.ReadResData(path.Join("res", "goja", "export", "chai.d.ts"))
DeepTestDeclareChai = string(bytes)
}
return DeepTestDeclareChai
} else if name == ScriptMock {
if MockScript == "" {
bytes, _ := deeptest.ReadResData(path.Join("res", "goja", "export", "mock.js"))
MockScript = string(bytes)
}
return MockScript
} else if name == DeclareMock {
if MockDeclare == "" {
bytes, _ := deeptest.ReadResData(path.Join("res", "goja", "export", "mock.d.ts"))
MockDeclare = string(bytes)
}
return MockDeclare
} else if name == SnippetDatapoolGet {
if DatapoolGetScript == "" {
bytes, _ := deeptest.ReadResData(path.Join("res", "goja", "snippet", "datapool_get.txt"))
DatapoolGetScript = string(bytes)
}
return DatapoolGetScript
} else if name == SnippetVariablesGet {
if VariablesGet == "" {
bytes, _ := deeptest.ReadResData(path.Join("res", "goja", "snippet", "variables_get.txt"))
VariablesGet = string(bytes)
}
return VariablesGet
} else if name == SnippetVariablesSet {
if VariablesSet == "" {
bytes, _ := deeptest.ReadResData(path.Join("res", "goja", "snippet", "variables_set.txt"))
VariablesSet = string(bytes)
}
return VariablesSet
} else if name == SnippetVariablesClear {
if VariablesClear == "" {
bytes, _ := deeptest.ReadResData(path.Join("res", "goja", "snippet", "variables_clear.txt"))
VariablesClear = string(bytes)
}
return VariablesClear
}
return ""
}
func GetModule(name string) (ret string) {
bytes, _ := deeptest.ReadResData(path.Join("res", "goja", "module", name))
ret = string(bytes)
return
}
func GenResultMsg(po *domain.ScriptBase) {
name := "脚本"
if po.ConditionSrc == consts.ConditionSrcPre {
name = "预请求" + name
} else if po.ConditionSrc == consts.ConditionSrcPost {
name = "后处理" + name
}
statusText := ""
if po.ResultStatus == consts.Pass {
statusText = "成功"
} else if po.ResultStatus == consts.Fail {
statusText = "失败"
}
po.ResultMsg = fmt.Sprintf("%s%s%s", name, _i118Utils.Sprintf("exec"), statusText)
po.ResultMsg += " JSON~" + po.Output + "~JSON"
return
}
var (
DeepTestScript = ""
DeepTestDeclare = ""
DeepTestDeclarePost = ""
DeepTestScenarioCustomCode = ""
DeepTestDeclareChai = ""
MockScript = ""
MockDeclare = ""
JslibsDeclares = ""
DatapoolGetScript = ""
VariablesGet = ""
VariablesSet = ""
VariablesClear = ""
)
type ScriptType string
const (
ScriptDeepTest = "deeptest"
DeclareDeepTest = "deeptest.d"
DeclareDeepTestPost = "deeptest-post.d"
DeclareDeepTestScenarioCustomCode = "deeptest-scenario-custom-code.d"
DeclareChai = "chai.d"
ModuleMockJs = "mockjs.js"
ScriptMock = "mock"
DeclareMock = "mock.d"
DeclareJslibs = "jslibs"
SnippetDatapoolGet = "datapool_get"
SnippetVariablesGet = "variables_get"
SnippetVariablesSet = "variables_set"
SnippetVariablesClear = "variables_clear"
)
func (e ScriptType) String() string {
return string(e)
}