sync: 同步 v1.0.4 并脱敏配置与镜像
This commit is contained in:
@@ -1,12 +1,127 @@
|
||||
package iot
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/model"
|
||||
)
|
||||
|
||||
func TestSimCardBatchCondition(t *testing.T) {
|
||||
condition, args, err := simCardBatchCondition(context.Background(), "\n iccid-1 \n\t\niccid-2 13800000000 460001234567890\n")
|
||||
if err != nil {
|
||||
t.Fatalf("parse batch input: %v", err)
|
||||
}
|
||||
if !strings.HasPrefix(condition, "((") || !strings.HasSuffix(condition, "))") {
|
||||
t.Fatalf("batch conditions must be grouped: %s", condition)
|
||||
}
|
||||
if !strings.Contains(condition, "iccid IN (?) OR msisdn IN (?) OR imsi IN (?)") {
|
||||
t.Fatalf("single values must be folded into IN lists: %s", condition)
|
||||
}
|
||||
if strings.Count(condition, "(iccid = ? OR msisdn = ? OR imsi = ?)") != 3 {
|
||||
t.Fatalf("three-value row must require every value on the same card: %s", condition)
|
||||
}
|
||||
if strings.Contains(condition, " = ? AND msisdn = ? AND imsi = ?") {
|
||||
t.Fatalf("field positions must not be assumed: %s", condition)
|
||||
}
|
||||
wantArgs := []interface{}{
|
||||
"iccid-1", "iccid-1", "iccid-1",
|
||||
"iccid-2", "iccid-2", "iccid-2",
|
||||
"13800000000", "13800000000", "13800000000",
|
||||
"460001234567890", "460001234567890", "460001234567890",
|
||||
}
|
||||
if len(args) != len(wantArgs) {
|
||||
t.Fatalf("got %d args, want %d: %#v", len(args), len(wantArgs), args)
|
||||
}
|
||||
for i := range wantArgs {
|
||||
if args[i] != wantArgs[i] {
|
||||
t.Fatalf("arg %d = %#v, want %#v", i, args[i], wantArgs[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSimCardBatchConditionAcceptsAnyTwoValuesPerRow(t *testing.T) {
|
||||
condition, args, err := simCardBatchCondition(context.Background(),
|
||||
"89860000000000000001 13800000000\n13800000001 460001234567891\n")
|
||||
if err != nil {
|
||||
t.Fatalf("two values per row must be accepted: %v", err)
|
||||
}
|
||||
if strings.Count(condition, "(iccid = ? OR msisdn = ? OR imsi = ?)") != 4 {
|
||||
t.Fatalf("each value must match any field, two rows expected four groups: %s", condition)
|
||||
}
|
||||
if len(args) != 12 {
|
||||
t.Fatalf("got %d args, want 12: %#v", len(args), args)
|
||||
}
|
||||
if !strings.Contains(condition, " AND ") {
|
||||
t.Fatalf("values of one row must be paired on the same card: %s", condition)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSimCardBatchConditionRejectsEmptyAndInvalidInput(t *testing.T) {
|
||||
for _, input := range []string{"", " \n\t ", "one two three four", "one two three four five"} {
|
||||
if _, _, err := simCardBatchCondition(context.Background(), input); err == nil {
|
||||
t.Errorf("expected input %q to be rejected", input)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSimCardBatchConditionLimitsNonEmptyRowsBeforeDeduplication(t *testing.T) {
|
||||
input := strings.Repeat("same-number\n", simCardBatchMaxRows)
|
||||
condition, args, err := simCardBatchCondition(context.Background(), input)
|
||||
if err != nil {
|
||||
t.Fatalf("accept exactly %d rows: %v", simCardBatchMaxRows, err)
|
||||
}
|
||||
if len(args) != 3 {
|
||||
t.Fatalf("duplicate single values must collapse to one IN list, got %d args: %s", len(args), condition)
|
||||
}
|
||||
|
||||
input += "one-more\n"
|
||||
if _, _, err := simCardBatchCondition(context.Background(), input); err == nil {
|
||||
t.Fatal("expected 1001 rows to be rejected even when values repeat")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSimCardBatchInputPresenceAndExportValidation(t *testing.T) {
|
||||
for _, payload := range []string{`{"batchInput":""}`, `{"batchInput":" \n\t"}`} {
|
||||
var in model.TSimCardInfoListParam
|
||||
if err := json.Unmarshal([]byte(payload), &in); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if in.BatchInput == nil {
|
||||
t.Fatal("显式空批量输入不能视为省略字段")
|
||||
}
|
||||
if _, _, err := NewIotTSimCardInfo().List(context.Background(), &in); err == nil {
|
||||
t.Fatal("列表应在访问数据库前拒绝空批量输入")
|
||||
}
|
||||
if err := NewIotTSimCardInfo().Export(context.Background(), &in); err == nil {
|
||||
t.Fatal("导出应在提交任务前拒绝空批量输入")
|
||||
}
|
||||
}
|
||||
var omitted model.TSimCardInfoListParam
|
||||
if err := json.Unmarshal([]byte(`{}`), &omitted); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if omitted.BatchInput != nil {
|
||||
t.Fatal("省略批量字段应保持原列表查询语义")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSimCardBatchExportKeepsListReuse(t *testing.T) {
|
||||
data, err := os.ReadFile("t_sim_card_info.go")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
source := string(data)
|
||||
for _, fragment := range []string{"QueryParam: in,", "query := *in", "s.List(ctx, &query)", "mod := s.Model(ctx)", "mod = mod.Where(batchCondition, batchArgs...)"} {
|
||||
if !strings.Contains(source, fragment) {
|
||||
t.Errorf("批量查询必须保留现有权限及导出复用: %s", fragment)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCardChannelAssocExistsSQLUsesChannelKeyOnly(t *testing.T) {
|
||||
query := cardChannelAssocExistsSQL("")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user