mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-13 04:20:31 +08:00
Merge branch 'main' into chore/support-rich-interface-request-result-verification-mechanism
This commit is contained in:
@@ -96,7 +96,7 @@ func loadFromYAML(path string) (*TCase, error) {
|
||||
return tc, err
|
||||
}
|
||||
|
||||
func loadFromCSV(path string) []map[string]string {
|
||||
func LoadFromCSV(path string) []map[string]string {
|
||||
path, err := filepath.Abs(path)
|
||||
if err != nil {
|
||||
log.Error().Str("path", path).Err(err).Msg("convert absolute path failed")
|
||||
|
||||
@@ -3,6 +3,7 @@ package builtin
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"github.com/httprunner/hrp"
|
||||
"math"
|
||||
"math/rand"
|
||||
"time"
|
||||
@@ -14,7 +15,8 @@ var Functions = map[string]interface{}{
|
||||
"gen_random_string": genRandomString, // call with one argument
|
||||
"max": math.Max, // call with two arguments
|
||||
"md5": MD5,
|
||||
"getAppVersion": getAppVersion, // test
|
||||
"parameterize": hrp.LoadFromCSV,
|
||||
"P": hrp.LoadFromCSV,
|
||||
}
|
||||
|
||||
func init() {
|
||||
@@ -45,7 +47,3 @@ func MD5(str string) string {
|
||||
hasher.Write([]byte(str))
|
||||
return hex.EncodeToString(hasher.Sum(nil))
|
||||
}
|
||||
|
||||
func getAppVersion() []float64 {
|
||||
return []float64{3.1, 3.3}
|
||||
}
|
||||
|
||||
20
parser.go
20
parser.go
@@ -259,25 +259,13 @@ func contains(s []string, e string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func getMappingFunction(funcName string) (interface{}, error) {
|
||||
if function, ok := builtin.Functions[funcName]; ok {
|
||||
// function is builtin
|
||||
return function, nil
|
||||
} else if contains([]string{"parameterize", "P"}, funcName) {
|
||||
// parameterize function
|
||||
return loadFromCSV, nil
|
||||
} else {
|
||||
// function not found
|
||||
return nil, fmt.Errorf("function %s is not found", funcName)
|
||||
}
|
||||
}
|
||||
|
||||
// callFunc call function with arguments
|
||||
// only support return at most one result value
|
||||
func callFunc(funcName string, arguments ...interface{}) (interface{}, error) {
|
||||
function, err := getMappingFunction(funcName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
function, ok := builtin.Functions[funcName]
|
||||
if !ok {
|
||||
// function not found
|
||||
return nil, fmt.Errorf("function %s is not found", funcName)
|
||||
}
|
||||
funcValue := reflect.ValueOf(function)
|
||||
if funcValue.Kind() != reflect.Func {
|
||||
|
||||
Reference in New Issue
Block a user