1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261 |
- 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(), "-", "")
- }
- const (
- noEvent = false
- )
- 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", "ee2d7dabe56646ce835d80873348ee0e")
- defer destroyClient(t, "ee2d7dabe56646ce835d80873348ee0e")
- newToolKit(t).
- autoMigrate([]client.AutoMigrateItem{
- {
- TablePrefixWithSchema: "test." + simpleUUID()[0:8],
- Version: "v1",
- TableModelDescribe: tableModelDescribe,
- NoEvent: noEvent,
- },
- })
- }
- func TestTransaction(t *testing.T) {
- initClient(t, "localhost:30170", "ee2d7dabe56646ce835d80873348ee0e")
- defer destroyClient(t, "ee2d7dabe56646ce835d80873348ee0e")
- tablePrefix := "test." + simpleUUID()[0:8]
- id := simpleUUID()
- name := simpleUUID()
- now := time.Now().Local()
- tableNum := rand.New(rand.NewSource(now.UnixMicro())).Intn(10)
- newName := simpleUUID()
- newNow := time.Now().Local()
- newTableNum := rand.New(rand.NewSource(now.UnixMicro())).Intn(10)
- var count int64
- resultTableRow := client.NewTableRow()
- newToolKit(t).
- autoMigrate([]client.AutoMigrateItem{
- {
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- TableModelDescribe: tableModelDescribe,
- NoEvent: noEvent,
- },
- }).
- transaction(func(tx client.Transaction) error {
- statement, err := tx.InsertTx(&client.InsertRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- KeyColumns: []string{"id"},
- TableRow: client.NewTableRow().
- AddColumnValueString("id", id).
- AddColumnValueString("name", name).
- AddColumnValueTime("time", now).
- AddColumnValueInt("table_num", tableNum),
- UserID: "test",
- })
- if err != nil {
- return err
- }
- fmt.Println(statement)
- return nil
- }).
- queryByKeys(&client.QueryByKeysRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- KeyValues: client.NewKeyValue().Add("id", id),
- }, resultTableRow).
- assertEqual(id, resultTableRow.ColumnValueString("id"), "ID不一致").
- assertEqual(name, resultTableRow.ColumnValueString("name"), "名称不一致").
- assertEqual(now.UnixMicro(), resultTableRow.ColumnValueTime("time").UnixMicro(), "时间不一致").
- assertEqual(tableNum, resultTableRow.ColumnValueInt("table_num"), "表数量不一致").
- transaction(func(tx client.Transaction) error {
- statement, err := tx.UpdateTx(&client.UpdateRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- KeyValues: client.NewKeyValue().Add("id", id),
- NewTableRow: client.NewTableRow().
- AddColumnValueString("id", id).
- AddColumnValueString("name", newName).
- AddColumnValueTime("time", newNow).
- AddColumnValueInt("table_num", newTableNum),
- UserID: "test",
- })
- if err != nil {
- return err
- }
- fmt.Println(statement)
- return nil
- }).
- queryByKeys(&client.QueryByKeysRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- KeyValues: client.NewKeyValue().Add("id", id),
- }, resultTableRow).
- assertEqual(id, resultTableRow.ColumnValueString("id"), "ID不一致").
- assertEqual(newName, resultTableRow.ColumnValueString("name"), "名称不一致").
- assertEqual(newNow.UnixMicro(), resultTableRow.ColumnValueTime("time").UnixMicro(), "时间不一致").
- assertEqual(newTableNum, resultTableRow.ColumnValueInt("table_num"), "表数量不一致").
- transaction(func(tx client.Transaction) error {
- statement, err := tx.UpdateTx(&client.UpdateRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- KeyValues: client.NewKeyValue().Add("id", id),
- NewTableRow: client.NewTableRow().
- AddColumnValueString("id", id).
- AddColumnValueString("name", name).
- AddColumnValueTime("time", now).
- AddColumnValueInt("table_num", tableNum),
- UserID: "test",
- })
- if err != nil {
- return err
- }
- fmt.Println(statement)
- statement, err = tx.DeleteTx(&client.DeleteRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- KeyValues: client.NewKeyValue().Add("id", id),
- UserID: "test",
- })
- if err != nil {
- return err
- }
- fmt.Println(statement)
- return nil
- }).
- countWhere(&client.CountWhereRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- Where: client.NewClause().Equal("id", id),
- }, &count).
- assertEqual(int64(0), count, "数量不一致").
- insert(&client.InsertRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- KeyColumns: []string{"id"},
- TableRow: client.NewTableRow().
- AddColumnValueString("id", id).
- AddColumnValueString("name", name).
- AddColumnValueTime("time", now).
- AddColumnValueInt("table_num", tableNum),
- UserID: "test",
- }).
- transaction(func(tx client.Transaction) error {
- statement, err := tx.DeleteWhereTx(&client.DeleteWhereRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- KeyColumns: []string{"id"},
- Where: client.NewClause().Equal("name", name),
- UserID: "test",
- })
- if err != nil {
- return err
- }
- fmt.Println(statement)
- return nil
- }).
- countWhere(&client.CountWhereRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- Where: client.NewClause().Equal("id", id),
- }, &count).
- assertEqual(int64(0), count, "数量不一致")
- }
- func TestTransactionBatch(t *testing.T) {
- initClient(t, "localhost:30170", "ee2d7dabe56646ce835d80873348ee0e")
- defer destroyClient(t, "ee2d7dabe56646ce835d80873348ee0e")
- tablePrefix := "test." + simpleUUID()[0:8]
- id1 := simpleUUID()
- name1 := simpleUUID()
- now1 := time.Now().Local()
- tableNum1 := rand.New(rand.NewSource(now1.UnixMicro())).Intn(10)
- id2 := simpleUUID()
- name2 := simpleUUID()
- now2 := time.Now().Local()
- tableNum2 := rand.New(rand.NewSource(now2.UnixMicro())).Intn(10)
- newName := simpleUUID()
- newNow := time.Now().Local()
- newTableNum := rand.New(rand.NewSource(newNow.UnixMicro())).Intn(10)
- var count int64
- resultTableRow := client.NewTableRow()
- newToolKit(t).
- autoMigrate([]client.AutoMigrateItem{
- {
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- TableModelDescribe: tableModelDescribe,
- NoEvent: noEvent,
- },
- }).
- transaction(func(tx client.Transaction) error {
- statement, err := tx.InsertBatchTx(&client.InsertBatchRequest{
- Items: []client.InsertTableRowItem{
- {
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- KeyColumns: []string{"id"},
- TableRows: []*client.TableRow{
- client.NewTableRow().
- AddColumnValueString("id", id1).
- AddColumnValueString("name", name1).
- AddColumnValueTime("time", now1).
- AddColumnValueInt("table_num", tableNum1),
- client.NewTableRow().
- AddColumnValueString("id", id2).
- AddColumnValueString("name", name2).
- AddColumnValueTime("time", now2).
- AddColumnValueInt("table_num", tableNum2),
- },
- },
- },
- })
- if err != nil {
- return err
- }
- fmt.Println(statement)
- return nil
- }).
- queryByKeys(&client.QueryByKeysRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- KeyValues: client.NewKeyValue().Add("id", id1),
- }, resultTableRow).
- assertEqual(id1, resultTableRow.ColumnValueString("id"), "ID不一致").
- assertEqual(name1, resultTableRow.ColumnValueString("name"), "名称不一致").
- assertEqual(now1.UnixMicro(), resultTableRow.ColumnValueTime("time").UnixMicro(), "时间不一致").
- assertEqual(tableNum1, resultTableRow.ColumnValueInt("table_num"), "表数量不一致").
- queryByKeys(&client.QueryByKeysRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- KeyValues: client.NewKeyValue().Add("id", id2),
- }, resultTableRow).
- assertEqual(id2, resultTableRow.ColumnValueString("id"), "ID不一致").
- assertEqual(name2, resultTableRow.ColumnValueString("name"), "名称不一致").
- assertEqual(now2.UnixMicro(), resultTableRow.ColumnValueTime("time").UnixMicro(), "时间不一致").
- assertEqual(tableNum2, resultTableRow.ColumnValueInt("table_num"), "表数量不一致").
- transaction(func(tx client.Transaction) error {
- statement, err := tx.UpdateWhereTx(&client.UpdateWhereRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- KeyColumns: []string{"id"},
- Where: client.NewClause().In("id", []string{id1, id2}),
- NewTableRow: client.NewTableRow().
- AddColumnValueString("name", newName).
- AddColumnValueTime("time", newNow).
- AddColumnValueInt("table_num", newTableNum),
- UserID: "test",
- })
- if err != nil {
- return err
- }
- fmt.Println(statement)
- return nil
- }).
- queryByKeys(&client.QueryByKeysRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- KeyValues: client.NewKeyValue().Add("id", id1),
- }, resultTableRow).
- assertEqual(id1, resultTableRow.ColumnValueString("id"), "ID不一致").
- assertEqual(newName, resultTableRow.ColumnValueString("name"), "名称不一致").
- assertEqual(newNow.UnixMicro(), resultTableRow.ColumnValueTime("time").UnixMicro(), "时间不一致").
- assertEqual(newTableNum, resultTableRow.ColumnValueInt("table_num"), "表数量不一致").
- queryByKeys(&client.QueryByKeysRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- KeyValues: client.NewKeyValue().Add("id", id2),
- }, resultTableRow).
- assertEqual(id2, resultTableRow.ColumnValueString("id"), "ID不一致").
- assertEqual(newName, resultTableRow.ColumnValueString("name"), "名称不一致").
- assertEqual(newNow.UnixMicro(), resultTableRow.ColumnValueTime("time").UnixMicro(), "时间不一致").
- assertEqual(newTableNum, resultTableRow.ColumnValueInt("table_num"), "表数量不一致").
- transaction(func(tx client.Transaction) error {
- statement, err := tx.DeleteWhereTx(&client.DeleteWhereRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- KeyColumns: []string{"id"},
- Where: client.NewClause().In("id", []string{id1, id2}),
- UserID: "test",
- })
- if err != nil {
- return err
- }
- fmt.Println(statement)
- return nil
- }).
- countWhere(&client.CountWhereRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- Where: client.NewClause().Equal("id", id1),
- }, &count).
- assertEqual(int64(0), count, "数量不一致").
- countWhere(&client.CountWhereRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- Where: client.NewClause().Equal("id", id2),
- }, &count).
- assertEqual(int64(0), count, "数量不一致")
- }
- func TestInsert(t *testing.T) {
- initClient(t, "localhost:30170", "ee2d7dabe56646ce835d80873348ee0e")
- defer destroyClient(t, "ee2d7dabe56646ce835d80873348ee0e")
- tablePrefix := "test." + simpleUUID()[0:8]
- id := simpleUUID()
- name := simpleUUID()
- now := time.Now().Local()
- tableNum := rand.New(rand.NewSource(now.UnixMicro())).Intn(10)
- resultTableRow := client.NewTableRow()
- var exist bool
- newToolKit(t).
- autoMigrate([]client.AutoMigrateItem{
- {
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- TableModelDescribe: tableModelDescribe,
- NoEvent: noEvent,
- },
- }).
- insert(&client.InsertRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- KeyColumns: []string{"id"},
- TableRow: client.NewTableRow().
- AddColumnValueString("id", id).
- AddColumnValueString("name", name).
- AddColumnValueTime("time", now).
- AddColumnValueInt("table_num", tableNum),
- UserID: "test",
- }).
- queryByKeys(&client.QueryByKeysRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- KeyValues: client.NewKeyValue().Add("id", id),
- }, resultTableRow).
- assertEqual(id, resultTableRow.ColumnValueString("id"), "ID不一致").
- assertEqual(name, resultTableRow.ColumnValueString("name"), "名称不一致").
- assertEqual(now.UnixMicro(), resultTableRow.ColumnValueTime("time").UnixMicro(), "时间不一致").
- assertEqual(tableNum, resultTableRow.ColumnValueInt("table_num"), "表数量不一致").
- checkExistWhere(&client.CountWhereRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- Where: client.NewClause().Equal("id", id),
- }, &exist).
- assertEqual(true, exist, "存在状态不一致").
- commonCheckExist(&client.CommonCountRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- Where: client.NewClause().
- Equal("id", id).
- Equal("name", name).
- Equal("table_num", tableNum),
- }, &exist).
- assertEqual(true, exist, "存在状态不一致")
- }
- func TestInsertBatch(t *testing.T) {
- initClient(t, "localhost:30170", "ee2d7dabe56646ce835d80873348ee0e")
- defer destroyClient(t, "ee2d7dabe56646ce835d80873348ee0e")
- tablePrefix := "test." + simpleUUID()[0:8]
- id1 := simpleUUID()
- name1 := simpleUUID()
- now1 := time.Now().Local()
- tableNum1 := rand.New(rand.NewSource(now1.UnixMicro())).Intn(10)
- id2 := simpleUUID()
- name2 := simpleUUID()
- now2 := time.Now().Local()
- tableNum2 := rand.New(rand.NewSource(now2.UnixMicro())).Intn(10)
- resultTableRows := make([]client.TableRow, 0)
- var totalCount int64
- newToolKit(t).
- autoMigrate([]client.AutoMigrateItem{
- {
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- TableModelDescribe: tableModelDescribe,
- NoEvent: noEvent,
- },
- }).
- insertBatch(&client.InsertBatchRequest{
- Items: []client.InsertTableRowItem{
- {
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- KeyColumns: []string{"id"},
- TableRows: []*client.TableRow{
- client.NewTableRow().
- AddColumnValueString("id", id1).
- AddColumnValueString("name", name1).
- AddColumnValueTime("time", now1).
- AddColumnValueInt("table_num", tableNum1),
- client.NewTableRow().
- AddColumnValueString("id", id2).
- AddColumnValueString("name", name2).
- AddColumnValueTime("time", now2).
- AddColumnValueInt("table_num", tableNum2),
- },
- },
- },
- }).
- queryByWhereAndOrderBy(&client.QueryByWhereAndOrderByRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- Where: client.NewClause().
- Equal("id", id1).
- Equal("name", name1).
- Equal("table_num", tableNum1),
- PageNo: 1,
- PageSize: 1,
- }, &resultTableRows, &totalCount).
- assertEqual(1, int(totalCount), "总数不一致").
- assertEqual(id1, resultTableRows[0].ColumnValueString("id"), "ID不一致").
- assertEqual(name1, resultTableRows[0].ColumnValueString("name"), "名称不一致").
- assertEqual(now1.UnixMicro(), resultTableRows[0].ColumnValueTime("time").UnixMicro(), "时间不一致").
- assertEqual(tableNum1, resultTableRows[0].ColumnValueInt("table_num"), "表数量不一致").
- commonQuery(&client.CommonQueryRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- Where: client.NewClause().
- Equal("id", id2).
- Equal("name", name2).
- Equal("table_num", tableNum2),
- PageNo: 1,
- PageSize: 1,
- }, &resultTableRows, &totalCount).
- assertEqual(1, int(totalCount), "总数不一致").
- assertEqual(id2, resultTableRows[0].ColumnValueString("id"), "ID不一致").
- assertEqual(name2, resultTableRows[0].ColumnValueString("name"), "名称不一致").
- assertEqual(now2.UnixMicro(), resultTableRows[0].ColumnValueTime("time").UnixMicro(), "时间不一致").
- assertEqual(tableNum2, resultTableRows[0].ColumnValueInt("table_num"), "表数量不一致").
- queryOnlyByWhereAndOrderBy(&client.QueryByWhereAndOrderByRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- Where: client.NewClause().
- Equal("id", id1).
- Equal("name", name1).
- Equal("table_num", tableNum1),
- PageNo: 1,
- PageSize: 1,
- }, &resultTableRows).
- assertEqual(id1, resultTableRows[0].ColumnValueString("id"), "ID不一致").
- assertEqual(name1, resultTableRows[0].ColumnValueString("name"), "名称不一致").
- assertEqual(now1.UnixMicro(), resultTableRows[0].ColumnValueTime("time").UnixMicro(), "时间不一致").
- assertEqual(tableNum1, resultTableRows[0].ColumnValueInt("table_num"), "表数量不一致").
- commonQueryOnly(&client.CommonQueryRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- Where: client.NewClause().
- Equal("id", id2).
- Equal("name", name2).
- Equal("table_num", tableNum2),
- PageNo: 1,
- PageSize: 1,
- }, &resultTableRows).
- assertEqual(id2, resultTableRows[0].ColumnValueString("id"), "ID不一致").
- assertEqual(name2, resultTableRows[0].ColumnValueString("name"), "名称不一致").
- assertEqual(now2.UnixMicro(), resultTableRows[0].ColumnValueTime("time").UnixMicro(), "时间不一致").
- assertEqual(tableNum2, resultTableRows[0].ColumnValueInt("table_num"), "表数量不一致")
- }
- func TestUpdate(t *testing.T) {
- initClient(t, "localhost:30170", "ee2d7dabe56646ce835d80873348ee0e")
- defer destroyClient(t, "ee2d7dabe56646ce835d80873348ee0e")
- tablePrefix := "test." + simpleUUID()[0:8]
- id := simpleUUID()
- name := simpleUUID()
- now := time.Now().Local()
- tableNum := rand.New(rand.NewSource(now.UnixMicro())).Intn(10)
- newName := simpleUUID()
- newNow := time.Now().Local()
- newTableNum := rand.New(rand.NewSource(now.UnixMicro())).Intn(10)
- resultTableRow := client.NewTableRow()
- newToolKit(t).
- autoMigrate([]client.AutoMigrateItem{
- {
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- TableModelDescribe: tableModelDescribe,
- NoEvent: noEvent,
- },
- }).
- insert(&client.InsertRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- KeyColumns: []string{"id"},
- TableRow: client.NewTableRow().
- AddColumnValueString("id", id).
- AddColumnValueString("name", name).
- AddColumnValueTime("time", now).
- AddColumnValueInt("table_num", tableNum),
- UserID: "test",
- }).
- update(&client.UpdateRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- KeyValues: client.NewKeyValue().Add("id", id),
- NewTableRow: client.NewTableRow().
- AddColumnValueString("id", id).
- AddColumnValueString("name", newName).
- AddColumnValueTime("time", newNow).
- AddColumnValueInt("table_num", newTableNum),
- UserID: "test",
- }).
- queryByKeys(&client.QueryByKeysRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- KeyValues: client.NewKeyValue().Add("id", id),
- }, resultTableRow).
- assertEqual(id, resultTableRow.ColumnValueString("id"), "ID不一致").
- assertEqual(newName, resultTableRow.ColumnValueString("name"), "名称不一致").
- assertEqual(newNow.UnixMicro(), resultTableRow.ColumnValueTime("time").UnixMicro(), "时间不一致").
- assertEqual(newTableNum, resultTableRow.ColumnValueInt("table_num"), "表数量不一致")
- }
- func TestUpdateWhere(t *testing.T) {
- initClient(t, "localhost:30170", "ee2d7dabe56646ce835d80873348ee0e")
- defer destroyClient(t, "ee2d7dabe56646ce835d80873348ee0e")
- tablePrefix := "test." + simpleUUID()[0:8]
- id := simpleUUID()
- name := simpleUUID()
- now := time.Now().Local()
- tableNum := rand.New(rand.NewSource(now.UnixMicro())).Intn(10)
- newName := simpleUUID()
- newNow := time.Now().Local()
- newTableNum := rand.New(rand.NewSource(now.UnixMicro())).Intn(10)
- resultTableRow := client.NewTableRow()
- newToolKit(t).
- autoMigrate([]client.AutoMigrateItem{
- {
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- TableModelDescribe: tableModelDescribe,
- NoEvent: noEvent,
- },
- }).
- insert(&client.InsertRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- KeyColumns: []string{"id"},
- TableRow: client.NewTableRow().
- AddColumnValueString("id", id).
- AddColumnValueString("name", name).
- AddColumnValueTime("time", now).
- AddColumnValueInt("table_num", tableNum),
- UserID: "test",
- }).
- updateWhere(&client.UpdateWhereRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- KeyColumns: []string{"id"},
- Where: client.NewClause().Equal("name", name),
- NewTableRow: client.NewTableRow().
- AddColumnValueString("id", id).
- AddColumnValueString("name", newName).
- AddColumnValueTime("time", newNow).
- AddColumnValueInt("table_num", newTableNum),
- UserID: "test",
- }).
- queryByKeys(&client.QueryByKeysRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- KeyValues: client.NewKeyValue().Add("id", id),
- }, resultTableRow).
- assertEqual(id, resultTableRow.ColumnValueString("id"), "ID不一致").
- assertEqual(newName, resultTableRow.ColumnValueString("name"), "名称不一致").
- assertEqual(newNow.UnixMicro(), resultTableRow.ColumnValueTime("time").UnixMicro(), "时间不一致").
- assertEqual(newTableNum, resultTableRow.ColumnValueInt("table_num"), "表数量不一致")
- }
- func TestDelete(t *testing.T) {
- initClient(t, "localhost:30170", "ee2d7dabe56646ce835d80873348ee0e")
- defer destroyClient(t, "ee2d7dabe56646ce835d80873348ee0e")
- tablePrefix := "test." + simpleUUID()[0:8]
- id := simpleUUID()
- name := simpleUUID()
- now := time.Now().Local()
- tableNum := rand.New(rand.NewSource(now.UnixMicro())).Intn(10)
- var count int64
- newToolKit(t).
- autoMigrate([]client.AutoMigrateItem{
- {
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- TableModelDescribe: tableModelDescribe,
- NoEvent: noEvent,
- },
- }).
- insert(&client.InsertRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- KeyColumns: []string{"id"},
- TableRow: client.NewTableRow().
- AddColumnValueString("id", id).
- AddColumnValueString("name", name).
- AddColumnValueTime("time", now).
- AddColumnValueInt("table_num", tableNum),
- UserID: "test",
- }).
- delete(&client.DeleteRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- KeyValues: client.NewKeyValue().Add("id", id),
- UserID: "test",
- }).
- countWhere(&client.CountWhereRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- Where: client.NewClause().Equal("id", id),
- }, &count).
- assertEqual(int64(0), count, "数量不一致")
- }
- func TestDeleteWhere(t *testing.T) {
- initClient(t, "localhost:30170", "ee2d7dabe56646ce835d80873348ee0e")
- defer destroyClient(t, "ee2d7dabe56646ce835d80873348ee0e")
- tablePrefix := "test." + simpleUUID()[0:8]
- id := simpleUUID()
- name := simpleUUID()
- now := time.Now().Local()
- tableNum := rand.New(rand.NewSource(now.UnixMicro())).Intn(10)
- var count int64
- newToolKit(t).
- autoMigrate([]client.AutoMigrateItem{
- {
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- TableModelDescribe: tableModelDescribe,
- NoEvent: noEvent,
- },
- }).
- insert(&client.InsertRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- KeyColumns: []string{"id"},
- TableRow: client.NewTableRow().
- AddColumnValueString("id", id).
- AddColumnValueString("name", name).
- AddColumnValueTime("time", now).
- AddColumnValueInt("table_num", tableNum),
- UserID: "test",
- }).
- deleteWhere(&client.DeleteWhereRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- KeyColumns: []string{"id"},
- Where: client.NewClause().Equal("name", name),
- UserID: "test",
- }).
- countWhere(&client.CountWhereRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- Where: client.NewClause().Equal("id", id),
- }, &count).
- assertEqual(int64(0), count, "数量不一致")
- }
- func TestReply(t *testing.T) {
- initClient(t, "localhost:30170", "ee2d7dabe56646ce835d80873348ee0e")
- defer destroyClient(t, "ee2d7dabe56646ce835d80873348ee0e")
- tablePrefix := "test." + simpleUUID()[0:8]
- id := simpleUUID()
- name := simpleUUID()
- now := time.Now().Local()
- tableNum := rand.New(rand.NewSource(now.UnixMicro())).Intn(10)
- resultTableRow := client.NewTableRow()
- newToolKit(t).
- autoMigrate([]client.AutoMigrateItem{
- {
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- TableModelDescribe: tableModelDescribe,
- NoEvent: noEvent,
- },
- }).
- insert(&client.InsertRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- KeyColumns: []string{"id"},
- TableRow: client.NewTableRow().
- AddColumnValueString("id", id).
- AddColumnValueString("name", name).
- AddColumnValueTime("time", now).
- AddColumnValueInt("table_num", tableNum),
- UserID: "test",
- }).
- reply(&client.ReplayRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- KeyValues: client.NewKeyValue().Add("id", id),
- UserID: "test",
- }).
- queryByKeys(&client.QueryByKeysRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- KeyValues: client.NewKeyValue().Add("id", id),
- }, resultTableRow).
- assertEqual(id, resultTableRow.ColumnValueString("id"), "ID不一致").
- assertEqual(name, resultTableRow.ColumnValueString("name"), "名称不一致").
- assertEqual(now.UnixMicro(), resultTableRow.ColumnValueTime("time").UnixMicro(), "时间不一致").
- assertEqual(tableNum, resultTableRow.ColumnValueInt("table_num"), "表数量不一致")
- }
- func TestEventQuery(t *testing.T) {
- if noEvent {
- return
- }
- initClient(t, "localhost:30170", "ee2d7dabe56646ce835d80873348ee0e")
- defer destroyClient(t, "ee2d7dabe56646ce835d80873348ee0e")
- tablePrefix := "test." + simpleUUID()[0:8]
- id := simpleUUID()
- name := simpleUUID()
- now := time.Now().Local()
- tableNum := rand.New(rand.NewSource(now.UnixMicro())).Intn(10)
- newName := simpleUUID()
- newNow := time.Now().Local()
- newTableNum := rand.New(rand.NewSource(now.UnixMicro())).Intn(10)
- var exist bool
- var totalCount int64
- eventInfos := make([]client.EventInfo, 0)
- newToolKit(t).
- autoMigrate([]client.AutoMigrateItem{
- {
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- TableModelDescribe: tableModelDescribe,
- NoEvent: noEvent,
- },
- }).
- insert(&client.InsertRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- KeyColumns: []string{"id"},
- TableRow: client.NewTableRow().
- AddColumnValueString("id", id).
- AddColumnValueString("name", name).
- AddColumnValueTime("time", now).
- AddColumnValueInt("table_num", tableNum),
- UserID: "test",
- }).
- checkEventExistByKeys(&client.CountEventByKeysRequest{
- TablePrefixWithSchema: tablePrefix,
- KeyValues: []string{id},
- }, &exist).
- assertEqual(true, exist, "存在状态不一致").
- commonCheckEventExist(&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),
- }, &exist).
- assertEqual(true, exist, "存在状态不一致").
- update(&client.UpdateRequest{
- TablePrefixWithSchema: tablePrefix,
- Version: "v1",
- KeyValues: client.NewKeyValue().Add("id", id),
- NewTableRow: client.NewTableRow().
- AddColumnValueString("id", id).
- AddColumnValueString("name", newName).
- AddColumnValueTime("time", newNow).
- AddColumnValueInt("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, "值为空不一致").
- eventQueryOnlyByKeys(&client.EventQueryByKeysRequest{
- TablePrefixWithSchema: tablePrefix,
- KeyValues: []string{id},
- PageNo: 0,
- PageSize: 0,
- }, &eventInfos).
- 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, "值为空不一致").
- eventQueryOnlyByKeys(&client.EventQueryByKeysRequest{
- TablePrefixWithSchema: tablePrefix,
- KeyValues: []string{id},
- PageNo: 1,
- PageSize: 1,
- }, &eventInfos).
- 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, "值为空不一致").
- commonEventQueryOnly(&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).
- 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, "值为空不一致").
- commonEventQueryOnly(&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).
- 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: client.NewKeyValue().Add("id", id),
- UserID: "test",
- }).
- checkEventHistoryExistByKeys(&client.CountEventByKeysRequest{
- TablePrefixWithSchema: tablePrefix,
- KeyValues: []string{id},
- }, &exist).
- assertEqual(true, exist, "存在状态不一致").
- commonCheckEventHistoryExist(&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),
- }, &exist).
- assertEqual(true, exist, "存在状态不一致").
- 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, "值为空不一致").
- eventHistoryQueryOnlyByKeys(&client.EventQueryByKeysRequest{
- TablePrefixWithSchema: tablePrefix,
- KeyValues: []string{id},
- PageNo: 0,
- PageSize: 0,
- }, &eventInfos).
- 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, "值为空不一致").
- eventHistoryQueryOnlyByKeys(&client.EventQueryByKeysRequest{
- TablePrefixWithSchema: tablePrefix,
- KeyValues: []string{id},
- PageNo: 1,
- PageSize: 1,
- }, &eventInfos).
- 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, "值为空不一致").
- commonEventHistoryQueryOnly(&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).
- 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, "值为空不一致").
- commonEventHistoryQueryOnly(&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).
- 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, "值为空不一致").
- commonEventHistoryQueryOnly(&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).
- 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, "值为空不一致")
- }
|