|
@@ -0,0 +1,922 @@
|
|
|
|
+package instance
|
|
|
|
+
|
|
|
|
+import (
|
|
|
|
+ "fmt"
|
|
|
|
+ "git.sxidc.com/service-supports/dps-sdk/client"
|
|
|
|
+ uuid "github.com/satori/go.uuid"
|
|
|
|
+ "math/rand"
|
|
|
|
+ "strings"
|
|
|
|
+ "testing"
|
|
|
|
+ "time"
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+func getUUID() string {
|
|
|
|
+ return uuid.NewV4().String()
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func simpleUUID() string {
|
|
|
|
+ return strings.ReplaceAll(getUUID(), "-", "")
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+var tableModelDescribe = map[string]string{
|
|
|
|
+ "ID": "gorm:\"primary_key;type:varchar(32);comment:id;\"",
|
|
|
|
+ "Name": "gorm:\"not null;type:varchar(128);comment:数据库名称;\"",
|
|
|
|
+ "Time": "gorm:\"not null;type:timestamp with time zone;comment:数据库时间;\"",
|
|
|
|
+ "TableNum": "gorm:\"not null;type:integer;comment:数据库表数量;\"",
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func TestAutoMigrate(t *testing.T) {
|
|
|
|
+ initClient(t, "localhost:30170", "2b78141779ee432295ca371b91c5cac7")
|
|
|
|
+ defer destroyClient(t, "2b78141779ee432295ca371b91c5cac7")
|
|
|
|
+
|
|
|
|
+ newToolKit(t).
|
|
|
|
+ autoMigrate([]client.AutoMigrateItem{
|
|
|
|
+ {
|
|
|
|
+ TablePrefixWithSchema: "test." + simpleUUID()[0:8],
|
|
|
|
+ Version: "v1",
|
|
|
|
+ TableModelDescribe: tableModelDescribe,
|
|
|
|
+ },
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func TestTransaction(t *testing.T) {
|
|
|
|
+ initClient(t, "localhost:30170", "2b78141779ee432295ca371b91c5cac7")
|
|
|
|
+ defer destroyClient(t, "2b78141779ee432295ca371b91c5cac7")
|
|
|
|
+
|
|
|
|
+ tablePrefix := "test." + simpleUUID()[0:8]
|
|
|
|
+
|
|
|
|
+ id := simpleUUID()
|
|
|
|
+ name := simpleUUID()
|
|
|
|
+ now := time.Now().Local()
|
|
|
|
+ tableNum := rand.New(rand.NewSource(now.Unix())).Intn(10)
|
|
|
|
+ newName := simpleUUID()
|
|
|
|
+ newNow := time.Now().Local()
|
|
|
|
+ newTableNum := rand.New(rand.NewSource(now.Unix())).Intn(10)
|
|
|
|
+
|
|
|
|
+ var count int64
|
|
|
|
+ resultMap := make(map[string]any)
|
|
|
|
+
|
|
|
|
+ newToolKit(t).
|
|
|
|
+ autoMigrate([]client.AutoMigrateItem{
|
|
|
|
+ {
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ TableModelDescribe: tableModelDescribe,
|
|
|
|
+ },
|
|
|
|
+ }).
|
|
|
|
+ transaction(func(tx client.Transaction) error {
|
|
|
|
+ statement, err := tx.InsertTx(&client.InsertRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ KeyColumns: []string{"id"},
|
|
|
|
+ TableRow: map[string]any{
|
|
|
|
+ "id": id,
|
|
|
|
+ "name": name,
|
|
|
|
+ "time": now,
|
|
|
|
+ "table_num": tableNum,
|
|
|
|
+ },
|
|
|
|
+ UserID: "test",
|
|
|
|
+ })
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fmt.Println(statement)
|
|
|
|
+
|
|
|
|
+ return nil
|
|
|
|
+ }).
|
|
|
|
+ queryByKeys(&client.QueryByKeysRequest{
|
|
|
|
+ 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).UnixMilli(), "时间不一致").
|
|
|
|
+ assertEqual(tableNum, resultMap["table_num"], "表数量不一致").
|
|
|
|
+ transaction(func(tx client.Transaction) error {
|
|
|
|
+ statement, err := tx.UpdateTx(&client.UpdateRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ KeyValues: map[string]string{"id": id},
|
|
|
|
+ NewTableRow: map[string]any{
|
|
|
|
+ "id": id,
|
|
|
|
+ "name": newName,
|
|
|
|
+ "time": newNow,
|
|
|
|
+ "table_num": newTableNum,
|
|
|
|
+ },
|
|
|
|
+ UserID: "test",
|
|
|
|
+ })
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fmt.Println(statement)
|
|
|
|
+
|
|
|
|
+ return nil
|
|
|
|
+ }).
|
|
|
|
+ queryByKeys(&client.QueryByKeysRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ KeyValues: map[string]string{"id": id},
|
|
|
|
+ }, &resultMap).
|
|
|
|
+ assertEqual(id, resultMap["id"], "ID不一致").
|
|
|
|
+ assertEqual(newName, resultMap["name"], "名称不一致").
|
|
|
|
+ assertEqual(newNow.UnixMilli(), resultMap["time"].(time.Time).UnixMilli(), "时间不一致").
|
|
|
|
+ assertEqual(newTableNum, resultMap["table_num"], "表数量不一致").
|
|
|
|
+ transaction(func(tx client.Transaction) error {
|
|
|
|
+ statement, err := tx.UpdateTx(&client.UpdateRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ KeyValues: map[string]string{"id": id},
|
|
|
|
+ NewTableRow: map[string]any{
|
|
|
|
+ "id": id,
|
|
|
|
+ "name": name,
|
|
|
|
+ "time": now,
|
|
|
|
+ "table_num": tableNum,
|
|
|
|
+ },
|
|
|
|
+ UserID: "test",
|
|
|
|
+ })
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fmt.Println(statement)
|
|
|
|
+
|
|
|
|
+ statement, err = tx.DeleteTx(&client.DeleteRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ KeyValues: map[string]string{"id": id},
|
|
|
|
+ UserID: "test",
|
|
|
|
+ })
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fmt.Println(statement)
|
|
|
|
+
|
|
|
|
+ return nil
|
|
|
|
+ }).
|
|
|
|
+ countWhere(&client.CountWhereRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ Where: map[string][]any{
|
|
|
|
+ "id = ?": {id},
|
|
|
|
+ },
|
|
|
|
+ }, &count).
|
|
|
|
+ assertEqual(int64(0), count, "数量不一致")
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func TestTransactionBatch(t *testing.T) {
|
|
|
|
+ initClient(t, "localhost:30170", "2b78141779ee432295ca371b91c5cac7")
|
|
|
|
+ defer destroyClient(t, "2b78141779ee432295ca371b91c5cac7")
|
|
|
|
+
|
|
|
|
+ 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
|
|
|
|
+ resultMap := make(map[string]any)
|
|
|
|
+
|
|
|
|
+ newToolKit(t).
|
|
|
|
+ autoMigrate([]client.AutoMigrateItem{
|
|
|
|
+ {
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ TableModelDescribe: tableModelDescribe,
|
|
|
|
+ },
|
|
|
|
+ }).
|
|
|
|
+ transaction(func(tx client.Transaction) error {
|
|
|
|
+ statement, err := tx.InsertBatchTx(&client.InsertBatchRequest{
|
|
|
|
+ Items: []client.InsertTableRowItem{
|
|
|
|
+ {
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ KeyColumns: []string{"id"},
|
|
|
|
+ TableRows: []map[string]any{
|
|
|
|
+ {
|
|
|
|
+ "id": id1,
|
|
|
|
+ "name": name1,
|
|
|
|
+ "time": now1,
|
|
|
|
+ "table_num": tableNum1,
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ "id": id2,
|
|
|
|
+ "name": name2,
|
|
|
|
+ "time": now2,
|
|
|
|
+ "table_num": tableNum2,
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ })
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fmt.Println(statement)
|
|
|
|
+
|
|
|
|
+ return nil
|
|
|
|
+ }).
|
|
|
|
+ queryByKeys(&client.QueryByKeysRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ KeyValues: map[string]string{"id": id1},
|
|
|
|
+ }, &resultMap).
|
|
|
|
+ assertEqual(id1, resultMap["id"], "ID不一致").
|
|
|
|
+ assertEqual(name1, resultMap["name"], "名称不一致").
|
|
|
|
+ assertEqual(now1.UnixMilli(), resultMap["time"].(time.Time).UnixMilli(), "时间不一致").
|
|
|
|
+ assertEqual(tableNum1, resultMap["table_num"], "表数量不一致").
|
|
|
|
+ queryByKeys(&client.QueryByKeysRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ KeyValues: map[string]string{"id": id2},
|
|
|
|
+ }, &resultMap).
|
|
|
|
+ assertEqual(id2, resultMap["id"], "ID不一致").
|
|
|
|
+ assertEqual(name2, resultMap["name"], "名称不一致").
|
|
|
|
+ assertEqual(now2.UnixMilli(), resultMap["time"].(time.Time).UnixMilli(), "时间不一致").
|
|
|
|
+ assertEqual(tableNum2, resultMap["table_num"], "表数量不一致").
|
|
|
|
+ transaction(func(tx client.Transaction) error {
|
|
|
|
+ statement, err := tx.DeleteBatchTx(&client.DeleteBatchRequest{
|
|
|
|
+ Items: []client.DeleteTableRowItem{
|
|
|
|
+ {
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ KeyValues: []map[string]string{
|
|
|
|
+ {"id": id1},
|
|
|
|
+ {"id": id2},
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ UserID: "test",
|
|
|
|
+ })
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fmt.Println(statement)
|
|
|
|
+
|
|
|
|
+ return nil
|
|
|
|
+ }).
|
|
|
|
+ countWhere(&client.CountWhereRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ Where: map[string][]any{
|
|
|
|
+ "id = ?": {id1},
|
|
|
|
+ },
|
|
|
|
+ }, &count).
|
|
|
|
+ assertEqual(int64(0), count, "数量不一致").
|
|
|
|
+ countWhere(&client.CountWhereRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ Where: map[string][]any{
|
|
|
|
+ "id = ?": {id2},
|
|
|
|
+ },
|
|
|
|
+ }, &count).
|
|
|
|
+ assertEqual(int64(0), count, "数量不一致")
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func TestInsert(t *testing.T) {
|
|
|
|
+ initClient(t, "localhost:30170", "2b78141779ee432295ca371b91c5cac7")
|
|
|
|
+ defer destroyClient(t, "2b78141779ee432295ca371b91c5cac7")
|
|
|
|
+
|
|
|
|
+ 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([]client.AutoMigrateItem{
|
|
|
|
+ {
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ TableModelDescribe: tableModelDescribe,
|
|
|
|
+ },
|
|
|
|
+ }).
|
|
|
|
+ insert(&client.InsertRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ KeyColumns: []string{"id"},
|
|
|
|
+ TableRow: map[string]any{
|
|
|
|
+ "id": id,
|
|
|
|
+ "name": name,
|
|
|
|
+ "time": now,
|
|
|
|
+ "table_num": tableNum,
|
|
|
|
+ },
|
|
|
|
+ UserID: "test",
|
|
|
|
+ }).
|
|
|
|
+ queryByKeys(&client.QueryByKeysRequest{
|
|
|
|
+ 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"], "表数量不一致")
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func TestInsertBatch(t *testing.T) {
|
|
|
|
+ initClient(t, "localhost:30170", "2b78141779ee432295ca371b91c5cac7")
|
|
|
|
+ defer destroyClient(t, "2b78141779ee432295ca371b91c5cac7")
|
|
|
|
+
|
|
|
|
+ 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)
|
|
|
|
+
|
|
|
|
+ resultsMap := make([]map[string]any, 0)
|
|
|
|
+ var totalCount int64
|
|
|
|
+
|
|
|
|
+ newToolKit(t).
|
|
|
|
+ autoMigrate([]client.AutoMigrateItem{
|
|
|
|
+ {
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ TableModelDescribe: tableModelDescribe,
|
|
|
|
+ },
|
|
|
|
+ }).
|
|
|
|
+ insertBatch(&client.InsertBatchRequest{
|
|
|
|
+ Items: []client.InsertTableRowItem{
|
|
|
|
+ {
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ KeyColumns: []string{"id"},
|
|
|
|
+ TableRows: []map[string]any{
|
|
|
|
+ {
|
|
|
|
+ "id": id1,
|
|
|
|
+ "name": name1,
|
|
|
|
+ "time": now1,
|
|
|
|
+ "table_num": tableNum1,
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ "id": id2,
|
|
|
|
+ "name": name2,
|
|
|
|
+ "time": now2,
|
|
|
|
+ "table_num": tableNum2,
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ }).
|
|
|
|
+ queryByWhereAndOrderBy(&client.QueryByWhereAndOrderByRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ Where: map[string][]any{
|
|
|
|
+ "id = ? AND name = ? AND table_num = ?": {id1, name1, tableNum1},
|
|
|
|
+ },
|
|
|
|
+ PageNo: 1,
|
|
|
|
+ PageSize: 1,
|
|
|
|
+ }, &resultsMap, &totalCount).
|
|
|
|
+ assertEqual(1, int(totalCount), "总数不一致").
|
|
|
|
+ assertEqual(id1, resultsMap[0]["id"], "ID不一致").
|
|
|
|
+ assertEqual(name1, resultsMap[0]["name"], "名称不一致").
|
|
|
|
+ assertEqual(now1.UnixMilli(), resultsMap[0]["time"].(time.Time).Local().UnixMilli(), "时间不一致").
|
|
|
|
+ assertEqual(tableNum1, resultsMap[0]["table_num"], "表数量不一致").
|
|
|
|
+ commonQuery(&client.CommonQueryRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ Where: map[string][]any{
|
|
|
|
+ "id = ? AND name = ? AND table_num = ?": {id2, name2, tableNum2},
|
|
|
|
+ },
|
|
|
|
+ PageNo: 1,
|
|
|
|
+ PageSize: 1,
|
|
|
|
+ }, &resultsMap, &totalCount).
|
|
|
|
+ assertEqual(1, int(totalCount), "总数不一致").
|
|
|
|
+ assertEqual(id2, resultsMap[0]["id"], "ID不一致").
|
|
|
|
+ assertEqual(name2, resultsMap[0]["name"], "名称不一致").
|
|
|
|
+ assertEqual(now2.UnixMilli(), resultsMap[0]["time"].(time.Time).Local().UnixMilli(), "时间不一致").
|
|
|
|
+ assertEqual(tableNum2, resultsMap[0]["table_num"], "表数量不一致")
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func TestUpdate(t *testing.T) {
|
|
|
|
+ initClient(t, "localhost:30170", "2b78141779ee432295ca371b91c5cac7")
|
|
|
|
+ defer destroyClient(t, "2b78141779ee432295ca371b91c5cac7")
|
|
|
|
+
|
|
|
|
+ tablePrefix := "test." + simpleUUID()[0:8]
|
|
|
|
+
|
|
|
|
+ id := simpleUUID()
|
|
|
|
+ name := simpleUUID()
|
|
|
|
+ now := time.Now().Local()
|
|
|
|
+ tableNum := rand.New(rand.NewSource(now.Unix())).Intn(10)
|
|
|
|
+ newName := simpleUUID()
|
|
|
|
+ newNow := time.Now().Local()
|
|
|
|
+ newTableNum := rand.New(rand.NewSource(now.Unix())).Intn(10)
|
|
|
|
+
|
|
|
|
+ resultMap := make(map[string]any)
|
|
|
|
+
|
|
|
|
+ newToolKit(t).
|
|
|
|
+ autoMigrate([]client.AutoMigrateItem{
|
|
|
|
+ {
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ TableModelDescribe: tableModelDescribe,
|
|
|
|
+ },
|
|
|
|
+ }).
|
|
|
|
+ insert(&client.InsertRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ KeyColumns: []string{"id"},
|
|
|
|
+ TableRow: map[string]any{
|
|
|
|
+ "id": id,
|
|
|
|
+ "name": name,
|
|
|
|
+ "time": now,
|
|
|
|
+ "table_num": tableNum,
|
|
|
|
+ },
|
|
|
|
+ UserID: "test",
|
|
|
|
+ }).
|
|
|
|
+ update(&client.UpdateRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ KeyValues: map[string]string{"id": id},
|
|
|
|
+ NewTableRow: map[string]any{
|
|
|
|
+ "id": id,
|
|
|
|
+ "name": newName,
|
|
|
|
+ "time": newNow,
|
|
|
|
+ "table_num": newTableNum,
|
|
|
|
+ },
|
|
|
|
+ UserID: "test",
|
|
|
|
+ }).
|
|
|
|
+ queryByKeys(&client.QueryByKeysRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ KeyValues: map[string]string{"id": id},
|
|
|
|
+ }, &resultMap).
|
|
|
|
+ assertEqual(id, resultMap["id"], "ID不一致").
|
|
|
|
+ assertEqual(newName, resultMap["name"], "名称不一致").
|
|
|
|
+ assertEqual(newNow.UnixMilli(), resultMap["time"].(time.Time).Local().UnixMilli(), "时间不一致").
|
|
|
|
+ assertEqual(newTableNum, resultMap["table_num"], "表数量不一致")
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func TestDelete(t *testing.T) {
|
|
|
|
+ initClient(t, "localhost:30170", "2b78141779ee432295ca371b91c5cac7")
|
|
|
|
+ defer destroyClient(t, "2b78141779ee432295ca371b91c5cac7")
|
|
|
|
+
|
|
|
|
+ tablePrefix := "test." + simpleUUID()[0:8]
|
|
|
|
+
|
|
|
|
+ id := simpleUUID()
|
|
|
|
+ name := simpleUUID()
|
|
|
|
+ now := time.Now().Local()
|
|
|
|
+ tableNum := rand.New(rand.NewSource(now.Unix())).Intn(10)
|
|
|
|
+
|
|
|
|
+ var count int64
|
|
|
|
+
|
|
|
|
+ newToolKit(t).
|
|
|
|
+ autoMigrate([]client.AutoMigrateItem{
|
|
|
|
+ {
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ TableModelDescribe: tableModelDescribe,
|
|
|
|
+ },
|
|
|
|
+ }).
|
|
|
|
+ insert(&client.InsertRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ KeyColumns: []string{"id"},
|
|
|
|
+ TableRow: map[string]any{
|
|
|
|
+ "id": id,
|
|
|
|
+ "name": name,
|
|
|
|
+ "time": now,
|
|
|
|
+ "table_num": tableNum,
|
|
|
|
+ },
|
|
|
|
+ UserID: "test",
|
|
|
|
+ }).
|
|
|
|
+ delete(&client.DeleteRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ KeyValues: map[string]string{"id": id},
|
|
|
|
+ UserID: "test",
|
|
|
|
+ }).
|
|
|
|
+ countWhere(&client.CountWhereRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ Where: map[string][]any{
|
|
|
|
+ "id = ?": {id},
|
|
|
|
+ },
|
|
|
|
+ }, &count).
|
|
|
|
+ assertEqual(int64(0), count, "数量不一致")
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func TestDeleteBatch(t *testing.T) {
|
|
|
|
+ initClient(t, "localhost:30170", "2b78141779ee432295ca371b91c5cac7")
|
|
|
|
+ defer destroyClient(t, "2b78141779ee432295ca371b91c5cac7")
|
|
|
|
+
|
|
|
|
+ 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([]client.AutoMigrateItem{
|
|
|
|
+ {
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ TableModelDescribe: tableModelDescribe,
|
|
|
|
+ },
|
|
|
|
+ }).
|
|
|
|
+ insertBatch(&client.InsertBatchRequest{
|
|
|
|
+ Items: []client.InsertTableRowItem{
|
|
|
|
+ {
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ KeyColumns: []string{"id"},
|
|
|
|
+ TableRows: []map[string]any{
|
|
|
|
+ {
|
|
|
|
+ "id": id1,
|
|
|
|
+ "name": name1,
|
|
|
|
+ "time": now1,
|
|
|
|
+ "table_num": tableNum1,
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ "id": id2,
|
|
|
|
+ "name": name2,
|
|
|
|
+ "time": now2,
|
|
|
|
+ "table_num": tableNum2,
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ }).
|
|
|
|
+ deleteBatch(&client.DeleteBatchRequest{
|
|
|
|
+ Items: []client.DeleteTableRowItem{
|
|
|
|
+ {
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ KeyValues: []map[string]string{
|
|
|
|
+ {"id": id1},
|
|
|
|
+ {"id": id2},
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ UserID: "test",
|
|
|
|
+ }).
|
|
|
|
+ commonCount(&client.CommonCountRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ }, &count).
|
|
|
|
+ assertEqual(int64(0), count, "数量不一致")
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func TestReply(t *testing.T) {
|
|
|
|
+ initClient(t, "localhost:30170", "2b78141779ee432295ca371b91c5cac7")
|
|
|
|
+ defer destroyClient(t, "2b78141779ee432295ca371b91c5cac7")
|
|
|
|
+
|
|
|
|
+ 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([]client.AutoMigrateItem{
|
|
|
|
+ {
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ TableModelDescribe: tableModelDescribe,
|
|
|
|
+ },
|
|
|
|
+ }).
|
|
|
|
+ insert(&client.InsertRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ KeyColumns: []string{"id"},
|
|
|
|
+ TableRow: map[string]any{
|
|
|
|
+ "id": id,
|
|
|
|
+ "name": name,
|
|
|
|
+ "time": now,
|
|
|
|
+ "table_num": tableNum,
|
|
|
|
+ },
|
|
|
|
+ UserID: "test",
|
|
|
|
+ }).
|
|
|
|
+ reply(&client.ReplayRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ KeyValues: map[string]string{"id": id},
|
|
|
|
+ UserID: "test",
|
|
|
|
+ }).
|
|
|
|
+ queryByKeys(&client.QueryByKeysRequest{
|
|
|
|
+ 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"], "表数量不一致")
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func TestEventQuery(t *testing.T) {
|
|
|
|
+ initClient(t, "localhost:30170", "2b78141779ee432295ca371b91c5cac7")
|
|
|
|
+ defer destroyClient(t, "2b78141779ee432295ca371b91c5cac7")
|
|
|
|
+
|
|
|
|
+ tablePrefix := "test." + simpleUUID()[0:8]
|
|
|
|
+
|
|
|
|
+ id := simpleUUID()
|
|
|
|
+ name := simpleUUID()
|
|
|
|
+ now := time.Now().Local()
|
|
|
|
+ tableNum := rand.New(rand.NewSource(now.Unix())).Intn(10)
|
|
|
|
+ newName := simpleUUID()
|
|
|
|
+ newNow := time.Now().Local()
|
|
|
|
+ newTableNum := rand.New(rand.NewSource(now.Unix())).Intn(10)
|
|
|
|
+
|
|
|
|
+ var totalCount int64
|
|
|
|
+ eventInfos := make([]client.EventInfo, 0)
|
|
|
|
+
|
|
|
|
+ newToolKit(t).
|
|
|
|
+ autoMigrate([]client.AutoMigrateItem{
|
|
|
|
+ {
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ TableModelDescribe: tableModelDescribe,
|
|
|
|
+ },
|
|
|
|
+ }).
|
|
|
|
+ insert(&client.InsertRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ KeyColumns: []string{"id"},
|
|
|
|
+ TableRow: map[string]any{
|
|
|
|
+ "id": id,
|
|
|
|
+ "name": name,
|
|
|
|
+ "time": now,
|
|
|
|
+ "table_num": tableNum,
|
|
|
|
+ },
|
|
|
|
+ UserID: "test",
|
|
|
|
+ }).
|
|
|
|
+ update(&client.UpdateRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ KeyValues: map[string]string{"id": id},
|
|
|
|
+ NewTableRow: map[string]any{
|
|
|
|
+ "id": id,
|
|
|
|
+ "name": newName,
|
|
|
|
+ "time": newNow,
|
|
|
|
+ "table_num": newTableNum,
|
|
|
|
+ },
|
|
|
|
+ UserID: "test",
|
|
|
|
+ }).
|
|
|
|
+ countEventByKeys(&client.CountEventByKeysRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ KeyValues: []string{id},
|
|
|
|
+ }, &totalCount).
|
|
|
|
+ assertEqual(2, int(totalCount), "总数不一致").
|
|
|
|
+ commonCountEvent(&client.CommonCountEventRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ KeyValues: []string{id},
|
|
|
|
+ Version: "v1",
|
|
|
|
+ Operation: "create",
|
|
|
|
+ CreatorID: "test",
|
|
|
|
+ StartCreatedTime: now.Format(time.DateTime),
|
|
|
|
+ EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
|
|
|
|
+ }, &totalCount).
|
|
|
|
+ assertEqual(1, int(totalCount), "总数不一致").
|
|
|
|
+ commonCountEvent(&client.CommonCountEventRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ KeyValues: []string{id},
|
|
|
|
+ Version: "v1",
|
|
|
|
+ Operation: "update",
|
|
|
|
+ CreatorID: "test",
|
|
|
|
+ StartCreatedTime: now.Format(time.DateTime),
|
|
|
|
+ EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
|
|
|
|
+ }, &totalCount).
|
|
|
|
+ assertEqual(1, int(totalCount), "总数不一致").
|
|
|
|
+ eventQueryByKeys(&client.EventQueryByKeysRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ KeyValues: []string{id},
|
|
|
|
+ PageNo: 0,
|
|
|
|
+ PageSize: 0,
|
|
|
|
+ }, &eventInfos, &totalCount).
|
|
|
|
+ assertEqual(2, int(totalCount), "总数不一致").
|
|
|
|
+ assertEqual(2, len(eventInfos), "事件数量不一致").
|
|
|
|
+ assertEqual(id, eventInfos[0].Key, "关键字段不一致").
|
|
|
|
+ assertEqual("v1", eventInfos[0].Version, "版本不一致").
|
|
|
|
+ assertEqual("create", eventInfos[0].Operation, "操作不一致").
|
|
|
|
+ assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
|
|
|
|
+ assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
|
|
|
|
+ assertNotEmpty(eventInfos[0].Value, "值为空不一致").
|
|
|
|
+ assertEqual(id, eventInfos[1].Key, "关键字段不一致").
|
|
|
|
+ assertEqual("v1", eventInfos[1].Version, "版本不一致").
|
|
|
|
+ assertEqual("update", eventInfos[1].Operation, "操作不一致").
|
|
|
|
+ assertEqual("test", eventInfos[1].CreatorID, "创建者ID不一致").
|
|
|
|
+ assertNotEmpty(eventInfos[1].CreateTime, "创建事件为空").
|
|
|
|
+ assertNotEmpty(eventInfos[1].Value, "值为空不一致").
|
|
|
|
+ eventQueryByKeys(&client.EventQueryByKeysRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ KeyValues: []string{id},
|
|
|
|
+ PageNo: 1,
|
|
|
|
+ PageSize: 1,
|
|
|
|
+ }, &eventInfos, &totalCount).
|
|
|
|
+ assertEqual(2, int(totalCount), "总数不一致").
|
|
|
|
+ assertEqual(1, len(eventInfos), "事件数量不一致").
|
|
|
|
+ assertEqual(id, eventInfos[0].Key, "关键字段不一致").
|
|
|
|
+ assertEqual("v1", eventInfos[0].Version, "版本不一致").
|
|
|
|
+ assertEqual("create", eventInfos[0].Operation, "操作不一致").
|
|
|
|
+ assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
|
|
|
|
+ assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
|
|
|
|
+ assertNotEmpty(eventInfos[0].Value, "值为空不一致").
|
|
|
|
+ commonEventQuery(&client.CommonEventQueryRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ KeyValues: []string{id},
|
|
|
|
+ Version: "v1",
|
|
|
|
+ Operation: "create",
|
|
|
|
+ CreatorID: "test",
|
|
|
|
+ StartCreatedTime: now.Format(time.DateTime),
|
|
|
|
+ EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
|
|
|
|
+ PageNo: 0,
|
|
|
|
+ PageSize: 0,
|
|
|
|
+ }, &eventInfos, &totalCount).
|
|
|
|
+ assertEqual(1, int(totalCount), "总数不一致").
|
|
|
|
+ assertEqual(1, len(eventInfos), "事件数量不一致").
|
|
|
|
+ assertEqual(id, eventInfos[0].Key, "关键字段不一致").
|
|
|
|
+ assertEqual("v1", eventInfos[0].Version, "版本不一致").
|
|
|
|
+ assertEqual("create", eventInfos[0].Operation, "操作不一致").
|
|
|
|
+ assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
|
|
|
|
+ assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
|
|
|
|
+ assertNotEmpty(eventInfos[0].Value, "值为空不一致").
|
|
|
|
+ commonEventQuery(&client.CommonEventQueryRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ KeyValues: []string{id},
|
|
|
|
+ Version: "v1",
|
|
|
|
+ Operation: "update",
|
|
|
|
+ CreatorID: "test",
|
|
|
|
+ StartCreatedTime: now.Format(time.DateTime),
|
|
|
|
+ EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
|
|
|
|
+ PageNo: 0,
|
|
|
|
+ PageSize: 0,
|
|
|
|
+ }, &eventInfos, &totalCount).
|
|
|
|
+ assertEqual(1, int(totalCount), "总数不一致").
|
|
|
|
+ assertEqual(1, len(eventInfos), "事件数量不一致").
|
|
|
|
+ assertEqual(id, eventInfos[0].Key, "关键字段不一致").
|
|
|
|
+ assertEqual("v1", eventInfos[0].Version, "版本不一致").
|
|
|
|
+ assertEqual("update", eventInfos[0].Operation, "操作不一致").
|
|
|
|
+ assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
|
|
|
|
+ assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
|
|
|
|
+ assertNotEmpty(eventInfos[0].Value, "值为空不一致").
|
|
|
|
+ delete(&client.DeleteRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ Version: "v1",
|
|
|
|
+ KeyValues: map[string]string{"id": id},
|
|
|
|
+ UserID: "test",
|
|
|
|
+ }).
|
|
|
|
+ countEventHistoryByKeys(&client.CountEventByKeysRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ KeyValues: []string{id},
|
|
|
|
+ }, &totalCount).
|
|
|
|
+ assertEqual(3, int(totalCount), "总数不一致").
|
|
|
|
+ commonCountEventHistory(&client.CommonCountEventRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ KeyValues: []string{id},
|
|
|
|
+ Version: "v1",
|
|
|
|
+ Operation: "create",
|
|
|
|
+ CreatorID: "test",
|
|
|
|
+ StartCreatedTime: now.Format(time.DateTime),
|
|
|
|
+ EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
|
|
|
|
+ }, &totalCount).
|
|
|
|
+ assertEqual(1, int(totalCount), "总数不一致").
|
|
|
|
+ commonCountEventHistory(&client.CommonCountEventRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ KeyValues: []string{id},
|
|
|
|
+ Version: "v1",
|
|
|
|
+ Operation: "update",
|
|
|
|
+ CreatorID: "test",
|
|
|
|
+ StartCreatedTime: now.Format(time.DateTime),
|
|
|
|
+ EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
|
|
|
|
+ }, &totalCount).
|
|
|
|
+ assertEqual(1, int(totalCount), "总数不一致").
|
|
|
|
+ commonCountEventHistory(&client.CommonCountEventRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ KeyValues: []string{id},
|
|
|
|
+ Version: "v1",
|
|
|
|
+ Operation: "delete",
|
|
|
|
+ CreatorID: "test",
|
|
|
|
+ StartCreatedTime: now.Format(time.DateTime),
|
|
|
|
+ EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
|
|
|
|
+ }, &totalCount).
|
|
|
|
+ assertEqual(1, int(totalCount), "总数不一致").
|
|
|
|
+ eventHistoryQueryByKeys(&client.EventQueryByKeysRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ KeyValues: []string{id},
|
|
|
|
+ PageNo: 0,
|
|
|
|
+ PageSize: 0,
|
|
|
|
+ }, &eventInfos, &totalCount).
|
|
|
|
+ assertEqual(3, int(totalCount), "总数不一致").
|
|
|
|
+ assertEqual(3, len(eventInfos), "事件数量不一致").
|
|
|
|
+ assertEqual(id, eventInfos[0].Key, "关键字段不一致").
|
|
|
|
+ assertEqual("v1", eventInfos[0].Version, "版本不一致").
|
|
|
|
+ assertEqual("create", eventInfos[0].Operation, "操作不一致").
|
|
|
|
+ assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
|
|
|
|
+ assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
|
|
|
|
+ assertNotEmpty(eventInfos[0].Value, "值为空不一致").
|
|
|
|
+ assertEqual(id, eventInfos[1].Key, "关键字段不一致").
|
|
|
|
+ assertEqual("v1", eventInfos[1].Version, "版本不一致").
|
|
|
|
+ assertEqual("update", eventInfos[1].Operation, "操作不一致").
|
|
|
|
+ assertEqual("test", eventInfos[1].CreatorID, "创建者ID不一致").
|
|
|
|
+ assertNotEmpty(eventInfos[1].CreateTime, "创建事件为空").
|
|
|
|
+ assertNotEmpty(eventInfos[1].Value, "值为空不一致").
|
|
|
|
+ assertEqual(id, eventInfos[2].Key, "关键字段不一致").
|
|
|
|
+ assertEqual("v1", eventInfos[2].Version, "版本不一致").
|
|
|
|
+ assertEqual("delete", eventInfos[2].Operation, "操作不一致").
|
|
|
|
+ assertEqual("test", eventInfos[2].CreatorID, "创建者ID不一致").
|
|
|
|
+ assertNotEmpty(eventInfos[2].CreateTime, "创建事件为空").
|
|
|
|
+ assertEqual("", eventInfos[2].Value, "值为空不一致").
|
|
|
|
+ eventHistoryQueryByKeys(&client.EventQueryByKeysRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ KeyValues: []string{id},
|
|
|
|
+ PageNo: 1,
|
|
|
|
+ PageSize: 1,
|
|
|
|
+ }, &eventInfos, &totalCount).
|
|
|
|
+ assertEqual(3, int(totalCount), "总数不一致").
|
|
|
|
+ assertEqual(1, len(eventInfos), "事件数量不一致").
|
|
|
|
+ assertEqual(id, eventInfos[0].Key, "关键字段不一致").
|
|
|
|
+ assertEqual("v1", eventInfos[0].Version, "版本不一致").
|
|
|
|
+ assertEqual("create", eventInfos[0].Operation, "操作不一致").
|
|
|
|
+ assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
|
|
|
|
+ assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
|
|
|
|
+ assertNotEmpty(eventInfos[0].Value, "值为空不一致").
|
|
|
|
+ commonEventHistoryQuery(&client.CommonEventQueryRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ KeyValues: []string{id},
|
|
|
|
+ Version: "v1",
|
|
|
|
+ Operation: "create",
|
|
|
|
+ CreatorID: "test",
|
|
|
|
+ StartCreatedTime: now.Format(time.DateTime),
|
|
|
|
+ EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
|
|
|
|
+ PageNo: 0,
|
|
|
|
+ PageSize: 0,
|
|
|
|
+ }, &eventInfos, &totalCount).
|
|
|
|
+ assertEqual(1, int(totalCount), "总数不一致").
|
|
|
|
+ assertEqual(1, len(eventInfos), "事件数量不一致").
|
|
|
|
+ assertEqual(id, eventInfos[0].Key, "关键字段不一致").
|
|
|
|
+ assertEqual("v1", eventInfos[0].Version, "版本不一致").
|
|
|
|
+ assertEqual("create", eventInfos[0].Operation, "操作不一致").
|
|
|
|
+ assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
|
|
|
|
+ assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
|
|
|
|
+ assertNotEmpty(eventInfos[0].Value, "值为空不一致").
|
|
|
|
+ commonEventHistoryQuery(&client.CommonEventQueryRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ KeyValues: []string{id},
|
|
|
|
+ Version: "v1",
|
|
|
|
+ Operation: "update",
|
|
|
|
+ CreatorID: "test",
|
|
|
|
+ StartCreatedTime: now.Format(time.DateTime),
|
|
|
|
+ EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
|
|
|
|
+ PageNo: 0,
|
|
|
|
+ PageSize: 0,
|
|
|
|
+ }, &eventInfos, &totalCount).
|
|
|
|
+ assertEqual(1, int(totalCount), "总数不一致").
|
|
|
|
+ assertEqual(1, len(eventInfos), "事件数量不一致").
|
|
|
|
+ assertEqual(id, eventInfos[0].Key, "关键字段不一致").
|
|
|
|
+ assertEqual("v1", eventInfos[0].Version, "版本不一致").
|
|
|
|
+ assertEqual("update", eventInfos[0].Operation, "操作不一致").
|
|
|
|
+ assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
|
|
|
|
+ assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
|
|
|
|
+ assertNotEmpty(eventInfos[0].Value, "值为空不一致").
|
|
|
|
+ commonEventHistoryQuery(&client.CommonEventQueryRequest{
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
+ KeyValues: []string{id},
|
|
|
|
+ Version: "v1",
|
|
|
|
+ Operation: "delete",
|
|
|
|
+ CreatorID: "test",
|
|
|
|
+ StartCreatedTime: now.Format(time.DateTime),
|
|
|
|
+ EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
|
|
|
|
+ PageNo: 0,
|
|
|
|
+ PageSize: 0,
|
|
|
|
+ }, &eventInfos, &totalCount).
|
|
|
|
+ assertEqual(1, int(totalCount), "总数不一致").
|
|
|
|
+ assertEqual(1, len(eventInfos), "事件数量不一致").
|
|
|
|
+ assertEqual(id, eventInfos[0].Key, "关键字段不一致").
|
|
|
|
+ assertEqual("v1", eventInfos[0].Version, "版本不一致").
|
|
|
|
+ assertEqual("delete", eventInfos[0].Operation, "操作不一致").
|
|
|
|
+ assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
|
|
|
|
+ assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
|
|
|
|
+ assertEqual("", eventInfos[0].Value, "值为空不一致")
|
|
|
|
+}
|