refactor: move converter from hrp internal to pkg

This commit is contained in:
debugtalk
2022-10-11 11:22:02 +08:00
parent 0a0700dda8
commit 0ff5fb762f
20 changed files with 41 additions and 3 deletions

View File

@@ -0,0 +1,28 @@
package convert
import (
"reflect"
"github.com/pkg/errors"
"github.com/httprunner/httprunner/v4/hrp"
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
)
func NewYAMLCase(path string) (*hrp.TCase, error) {
// load yaml case file
caseJSON := new(hrp.TCase)
err := builtin.LoadFile(path, caseJSON)
if err != nil {
return nil, errors.Wrap(err, "load yaml file failed")
}
if reflect.ValueOf(*caseJSON).IsZero() {
return nil, errors.New("invalid yaml file")
}
err = caseJSON.MakeCompat()
if err != nil {
return nil, err
}
return caseJSON, nil
}