mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-09 01:39:39 +08:00
refactor: NewDataOptions and NewData
This commit is contained in:
@@ -860,13 +860,8 @@ func WithDataWaitTime(sec float64) DataOption {
|
||||
}
|
||||
}
|
||||
|
||||
func NewData(data map[string]interface{}, options ...DataOption) *DataOptions {
|
||||
if data == nil {
|
||||
data = make(map[string]interface{})
|
||||
}
|
||||
dataOptions := &DataOptions{
|
||||
Data: data,
|
||||
}
|
||||
func NewDataOptions(options ...DataOption) *DataOptions {
|
||||
dataOptions := &DataOptions{}
|
||||
for _, option := range options {
|
||||
option(dataOptions)
|
||||
}
|
||||
@@ -874,7 +869,18 @@ func NewData(data map[string]interface{}, options ...DataOption) *DataOptions {
|
||||
if len(dataOptions.Scope) == 0 {
|
||||
dataOptions.Scope = []int{0, 0, math.MaxInt64, math.MaxInt64} // default scope
|
||||
}
|
||||
return dataOptions
|
||||
}
|
||||
|
||||
func NewData(data map[string]interface{}, options ...DataOption) map[string]interface{} {
|
||||
dataOptions := NewDataOptions(options...)
|
||||
|
||||
// merge with data options
|
||||
for k, v := range dataOptions.Data {
|
||||
data[k] = v
|
||||
}
|
||||
|
||||
// handle point offset
|
||||
if len(dataOptions.Offset) == 2 {
|
||||
if x, ok := data["x"]; ok {
|
||||
xf, _ := builtin.Interface2Float64(x)
|
||||
@@ -886,23 +892,24 @@ func NewData(data map[string]interface{}, options ...DataOption) *DataOptions {
|
||||
}
|
||||
}
|
||||
|
||||
if _, ok := dataOptions.Data["steps"]; !ok {
|
||||
dataOptions.Data["steps"] = 12 // default steps
|
||||
// add default options
|
||||
if _, ok := data["steps"]; !ok {
|
||||
data["steps"] = 12 // default steps
|
||||
}
|
||||
|
||||
if _, ok := dataOptions.Data["duration"]; !ok {
|
||||
dataOptions.Data["duration"] = 0 // default duration
|
||||
if _, ok := data["duration"]; !ok {
|
||||
data["duration"] = 0 // default duration
|
||||
}
|
||||
|
||||
if _, ok := dataOptions.Data["frequency"]; !ok {
|
||||
dataOptions.Data["frequency"] = 60 // default frequency
|
||||
if _, ok := data["frequency"]; !ok {
|
||||
data["frequency"] = 60 // default frequency
|
||||
}
|
||||
|
||||
if _, ok := dataOptions.Data["isReplace"]; !ok {
|
||||
dataOptions.Data["isReplace"] = true // default true
|
||||
if _, ok := data["isReplace"]; !ok {
|
||||
data["isReplace"] = true // default true
|
||||
}
|
||||
|
||||
return dataOptions
|
||||
return data
|
||||
}
|
||||
|
||||
// current implemeted device: IOSDevice, AndroidDevice
|
||||
|
||||
Reference in New Issue
Block a user