mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-13 00:11:28 +08:00
change: add unittests for parameters iterator unlimited mode
This commit is contained in:
@@ -13,7 +13,7 @@ import (
|
|||||||
|
|
||||||
type TParamsConfig struct {
|
type TParamsConfig struct {
|
||||||
Strategy iteratorStrategy `json:"strategy,omitempty" yaml:"strategy,omitempty"` // overall strategy
|
Strategy iteratorStrategy `json:"strategy,omitempty" yaml:"strategy,omitempty"` // overall strategy
|
||||||
Strategies map[string]iteratorStrategy `json:"strategies,omitempty" yaml:"strategies,omitempty"` // map[string]string、string
|
Strategies map[string]iteratorStrategy `json:"strategies,omitempty" yaml:"strategies,omitempty"` // individual strategies for each parameters
|
||||||
Limit int `json:"limit,omitempty" yaml:"limit,omitempty"`
|
Limit int `json:"limit,omitempty" yaml:"limit,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,8 +107,8 @@ type ParametersIterator struct {
|
|||||||
hasNext bool // cache query result
|
hasNext bool // cache query result
|
||||||
sequentialParameters Parameters // cartesian product for sequential parameters
|
sequentialParameters Parameters // cartesian product for sequential parameters
|
||||||
randomParameterNames []string // value is parameter names
|
randomParameterNames []string // value is parameter names
|
||||||
limit int
|
limit int // limit count for iteration
|
||||||
index int
|
index int // current iteration index
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetUnlimitedMode is used for load testing
|
// SetUnlimitedMode is used for load testing
|
||||||
@@ -145,11 +145,6 @@ func (iter *ParametersIterator) Next() map[string]interface{} {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(iter.data) == 0 {
|
|
||||||
iter.hasNext = false
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var selectedParameters map[string]interface{}
|
var selectedParameters map[string]interface{}
|
||||||
if len(iter.sequentialParameters) == 0 {
|
if len(iter.sequentialParameters) == 0 {
|
||||||
selectedParameters = make(map[string]interface{})
|
selectedParameters = make(map[string]interface{})
|
||||||
|
|||||||
@@ -248,6 +248,59 @@ func TestInitParametersIteratorCount(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestInitParametersIteratorUnlimitedCount(t *testing.T) {
|
||||||
|
configParameters := map[string]interface{}{
|
||||||
|
"username-password": fmt.Sprintf("${parameterize(%s/account.csv)}", hrpExamplesDir), // 3
|
||||||
|
"user_agent": []interface{}{"iOS/10.1", "iOS/10.2"}, // 2
|
||||||
|
"app_version": []interface{}{4.0}, // 1
|
||||||
|
}
|
||||||
|
testData := []struct {
|
||||||
|
cfg *TConfig
|
||||||
|
}{
|
||||||
|
// default, no parameters setting
|
||||||
|
{
|
||||||
|
&TConfig{
|
||||||
|
Parameters: configParameters,
|
||||||
|
ParametersSetting: &TParamsConfig{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
// no parameters
|
||||||
|
// also will generate one empty item
|
||||||
|
{
|
||||||
|
&TConfig{
|
||||||
|
Parameters: nil,
|
||||||
|
ParametersSetting: nil,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, data := range testData {
|
||||||
|
iterator, err := initParametersIterator(data.cfg)
|
||||||
|
if !assert.Nil(t, err) {
|
||||||
|
t.Fatal()
|
||||||
|
}
|
||||||
|
// set unlimited mode
|
||||||
|
iterator.SetUnlimitedMode()
|
||||||
|
if !assert.Equal(t, -1, iterator.limit) {
|
||||||
|
t.Fatal()
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < 100; i++ {
|
||||||
|
if !assert.True(t, iterator.HasNext()) {
|
||||||
|
t.Fatal()
|
||||||
|
}
|
||||||
|
iterator.Next() // consume next parameters
|
||||||
|
}
|
||||||
|
if !assert.Equal(t, 100, iterator.index) {
|
||||||
|
t.Fatal()
|
||||||
|
}
|
||||||
|
// should also have next
|
||||||
|
if !assert.True(t, iterator.HasNext()) {
|
||||||
|
t.Fatal()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestInitParametersIteratorContent(t *testing.T) {
|
func TestInitParametersIteratorContent(t *testing.T) {
|
||||||
configParameters := map[string]interface{}{
|
configParameters := map[string]interface{}{
|
||||||
"username-password": fmt.Sprintf("${parameterize(%s/account.csv)}", hrpExamplesDir), // 3
|
"username-password": fmt.Sprintf("${parameterize(%s/account.csv)}", hrpExamplesDir), // 3
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ func (r *SessionRunner) MergeStepVariables(vars map[string]interface{}) (map[str
|
|||||||
// updateConfigVariables updates config variables with given variables.
|
// updateConfigVariables updates config variables with given variables.
|
||||||
// this is used for data driven
|
// this is used for data driven
|
||||||
func (r *SessionRunner) updateConfigVariables(parameters map[string]interface{}) {
|
func (r *SessionRunner) updateConfigVariables(parameters map[string]interface{}) {
|
||||||
if parameters == nil {
|
if len(parameters) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user