This repository has been archived by the owner on Mar 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
convert_test.go
69 lines (63 loc) · 1.81 KB
/
convert_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
61
62
63
64
65
66
67
68
69
package hrp
import (
"testing"
"github.com/stretchr/testify/assert"
)
var (
demoTestCaseJSONPath TestCasePath = "examples/demo.json"
demoTestCaseYAMLPath TestCasePath = "examples/demo.yaml"
demoRefAPIYAMLPath TestCasePath = "examples/ref_api_test.yaml"
demoRefTestCaseJSONPath TestCasePath = "examples/ref_testcase_test.json"
demoThinkTimeJsonPath TestCasePath = "examples/think_time_test.json"
demoAPIYAMLPath APIPath = "examples/api/put.yml"
)
func TestLoadCase(t *testing.T) {
tcJSON := &TCase{}
tcYAML := &TCase{}
err := loadFromJSON(demoTestCaseJSONPath.ToString(), tcJSON)
if !assert.NoError(t, err) {
t.Fail()
}
err = loadFromYAML(demoTestCaseYAMLPath.ToString(), tcYAML)
if !assert.NoError(t, err) {
t.Fail()
}
if !assert.Equal(t, tcJSON.Config.Name, tcYAML.Config.Name) {
t.Fail()
}
if !assert.Equal(t, tcJSON.Config.BaseURL, tcYAML.Config.BaseURL) {
t.Fail()
}
if !assert.Equal(t, tcJSON.TestSteps[1].Name, tcYAML.TestSteps[1].Name) {
t.Fail()
}
if !assert.Equal(t, tcJSON.TestSteps[1].Request, tcYAML.TestSteps[1].Request) {
t.Fail()
}
}
func Test_convertCheckExpr(t *testing.T) {
exprs := []struct {
before string
after string
}{
// normal check expression
{"a.b.c", "a.b.c"},
{"headers.\"Content-Type\"", "headers.\"Content-Type\""},
// check expression using regex
{"covering (.*) testing,", "covering (.*) testing,"},
{" (.*) a-b-c", " (.*) a-b-c"},
// abnormal check expression
{"-", "\"-\""},
{"b-c", "\"b-c\""},
{"a.b-c.d", "a.\"b-c\".d"},
{"a-b.c-d", "\"a-b\".\"c-d\""},
{"\"a-b\".c-d", "\"a-b\".\"c-d\""},
{"headers.Content-Type", "headers.\"Content-Type\""},
{"body.I-am-a-Key.name", "body.\"I-am-a-Key\".name"},
}
for _, expr := range exprs {
if !assert.Equal(t, convertCheckExpr(expr.before), expr.after) {
t.Fail()
}
}
}