mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-08 17:51:23 +08:00
feat: data-driven.
This commit is contained in:
46
parser.go
46
parser.go
@@ -3,16 +3,13 @@ package hrp
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"github.com/maja42/goval"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
"net/url"
|
"net/url"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/maja42/goval"
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/rs/zerolog/log"
|
|
||||||
|
|
||||||
"github.com/httprunner/hrp/internal/builtin"
|
"github.com/httprunner/hrp/internal/builtin"
|
||||||
)
|
)
|
||||||
@@ -250,15 +247,6 @@ func mergeVariables(variables, overriddenVariables map[string]interface{}) map[s
|
|||||||
return mergedVariables
|
return mergedVariables
|
||||||
}
|
}
|
||||||
|
|
||||||
func contains(s []string, e string) bool {
|
|
||||||
for _, a := range s {
|
|
||||||
if strings.EqualFold(a, e) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func getMappingFunction(funcName string) (interface{}, error) {
|
func getMappingFunction(funcName string) (interface{}, error) {
|
||||||
if function, ok := builtin.Functions[funcName]; ok {
|
if function, ok := builtin.Functions[funcName]; ok {
|
||||||
// function is builtin
|
// function is builtin
|
||||||
@@ -517,31 +505,6 @@ func findallVariables(raw string) variableSet {
|
|||||||
return varSet
|
return varSet
|
||||||
}
|
}
|
||||||
|
|
||||||
func shuffleCartesianProduct(slice []map[string]interface{}) {
|
|
||||||
r := rand.New(rand.NewSource(time.Now().Unix()))
|
|
||||||
for len(slice) > 0 {
|
|
||||||
n := len(slice)
|
|
||||||
randIndex := r.Intn(n)
|
|
||||||
slice[n-1], slice[randIndex] = slice[randIndex], slice[n-1]
|
|
||||||
slice = slice[:n-1]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func genCartesianProduct(params [][]map[string]interface{}) []map[string]interface{} {
|
|
||||||
var cartesianProduct []map[string]interface{}
|
|
||||||
cartesianProduct = params[0]
|
|
||||||
for i := 0; i < len(params)-1; i++ {
|
|
||||||
var tempProduct []map[string]interface{}
|
|
||||||
for _, param1 := range cartesianProduct {
|
|
||||||
for _, param2 := range params[i+1] {
|
|
||||||
tempProduct = append(tempProduct, mergeVariables(param1, param2))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cartesianProduct = tempProduct
|
|
||||||
}
|
|
||||||
return cartesianProduct
|
|
||||||
}
|
|
||||||
|
|
||||||
func getParameters(config IConfig) []map[string]interface{} {
|
func getParameters(config IConfig) []map[string]interface{} {
|
||||||
cfg := config.ToStruct()
|
cfg := config.ToStruct()
|
||||||
// parse config parameters
|
// parse config parameters
|
||||||
@@ -615,7 +578,8 @@ func parseParameters(parameters map[string]interface{}, variablesMapping map[str
|
|||||||
parameterList = append(parameterList, parameterMap)
|
parameterList = append(parameterList, parameterMap)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("parameter content should be List or Text(variables or functions call), got %v", v))
|
log.Error().Interface("parameter", parameters).Msg("[parseParameters] parameter content should be List or Text(variables or functions call), got %v")
|
||||||
|
return nil, errors.New("parameter content should be List or Text(variables or functions call)")
|
||||||
}
|
}
|
||||||
parsedParametersList = append(parsedParametersList, parameterList)
|
parsedParametersList = append(parsedParametersList, parameterList)
|
||||||
}
|
}
|
||||||
|
|||||||
41
utils.go
Normal file
41
utils.go
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
package hrp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math/rand"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func contains(s []string, e string) bool {
|
||||||
|
for _, a := range s {
|
||||||
|
if strings.EqualFold(a, e) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func shuffleCartesianProduct(slice []map[string]interface{}) {
|
||||||
|
r := rand.New(rand.NewSource(time.Now().Unix()))
|
||||||
|
for len(slice) > 0 {
|
||||||
|
n := len(slice)
|
||||||
|
randIndex := r.Intn(n)
|
||||||
|
slice[n-1], slice[randIndex] = slice[randIndex], slice[n-1]
|
||||||
|
slice = slice[:n-1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func genCartesianProduct(params [][]map[string]interface{}) []map[string]interface{} {
|
||||||
|
var cartesianProduct []map[string]interface{}
|
||||||
|
cartesianProduct = params[0]
|
||||||
|
for i := 0; i < len(params)-1; i++ {
|
||||||
|
var tempProduct []map[string]interface{}
|
||||||
|
for _, param1 := range cartesianProduct {
|
||||||
|
for _, param2 := range params[i+1] {
|
||||||
|
tempProduct = append(tempProduct, mergeVariables(param1, param2))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cartesianProduct = tempProduct
|
||||||
|
}
|
||||||
|
return cartesianProduct
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user