mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 15:37:35 +08:00
refactor: move files to hrp
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
package hrp
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var (
|
||||
demoTestCaseJSONPath TestCasePath = "../examples/hrp/demo.json"
|
||||
demoTestCaseYAMLPath TestCasePath = "../examples/hrp/demo.yaml"
|
||||
demoRefAPIYAMLPath TestCasePath = "../examples/hrp/ref_api_test.yaml"
|
||||
demoRefTestCaseJSONPath TestCasePath = "../examples/hrp/ref_testcase_test.json"
|
||||
demoThinkTimeJsonPath TestCasePath = "../examples/hrp/think_time_test.json"
|
||||
demoAPIYAMLPath APIPath = "../examples/hrp/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()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user