mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-06 00:09:37 +08:00
refactor: ParametersIterator
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package hrp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -754,152 +753,3 @@ func TestFindallVariables(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseParameters(t *testing.T) {
|
||||
testData := []struct {
|
||||
rawVars map[string]interface{}
|
||||
expectLength int
|
||||
}{
|
||||
{
|
||||
map[string]interface{}{
|
||||
"username-password": fmt.Sprintf("${parameterize(%s/account.csv)}", hrpExamplesDir),
|
||||
"user_agent": []interface{}{"IOS/10.1", "IOS/10.2"},
|
||||
},
|
||||
6,
|
||||
},
|
||||
{
|
||||
map[string]interface{}{
|
||||
"username-password": [][]interface{}{
|
||||
{"test1", "111111"},
|
||||
{"test2", "222222"},
|
||||
{"test3", "333333"},
|
||||
},
|
||||
"user_agent": []interface{}{"IOS/10.1", "IOS/10.2"},
|
||||
"app_version": []interface{}{0.3},
|
||||
},
|
||||
6,
|
||||
},
|
||||
{
|
||||
map[string]interface{}{
|
||||
"username-password": [][]interface{}{
|
||||
{"test1", "111111"},
|
||||
{"test2", "222222"},
|
||||
{"test3", "333333"},
|
||||
},
|
||||
"user_agent": []interface{}{"IOS/10.1", "IOS/10.2"},
|
||||
"app_version": []interface{}{0.3, 0.4, 0.5},
|
||||
},
|
||||
18,
|
||||
},
|
||||
{
|
||||
map[string]interface{}{},
|
||||
0,
|
||||
},
|
||||
{
|
||||
nil,
|
||||
0,
|
||||
},
|
||||
}
|
||||
for _, data := range testData {
|
||||
params, _ := parseParameters(data.rawVars, map[string]interface{}{})
|
||||
value := genCartesianProduct(params)
|
||||
if !assert.Len(t, value, data.expectLength) {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseParametersError(t *testing.T) {
|
||||
testData := []struct {
|
||||
rawVars map[string]interface{}
|
||||
}{
|
||||
{
|
||||
map[string]interface{}{
|
||||
"username_password": fmt.Sprintf("${parameterize(%s/account.csv)}", hrpExamplesDir),
|
||||
"user_agent": []interface{}{"IOS/10.1", "IOS/10.2"}},
|
||||
},
|
||||
{
|
||||
map[string]interface{}{
|
||||
"username-password": fmt.Sprintf("${parameterize(%s/account.csv)}", hrpExamplesDir),
|
||||
"user-agent": []interface{}{"IOS/10.1", "IOS/10.2"}},
|
||||
},
|
||||
{
|
||||
map[string]interface{}{
|
||||
"username-password": fmt.Sprintf("${param(%s/account.csv)}", hrpExamplesDir),
|
||||
"user_agent": []interface{}{"IOS/10.1", "IOS/10.2"}},
|
||||
},
|
||||
}
|
||||
for _, data := range testData {
|
||||
_, err := parseParameters(data.rawVars, map[string]interface{}{})
|
||||
if !assert.Error(t, err) {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseSlice(t *testing.T) {
|
||||
testData := []struct {
|
||||
rawVar1 string
|
||||
rawVar2 interface{}
|
||||
expect []map[string]interface{}
|
||||
}{
|
||||
{
|
||||
"username-password",
|
||||
[]map[string]interface{}{
|
||||
{"username": "test1", "password": 111111, "other": "111"},
|
||||
{"username": "test2", "password": 222222, "other": "222"},
|
||||
},
|
||||
[]map[string]interface{}{
|
||||
{"username": "test1", "password": 111111},
|
||||
{"username": "test2", "password": 222222},
|
||||
},
|
||||
},
|
||||
{
|
||||
"username-password",
|
||||
[][]string{
|
||||
{"test1", "111111"},
|
||||
{"test2", "222222"},
|
||||
},
|
||||
[]map[string]interface{}{
|
||||
{"username": "test1", "password": "111111"},
|
||||
{"username": "test2", "password": "222222"},
|
||||
},
|
||||
},
|
||||
{
|
||||
"app_version",
|
||||
[]float64{3.1, 3.0},
|
||||
[]map[string]interface{}{
|
||||
{"app_version": 3.1},
|
||||
{"app_version": 3.0},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, data := range testData {
|
||||
value, _ := parseSlice(data.rawVar1, data.rawVar2)
|
||||
if !assert.Equal(t, data.expect, value) {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseSliceError(t *testing.T) {
|
||||
testData := []struct {
|
||||
rawVar1 string
|
||||
rawVar2 interface{}
|
||||
}{
|
||||
{
|
||||
"app_version",
|
||||
123,
|
||||
},
|
||||
{
|
||||
"app_version",
|
||||
"123",
|
||||
},
|
||||
}
|
||||
for _, data := range testData {
|
||||
_, err := parseSlice(data.rawVar1, data.rawVar2)
|
||||
if !assert.Error(t, err) {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user