mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-08 09:19:41 +08:00
feat: data-driven.
This commit is contained in:
@@ -4,8 +4,7 @@ config:
|
|||||||
user_agent: [ "iOS/10.1", "iOS/10.2" ]
|
user_agent: [ "iOS/10.1", "iOS/10.2" ]
|
||||||
username-password: ${parameterize(examples/account.csv)}
|
username-password: ${parameterize(examples/account.csv)}
|
||||||
parameters_setting:
|
parameters_setting:
|
||||||
strategy: ""
|
strategy: ["random", "sequential"]
|
||||||
iteration: 10
|
|
||||||
variables:
|
variables:
|
||||||
app_version: v1
|
app_version: v1
|
||||||
user_agent: iOS/10.3
|
user_agent: iOS/10.3
|
||||||
|
|||||||
19
parser.go
19
parser.go
@@ -614,6 +614,7 @@ func initParameterIterator(cfg *TConfig, mode string) (err error) {
|
|||||||
rawValue := reflect.ValueOf(cfg.ParametersSetting.Strategy)
|
rawValue := reflect.ValueOf(cfg.ParametersSetting.Strategy)
|
||||||
switch rawValue.Kind() {
|
switch rawValue.Kind() {
|
||||||
case reflect.Slice:
|
case reflect.Slice:
|
||||||
|
// strategy: ["random", "sequential"]
|
||||||
if len(parameters) != rawValue.Len() {
|
if len(parameters) != rawValue.Len() {
|
||||||
return errors.New("parameters and strategy should have the same length")
|
return errors.New("parameters and strategy should have the same length")
|
||||||
} else {
|
} else {
|
||||||
@@ -625,6 +626,7 @@ func initParameterIterator(cfg *TConfig, mode string) (err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case reflect.String:
|
case reflect.String:
|
||||||
|
// strategy: "random"
|
||||||
if len(rawValue.String()) == 0 {
|
if len(rawValue.String()) == 0 {
|
||||||
cfg.ParametersSetting.Strategy = strategySequential
|
cfg.ParametersSetting.Strategy = strategySequential
|
||||||
} else {
|
} else {
|
||||||
@@ -635,6 +637,7 @@ func initParameterIterator(cfg *TConfig, mode string) (err error) {
|
|||||||
newIterator(genCartesianProduct(parameters), cfg.ParametersSetting.Strategy.(string), cfg.ParametersSetting.Iteration),
|
newIterator(genCartesianProduct(parameters), cfg.ParametersSetting.Strategy.(string), cfg.ParametersSetting.Iteration),
|
||||||
)
|
)
|
||||||
default:
|
default:
|
||||||
|
// default strategy: sequential
|
||||||
cfg.ParametersSetting.Strategy = strategySequential
|
cfg.ParametersSetting.Strategy = strategySequential
|
||||||
cfg.ParametersSetting.Iterator = append(
|
cfg.ParametersSetting.Iterator = append(
|
||||||
cfg.ParametersSetting.Iterator,
|
cfg.ParametersSetting.Iterator,
|
||||||
@@ -645,14 +648,14 @@ func initParameterIterator(cfg *TConfig, mode string) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newIterator(parameters paramsType, strategy string, iteration int) *Iterator {
|
func newIterator(parameters paramsType, strategy string, iteration int) *Iterator {
|
||||||
it := parameters.Iterator()
|
iter := parameters.Iterator()
|
||||||
it.strategy = strategy
|
iter.strategy = strategy
|
||||||
if iteration > 0 {
|
if iteration > 0 {
|
||||||
it.iteration = iteration
|
iter.iteration = iteration
|
||||||
} else if it.iteration == 0 {
|
} else if iteration < 0 {
|
||||||
it.iteration = 1
|
iter.iteration = -1
|
||||||
} else {
|
} else if iter.iteration == 0 {
|
||||||
it.iteration = -1
|
iter.iteration = 1
|
||||||
}
|
}
|
||||||
return it
|
return iter
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user