49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
package model
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/model/request"
|
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
)
|
|
|
|
func TestBatchExecutionLogSourceTypeValidation(t *testing.T) {
|
|
page := request.PageInfo{Page: 1, PageSize: 20}
|
|
if err := g.Validator().Data(BatchExecutionLogListParam{PageInfo: page}).Run(context.Background()); err != nil {
|
|
t.Fatalf("omitted sourceType: %v", err)
|
|
}
|
|
for _, value := range []int{-1, 0, 1, 2, 3, 4, 5} {
|
|
err := g.Validator().Data(BatchExecutionLogListParam{PageInfo: page, SourceType: &value}).Run(context.Background())
|
|
valid := value >= 0 && value <= 4
|
|
if (err == nil) != valid {
|
|
t.Fatalf("sourceType=%d: valid=%t err=%v", value, valid, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestBatchExecutionLogDetailModelOmitsItemCounts(t *testing.T) {
|
|
payload, err := json.Marshal(BatchExecutionLogDetailModel{
|
|
TotalCount: 7,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("marshal summary model: %v", err)
|
|
}
|
|
|
|
var fields map[string]any
|
|
if err := json.Unmarshal(payload, &fields); err != nil {
|
|
t.Fatalf("decode summary model: %v", err)
|
|
}
|
|
|
|
if got := fields["totalCount"]; got != float64(7) {
|
|
t.Fatalf("totalCount = %v, want 7", got)
|
|
}
|
|
for _, field := range []string{"validCount", "successCount", "failCount"} {
|
|
if _, ok := fields[field]; ok {
|
|
t.Fatalf("summary response still contains %q", field)
|
|
}
|
|
}
|
|
}
|