mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-04 23:16:57 +08:00
feat: convertTestCase
This commit is contained in:
+20
@@ -102,3 +102,23 @@ func loadFromYAML(path string) (*TCase, error) {
|
|||||||
err = yaml.Unmarshal(file, tc)
|
err = yaml.Unmarshal(file, tc)
|
||||||
return tc, err
|
return tc, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func convertTestCase(tc *TCase) (*TestCase, error) {
|
||||||
|
testCase := &TestCase{
|
||||||
|
Config: tc.Config,
|
||||||
|
}
|
||||||
|
for _, step := range tc.TestSteps {
|
||||||
|
if step.Request != nil {
|
||||||
|
testCase.TestSteps = append(testCase.TestSteps, &requestWithOptionalArgs{
|
||||||
|
step: step,
|
||||||
|
})
|
||||||
|
} else if step.TestCase != nil {
|
||||||
|
testCase.TestSteps = append(testCase.TestSteps, &testcaseWithOptionalArgs{
|
||||||
|
step: step,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
log.Printf("[convertTestCase] unexpected step: %+v", step)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return testCase, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -96,3 +96,19 @@ func TestDumpAndLoadYAML(t *testing.T) {
|
|||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLoadJSONAndRun(t *testing.T) {
|
||||||
|
jsonPath := "demo.json"
|
||||||
|
tc, err := loadFromJSON(jsonPath)
|
||||||
|
if !assert.NoError(t, err) {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
testcase, err := convertTestCase(tc)
|
||||||
|
if !assert.NoError(t, err) {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
err = Test(t, testcase)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("run testcase error: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user