voucher/internal/pkg/script/script_test.go

82 lines
1.5 KiB
Go

package script
import (
"encoding/json"
"testing"
"time"
)
func Test_script(t *testing.T) {
startTime, err := time.Parse(time.DateTime, "2025-05-01 00:00:00")
if err != nil {
t.Error(err)
return
}
endTime, err := time.Parse(time.DateTime, "2025-05-01 10:00:00")
if err != nil {
t.Error(err)
return
}
duration := 5 * time.Hour
// 创建请求体
requestBody := map[string]any{
"go_num": 2, // 并发数量
"time_slice_hours": 2, // 时间间隔
"order_no": "",
"product_no": "",
"start_time": startTime.Format(time.DateTime),
"end_time": endTime.Format(time.DateTime),
}
// 将请求体转换为 JSON 格式
bodyBytes, err := json.Marshal(requestBody)
if err != nil {
t.Error(err)
return
}
if err = script(startTime, endTime, duration, bodyBytes, URL); err != nil {
t.Error(err)
}
}
func Test_script2(t *testing.T) {
startTime, err := time.Parse(time.DateTime, "2025-05-31 00:00:00")
if err != nil {
t.Error(err)
return
}
endTime, err := time.Parse(time.DateTime, "2025-05-01 10:00:00")
if err != nil {
t.Error(err)
return
}
duration := 50 * time.Hour
// 创建请求体
requestBody := map[string]any{
"order_no": "",
"product_no": "",
"start_time": startTime.Format(time.DateTime),
"end_time": endTime.Format(time.DateTime),
}
// 将请求体转换为 JSON 格式
bodyBytes, err := json.Marshal(requestBody)
if err != nil {
t.Error(err)
return
}
if err = script(startTime, endTime, duration, bodyBytes, SINGLE_URL); err != nil {
t.Error(err)
}
}