Procházet zdrojové kódy

添加批量删除

yjp před 1 rokem
rodič
revize
aa22192a7d
2 změnil soubory, kde provedl 88 přidání a 0 odebrání
  1. 11 0
      test/v1/sdk.go
  2. 77 0
      test/v1/v1_test.go

+ 11 - 0
test/v1/sdk.go

@@ -78,6 +78,17 @@ func (toolKit *ToolKit) delete(req *ports.DeleteRequest) *ToolKit {
 	return toolKit
 }
 
+func (toolKit *ToolKit) deleteBatch(req *ports.DeleteBatchRequest) *ToolKit {
+	statement, err := clientInstance.DeleteBatch(req)
+	if err != nil {
+		toolKit.t.Fatal(err)
+	}
+
+	fmt.Println(statement)
+
+	return toolKit
+}
+
 func (toolKit *ToolKit) update(req *ports.UpdateRequest) *ToolKit {
 	statement, err := clientInstance.Update(req)
 	if err != nil {

+ 77 - 0
test/v1/v1_test.go

@@ -278,6 +278,83 @@ func TestDelete(t *testing.T) {
 		assertEqual(int64(0), count, "数量不一致")
 }
 
+func TestDeleteBatch(t *testing.T) {
+	initClient(t, "localhost:30170")
+	defer destroyClient(t)
+
+	tablePrefix := "test." + simpleUUID()[0:8]
+
+	id1 := simpleUUID()
+	name1 := simpleUUID()
+	now1 := time.Now().Local()
+	tableNum1 := rand.New(rand.NewSource(now1.Unix())).Intn(10)
+
+	id2 := simpleUUID()
+	name2 := simpleUUID()
+	now2 := time.Now().Local()
+	tableNum2 := rand.New(rand.NewSource(now2.Unix())).Intn(10)
+
+	var count int64
+
+	newToolKit(t).
+		autoMigrate(&ports.AutoMigrateRequest{
+			DatabaseID:            "2b78141779ee432295ca371b91c5cac7",
+			TablePrefixWithSchema: tablePrefix,
+			Version:               "v1",
+			TableModelDescribe:    tableModelDescribe,
+		}).
+		insertBatch(&ports.InsertBatchRequest{
+			DatabaseID: "2b78141779ee432295ca371b91c5cac7",
+			Items: []*ports.InsertTableItem{
+				{
+					TablePrefixWithSchema: tablePrefix,
+					Version:               "v1",
+					Items: []*ports.InsertItem{
+						{
+							KeyColumns: []string{"id"},
+							TableRow: map[string]any{
+								"id":        id1,
+								"name":      name1,
+								"time":      now1,
+								"table_num": tableNum1,
+							},
+						},
+						{
+							KeyColumns: []string{"id"},
+							TableRow: map[string]any{
+								"id":        id2,
+								"name":      name2,
+								"time":      now2,
+								"table_num": tableNum2,
+							},
+						},
+					},
+				},
+			},
+			UserID: "test",
+		}).
+		deleteBatch(&ports.DeleteBatchRequest{
+			DatabaseID: "2b78141779ee432295ca371b91c5cac7",
+			Items: []*ports.DeleteTableItem{
+				{
+					TablePrefixWithSchema: tablePrefix,
+					Version:               "v1",
+					Items: []*ports.DeleteItem{
+						{KeyValues: map[string]string{"id": id1}},
+						{KeyValues: map[string]string{"id": id2}},
+					},
+				},
+			},
+			UserID: "test",
+		}).
+		commonCount(&ports.CommonCountRequest{
+			DatabaseID:            "2b78141779ee432295ca371b91c5cac7",
+			TablePrefixWithSchema: tablePrefix,
+			Version:               "v1",
+		}, &count).
+		assertEqual(int64(0), count, "数量不一致")
+}
+
 func TestReply(t *testing.T) {
 	initClient(t, "localhost:30170")
 	defer destroyClient(t)