refactor: move tests

This commit is contained in:
lilong.129
2025-03-05 11:45:59 +08:00
parent e107389d6e
commit b9db874f38
25 changed files with 617 additions and 604 deletions

View File

@@ -12,6 +12,7 @@ import (
"gopkg.in/yaml.v2"
"github.com/httprunner/httprunner/v5/code"
"github.com/httprunner/httprunner/v5/internal/builtin"
"github.com/httprunner/httprunner/v5/internal/json"
)
@@ -85,7 +86,7 @@ func LoadTestCases(tests ...ITestCase) ([]*TestCase, error) {
// LoadFileObject loads file content with file extension and assigns to structObj
func LoadFileObject(path string, structObj interface{}) (err error) {
log.Info().Str("path", path).Msg("load file")
file, err := readFile(path)
file, err := builtin.LoadFile(path)
if err != nil {
return errors.Wrap(err, "read file failed")
}
@@ -145,19 +146,3 @@ func parseEnvContent(file []byte, obj interface{}) error {
}
return nil
}
func readFile(path string) ([]byte, error) {
var err error
path, err = filepath.Abs(path)
if err != nil {
log.Error().Err(err).Str("path", path).Msg("convert absolute path failed")
return nil, errors.Wrap(code.LoadFileError, err.Error())
}
file, err := os.ReadFile(path)
if err != nil {
log.Error().Err(err).Msg("read file failed")
return nil, errors.Wrap(code.LoadFileError, err.Error())
}
return file, nil
}