feat: run tsetcase by path

This commit is contained in:
debugtalk
2021-10-10 00:22:26 +08:00
parent ab85a78e47
commit e49d2a1b9c
6 changed files with 84 additions and 12 deletions

View File

@@ -3,6 +3,7 @@ package httpboomer
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"path/filepath"
@@ -124,3 +125,29 @@ func convertTestCase(tc *TCase) (*TestCase, error) {
}
return testCase, nil
}
var ErrUnsupportedFileExt = fmt.Errorf("unsupported testcase file extension")
func loadTestFile(path *TestCasePath) (*TestCase, error) {
var tc *TCase
var err error
casePath := path.string
ext := filepath.Ext(casePath)
switch ext {
case ".json":
tc, err = loadFromJSON(casePath)
case ".yaml", ".yml":
tc, err = loadFromYAML(casePath)
default:
err = ErrUnsupportedFileExt
}
if err != nil {
return nil, err
}
testcase, err := convertTestCase(tc)
if err != nil {
return nil, err
}
return testcase, nil
}