yjp 1 anno fa
parent
commit
684be0a3ea
3 ha cambiato i file con 64 aggiunte e 0 eliminazioni
  1. 1 0
      ports/client.go
  2. 11 0
      test/v1/sdk.go
  3. 52 0
      test/v1/v1_test.go

+ 1 - 0
ports/client.go

@@ -17,6 +17,7 @@ type Client interface {
 	Insert(request *InsertRequest) (string, error)
 	Delete(request *DeleteRequest) (string, error)
 	Update(request *UpdateRequest) (string, error)
+	Replay(req *ReplayRequest) (string, error)
 	QueryByWhereAndOrderBy(request *QueryByWhereAndOrderByRequest) (string, []map[string]any, int64, error)
 	CommonQuery(request *CommonQueryRequest) (string, []map[string]any, int64, error)
 	QueryByKeys(request *QueryByKeysRequest) (string, map[string]any, error)

+ 11 - 0
test/v1/sdk.go

@@ -78,6 +78,17 @@ func (toolKit *ToolKit) update(req *ports.UpdateRequest) *ToolKit {
 	return toolKit
 }
 
+func (toolKit *ToolKit) reply(req *ports.ReplayRequest) *ToolKit {
+	statement, err := clientInstance.Replay(req)
+	if err != nil {
+		toolKit.t.Fatal(err)
+	}
+
+	fmt.Println(statement)
+
+	return toolKit
+}
+
 func (toolKit *ToolKit) queryByWhereAndOrderBy(req *ports.QueryByWhereAndOrderByRequest, retInfosMap *[]map[string]any) *ToolKit {
 	statement, infosMap, totalCount, err := clientInstance.QueryByWhereAndOrderBy(req)
 	if err != nil {

+ 52 - 0
test/v1/v1_test.go

@@ -188,3 +188,55 @@ func TestDelete(t *testing.T) {
 		}, &count).
 		assertEqual(int64(0), count, "数量不一致")
 }
+
+func TestReply(t *testing.T) {
+	initClient(t, "localhost:30170")
+	defer destroyClient(t)
+
+	tablePrefix := "test." + simpleUUID()[0:8]
+
+	id := simpleUUID()
+	name := simpleUUID()
+	now := time.Now().Local()
+	tableNum := rand.New(rand.NewSource(now.Unix())).Intn(10)
+
+	resultMap := make(map[string]any)
+
+	newToolKit(t).
+		autoMigrate(&ports.AutoMigrateRequest{
+			DatabaseID:            "2b78141779ee432295ca371b91c5cac7",
+			TablePrefixWithSchema: tablePrefix,
+			Version:               "v1",
+			TableModelDescribe:    tableModelDescribe,
+		}).
+		insert(&ports.InsertRequest{
+			DatabaseID:            "2b78141779ee432295ca371b91c5cac7",
+			TablePrefixWithSchema: tablePrefix,
+			Version:               "v1",
+			KeyColumns:            []string{"id"},
+			TableRow: map[string]any{
+				"id":        id,
+				"name":      name,
+				"time":      now,
+				"table_num": tableNum,
+			},
+			UserID: "test",
+		}).
+		reply(&ports.ReplayRequest{
+			DatabaseID:            "2b78141779ee432295ca371b91c5cac7",
+			TablePrefixWithSchema: tablePrefix,
+			Version:               "v1",
+			KeyValues:             map[string]string{"id": id},
+			UserID:                "test",
+		}).
+		queryByKeys(&ports.QueryByKeysRequest{
+			DatabaseID:            "2b78141779ee432295ca371b91c5cac7",
+			TablePrefixWithSchema: tablePrefix,
+			Version:               "v1",
+			KeyValues:             map[string]string{"id": id},
+		}, &resultMap).
+		assertEqual(id, resultMap["id"], "ID不一致").
+		assertEqual(name, resultMap["name"], "名称不一致").
+		assertEqual(now.UnixMilli(), resultMap["time"].(time.Time).Local().UnixMilli(), "时间不一致").
+		assertEqual(tableNum, resultMap["table_num"], "表数量不一致")
+}