mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-06 07:57:27 +08:00
refactor: unify float64 conversion logic in ToolSleep and ToolSleepMS, enhance error logging
This commit is contained in:
@@ -30,6 +30,15 @@ func TestToolSleep_ConvertActionToCallToolRequest(t *testing.T) {
|
||||
expectedArgs: map[string]any{"seconds": float64(3.5)},
|
||||
shouldError: false,
|
||||
},
|
||||
{
|
||||
name: "float64 parameter",
|
||||
action: option.MobileAction{
|
||||
Method: option.ACTION_Sleep,
|
||||
Params: float64(5.2),
|
||||
},
|
||||
expectedArgs: map[string]any{"seconds": float64(5.2)},
|
||||
shouldError: false,
|
||||
},
|
||||
{
|
||||
name: "int64 parameter",
|
||||
action: option.MobileAction{
|
||||
@@ -63,6 +72,24 @@ func TestToolSleep_ConvertActionToCallToolRequest(t *testing.T) {
|
||||
expectedArgs: nil,
|
||||
shouldError: true,
|
||||
},
|
||||
{
|
||||
name: "json.Number with integer value",
|
||||
action: option.MobileAction{
|
||||
Method: option.ACTION_Sleep,
|
||||
Params: json.Number("10"),
|
||||
},
|
||||
expectedArgs: map[string]any{"seconds": float64(10)},
|
||||
shouldError: false,
|
||||
},
|
||||
{
|
||||
name: "json.Number with decimal value",
|
||||
action: option.MobileAction{
|
||||
Method: option.ACTION_Sleep,
|
||||
Params: json.Number("1.25"),
|
||||
},
|
||||
expectedArgs: map[string]any{"seconds": float64(1.25)},
|
||||
shouldError: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
@@ -109,6 +136,15 @@ func TestToolSleepMS_ConvertActionToCallToolRequest(t *testing.T) {
|
||||
expectedArgs: map[string]any{"milliseconds": int64(2000)},
|
||||
shouldError: false,
|
||||
},
|
||||
{
|
||||
name: "float64 parameter",
|
||||
action: option.MobileAction{
|
||||
Method: option.ACTION_SleepMS,
|
||||
Params: float64(2500.7),
|
||||
},
|
||||
expectedArgs: map[string]any{"milliseconds": int64(2500)},
|
||||
shouldError: false,
|
||||
},
|
||||
{
|
||||
name: "SleepConfig with startTime",
|
||||
action: option.MobileAction{
|
||||
@@ -124,6 +160,15 @@ func TestToolSleepMS_ConvertActionToCallToolRequest(t *testing.T) {
|
||||
},
|
||||
shouldError: false,
|
||||
},
|
||||
{
|
||||
name: "json.Number with decimal value",
|
||||
action: option.MobileAction{
|
||||
Method: option.ACTION_SleepMS,
|
||||
Params: json.Number("1234.56"),
|
||||
},
|
||||
expectedArgs: map[string]any{"milliseconds": int64(1234)},
|
||||
shouldError: false,
|
||||
},
|
||||
{
|
||||
name: "invalid parameter type",
|
||||
action: option.MobileAction{
|
||||
|
||||
Reference in New Issue
Block a user