v1_test.go 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128
  1. package v1
  2. import (
  3. "fmt"
  4. "git.sxidc.com/service-supports/dps-sdk/client"
  5. uuid "github.com/satori/go.uuid"
  6. "math/rand"
  7. "strings"
  8. "testing"
  9. "time"
  10. )
  11. func getUUID() string {
  12. return uuid.NewV4().String()
  13. }
  14. func simpleUUID() string {
  15. return strings.ReplaceAll(getUUID(), "-", "")
  16. }
  17. var tableModelDescribe = map[string]string{
  18. "ID": "gorm:\"primary_key;type:varchar(32);comment:id;\"",
  19. "Name": "gorm:\"not null;type:varchar(128);comment:数据库名称;\"",
  20. "Time": "gorm:\"not null;type:timestamp with time zone;comment:数据库时间;\"",
  21. "TableNum": "gorm:\"not null;type:integer;comment:数据库表数量;\"",
  22. }
  23. func TestAutoMigrate(t *testing.T) {
  24. initClient(t, "localhost:30170", "2b78141779ee432295ca371b91c5cac7")
  25. defer destroyClient(t, "2b78141779ee432295ca371b91c5cac7")
  26. newToolKit(t).
  27. autoMigrate(&client.AutoMigrateRequest{
  28. Items: []client.AutoMigrateItem{
  29. {
  30. TablePrefixWithSchema: "test." + simpleUUID()[0:8],
  31. Version: "v1",
  32. TableModelDescribe: tableModelDescribe,
  33. },
  34. },
  35. })
  36. }
  37. func TestTransaction(t *testing.T) {
  38. initClient(t, "localhost:30170", "2b78141779ee432295ca371b91c5cac7")
  39. defer destroyClient(t, "2b78141779ee432295ca371b91c5cac7")
  40. tablePrefix := "test." + simpleUUID()[0:8]
  41. id := simpleUUID()
  42. name := simpleUUID()
  43. now := time.Now().Local()
  44. tableNum := rand.New(rand.NewSource(now.Unix())).Intn(10)
  45. newName := simpleUUID()
  46. newNow := time.Now().Local()
  47. newTableNum := rand.New(rand.NewSource(now.Unix())).Intn(10)
  48. var count int64
  49. resultMap := make(map[string]any)
  50. newToolKit(t).
  51. autoMigrate(&client.AutoMigrateRequest{
  52. Items: []client.AutoMigrateItem{
  53. {
  54. TablePrefixWithSchema: tablePrefix,
  55. Version: "v1",
  56. TableModelDescribe: tableModelDescribe,
  57. },
  58. },
  59. }).
  60. transaction(func(tx client.Transaction) error {
  61. statement, err := tx.InsertTx(&client.InsertRequest{
  62. TablePrefixWithSchema: tablePrefix,
  63. Version: "v1",
  64. KeyColumns: []string{"id"},
  65. TableRow: map[string]any{
  66. "id": id,
  67. "name": name,
  68. "time": now,
  69. "table_num": tableNum,
  70. },
  71. UserID: "test",
  72. })
  73. if err != nil {
  74. return err
  75. }
  76. fmt.Println(statement)
  77. return nil
  78. }).
  79. queryByKeys(&client.QueryByKeysRequest{
  80. TablePrefixWithSchema: tablePrefix,
  81. Version: "v1",
  82. KeyValues: map[string]string{"id": id},
  83. }, &resultMap).
  84. assertEqual(id, resultMap["id"], "ID不一致").
  85. assertEqual(name, resultMap["name"], "名称不一致").
  86. assertEqual(now.UnixMilli(), resultMap["time"].(time.Time).UnixMilli(), "时间不一致").
  87. assertEqual(tableNum, resultMap["table_num"], "表数量不一致").
  88. transaction(func(tx client.Transaction) error {
  89. statement, err := tx.UpdateTx(&client.UpdateRequest{
  90. TablePrefixWithSchema: tablePrefix,
  91. Version: "v1",
  92. KeyValues: map[string]string{"id": id},
  93. NewTableRow: map[string]any{
  94. "id": id,
  95. "name": newName,
  96. "time": newNow,
  97. "table_num": newTableNum,
  98. },
  99. UserID: "test",
  100. })
  101. if err != nil {
  102. return err
  103. }
  104. fmt.Println(statement)
  105. return nil
  106. }).
  107. queryByKeys(&client.QueryByKeysRequest{
  108. TablePrefixWithSchema: tablePrefix,
  109. Version: "v1",
  110. KeyValues: map[string]string{"id": id},
  111. }, &resultMap).
  112. assertEqual(id, resultMap["id"], "ID不一致").
  113. assertEqual(newName, resultMap["name"], "名称不一致").
  114. assertEqual(newNow.UnixMilli(), resultMap["time"].(time.Time).UnixMilli(), "时间不一致").
  115. assertEqual(newTableNum, resultMap["table_num"], "表数量不一致").
  116. transaction(func(tx client.Transaction) error {
  117. statement, err := tx.UpdateTx(&client.UpdateRequest{
  118. TablePrefixWithSchema: tablePrefix,
  119. Version: "v1",
  120. KeyValues: map[string]string{"id": id},
  121. NewTableRow: map[string]any{
  122. "id": id,
  123. "name": name,
  124. "time": now,
  125. "table_num": tableNum,
  126. },
  127. UserID: "test",
  128. })
  129. if err != nil {
  130. return err
  131. }
  132. fmt.Println(statement)
  133. statement, err = tx.DeleteTx(&client.DeleteRequest{
  134. TablePrefixWithSchema: tablePrefix,
  135. Version: "v1",
  136. KeyValues: map[string]string{"id": id},
  137. UserID: "test",
  138. })
  139. if err != nil {
  140. return err
  141. }
  142. fmt.Println(statement)
  143. return nil
  144. }).
  145. countWhere(&client.CountWhereRequest{
  146. TablePrefixWithSchema: tablePrefix,
  147. Version: "v1",
  148. Where: map[string][]any{
  149. "id = ?": {id},
  150. },
  151. }, &count).
  152. assertEqual(int64(0), count, "数量不一致")
  153. }
  154. func TestTransactionBatch(t *testing.T) {
  155. initClient(t, "localhost:30170", "2b78141779ee432295ca371b91c5cac7")
  156. defer destroyClient(t, "2b78141779ee432295ca371b91c5cac7")
  157. tablePrefix := "test." + simpleUUID()[0:8]
  158. id1 := simpleUUID()
  159. name1 := simpleUUID()
  160. now1 := time.Now().Local()
  161. tableNum1 := rand.New(rand.NewSource(now1.Unix())).Intn(10)
  162. id2 := simpleUUID()
  163. name2 := simpleUUID()
  164. now2 := time.Now().Local()
  165. tableNum2 := rand.New(rand.NewSource(now2.Unix())).Intn(10)
  166. var count int64
  167. resultMap := make(map[string]any)
  168. newToolKit(t).
  169. autoMigrate(&client.AutoMigrateRequest{
  170. Items: []client.AutoMigrateItem{
  171. {
  172. TablePrefixWithSchema: tablePrefix,
  173. Version: "v1",
  174. TableModelDescribe: tableModelDescribe,
  175. },
  176. },
  177. }).
  178. transaction(func(tx client.Transaction) error {
  179. statement, err := tx.InsertBatchTx(&client.InsertBatchRequest{
  180. Items: []client.InsertTableRowItem{
  181. {
  182. TablePrefixWithSchema: tablePrefix,
  183. Version: "v1",
  184. KeyColumns: []string{"id"},
  185. TableRows: []map[string]any{
  186. {
  187. "id": id1,
  188. "name": name1,
  189. "time": now1,
  190. "table_num": tableNum1,
  191. },
  192. {
  193. "id": id2,
  194. "name": name2,
  195. "time": now2,
  196. "table_num": tableNum2,
  197. },
  198. },
  199. },
  200. },
  201. })
  202. if err != nil {
  203. return err
  204. }
  205. fmt.Println(statement)
  206. return nil
  207. }).
  208. queryByKeys(&client.QueryByKeysRequest{
  209. TablePrefixWithSchema: tablePrefix,
  210. Version: "v1",
  211. KeyValues: map[string]string{"id": id1},
  212. }, &resultMap).
  213. assertEqual(id1, resultMap["id"], "ID不一致").
  214. assertEqual(name1, resultMap["name"], "名称不一致").
  215. assertEqual(now1.UnixMilli(), resultMap["time"].(time.Time).UnixMilli(), "时间不一致").
  216. assertEqual(tableNum1, resultMap["table_num"], "表数量不一致").
  217. queryByKeys(&client.QueryByKeysRequest{
  218. TablePrefixWithSchema: tablePrefix,
  219. Version: "v1",
  220. KeyValues: map[string]string{"id": id2},
  221. }, &resultMap).
  222. assertEqual(id2, resultMap["id"], "ID不一致").
  223. assertEqual(name2, resultMap["name"], "名称不一致").
  224. assertEqual(now2.UnixMilli(), resultMap["time"].(time.Time).UnixMilli(), "时间不一致").
  225. assertEqual(tableNum2, resultMap["table_num"], "表数量不一致").
  226. transaction(func(tx client.Transaction) error {
  227. statement, err := tx.DeleteBatchTx(&client.DeleteBatchRequest{
  228. Items: []client.DeleteTableRowItem{
  229. {
  230. TablePrefixWithSchema: tablePrefix,
  231. Version: "v1",
  232. KeyValues: []map[string]string{
  233. {"id": id1},
  234. {"id": id2},
  235. },
  236. },
  237. },
  238. UserID: "test",
  239. })
  240. if err != nil {
  241. return err
  242. }
  243. fmt.Println(statement)
  244. return nil
  245. }).
  246. countWhere(&client.CountWhereRequest{
  247. TablePrefixWithSchema: tablePrefix,
  248. Version: "v1",
  249. Where: map[string][]any{
  250. "id = ?": {id1},
  251. },
  252. }, &count).
  253. assertEqual(int64(0), count, "数量不一致").
  254. countWhere(&client.CountWhereRequest{
  255. TablePrefixWithSchema: tablePrefix,
  256. Version: "v1",
  257. Where: map[string][]any{
  258. "id = ?": {id2},
  259. },
  260. }, &count).
  261. assertEqual(int64(0), count, "数量不一致")
  262. }
  263. func TestInsert(t *testing.T) {
  264. initClient(t, "localhost:30170", "2b78141779ee432295ca371b91c5cac7")
  265. defer destroyClient(t, "2b78141779ee432295ca371b91c5cac7")
  266. tablePrefix := "test." + simpleUUID()[0:8]
  267. id := simpleUUID()
  268. name := simpleUUID()
  269. now := time.Now().Local()
  270. tableNum := rand.New(rand.NewSource(now.Unix())).Intn(10)
  271. resultMap := make(map[string]any)
  272. newToolKit(t).
  273. autoMigrate(&client.AutoMigrateRequest{
  274. Items: []client.AutoMigrateItem{
  275. {
  276. TablePrefixWithSchema: tablePrefix,
  277. Version: "v1",
  278. TableModelDescribe: tableModelDescribe,
  279. },
  280. },
  281. }).
  282. insert(&client.InsertRequest{
  283. TablePrefixWithSchema: tablePrefix,
  284. Version: "v1",
  285. KeyColumns: []string{"id"},
  286. TableRow: map[string]any{
  287. "id": id,
  288. "name": name,
  289. "time": now,
  290. "table_num": tableNum,
  291. },
  292. UserID: "test",
  293. }).
  294. queryByKeys(&client.QueryByKeysRequest{
  295. TablePrefixWithSchema: tablePrefix,
  296. Version: "v1",
  297. KeyValues: map[string]string{"id": id},
  298. }, &resultMap).
  299. assertEqual(id, resultMap["id"], "ID不一致").
  300. assertEqual(name, resultMap["name"], "名称不一致").
  301. assertEqual(now.UnixMilli(), resultMap["time"].(time.Time).Local().UnixMilli(), "时间不一致").
  302. assertEqual(tableNum, resultMap["table_num"], "表数量不一致")
  303. }
  304. func TestInsertBatch(t *testing.T) {
  305. initClient(t, "localhost:30170", "2b78141779ee432295ca371b91c5cac7")
  306. defer destroyClient(t, "2b78141779ee432295ca371b91c5cac7")
  307. tablePrefix := "test." + simpleUUID()[0:8]
  308. id1 := simpleUUID()
  309. name1 := simpleUUID()
  310. now1 := time.Now().Local()
  311. tableNum1 := rand.New(rand.NewSource(now1.Unix())).Intn(10)
  312. id2 := simpleUUID()
  313. name2 := simpleUUID()
  314. now2 := time.Now().Local()
  315. tableNum2 := rand.New(rand.NewSource(now2.Unix())).Intn(10)
  316. resultsMap := make([]map[string]any, 0)
  317. var totalCount int64
  318. newToolKit(t).
  319. autoMigrate(&client.AutoMigrateRequest{
  320. Items: []client.AutoMigrateItem{
  321. {
  322. TablePrefixWithSchema: tablePrefix,
  323. Version: "v1",
  324. TableModelDescribe: tableModelDescribe,
  325. },
  326. },
  327. }).
  328. insertBatch(&client.InsertBatchRequest{
  329. Items: []client.InsertTableRowItem{
  330. {
  331. TablePrefixWithSchema: tablePrefix,
  332. Version: "v1",
  333. KeyColumns: []string{"id"},
  334. TableRows: []map[string]any{
  335. {
  336. "id": id1,
  337. "name": name1,
  338. "time": now1,
  339. "table_num": tableNum1,
  340. },
  341. {
  342. "id": id2,
  343. "name": name2,
  344. "time": now2,
  345. "table_num": tableNum2,
  346. },
  347. },
  348. },
  349. },
  350. }).
  351. queryByWhereAndOrderBy(&client.QueryByWhereAndOrderByRequest{
  352. TablePrefixWithSchema: tablePrefix,
  353. Version: "v1",
  354. Where: map[string][]any{
  355. "id = ? AND name = ? AND table_num = ?": {id1, name1, tableNum1},
  356. },
  357. PageNo: 1,
  358. PageSize: 1,
  359. }, &resultsMap, &totalCount).
  360. assertEqual(1, int(totalCount), "总数不一致").
  361. assertEqual(id1, resultsMap[0]["id"], "ID不一致").
  362. assertEqual(name1, resultsMap[0]["name"], "名称不一致").
  363. assertEqual(now1.UnixMilli(), resultsMap[0]["time"].(time.Time).Local().UnixMilli(), "时间不一致").
  364. assertEqual(tableNum1, resultsMap[0]["table_num"], "表数量不一致").
  365. commonQuery(&client.CommonQueryRequest{
  366. TablePrefixWithSchema: tablePrefix,
  367. Version: "v1",
  368. Where: map[string][]any{
  369. "id = ? AND name = ? AND table_num = ?": {id2, name2, tableNum2},
  370. },
  371. PageNo: 1,
  372. PageSize: 1,
  373. }, &resultsMap, &totalCount).
  374. assertEqual(1, int(totalCount), "总数不一致").
  375. assertEqual(id2, resultsMap[0]["id"], "ID不一致").
  376. assertEqual(name2, resultsMap[0]["name"], "名称不一致").
  377. assertEqual(now2.UnixMilli(), resultsMap[0]["time"].(time.Time).Local().UnixMilli(), "时间不一致").
  378. assertEqual(tableNum2, resultsMap[0]["table_num"], "表数量不一致").
  379. queryOnlyByWhereAndOrderBy(&client.QueryByWhereAndOrderByRequest{
  380. TablePrefixWithSchema: tablePrefix,
  381. Version: "v1",
  382. Where: map[string][]any{
  383. "id = ? AND name = ? AND table_num = ?": {id1, name1, tableNum1},
  384. },
  385. PageNo: 1,
  386. PageSize: 1,
  387. }, &resultsMap).
  388. assertEqual(id1, resultsMap[0]["id"], "ID不一致").
  389. assertEqual(name1, resultsMap[0]["name"], "名称不一致").
  390. assertEqual(now1.UnixMilli(), resultsMap[0]["time"].(time.Time).Local().UnixMilli(), "时间不一致").
  391. assertEqual(tableNum1, resultsMap[0]["table_num"], "表数量不一致").
  392. commonQueryOnly(&client.CommonQueryRequest{
  393. TablePrefixWithSchema: tablePrefix,
  394. Version: "v1",
  395. Where: map[string][]any{
  396. "id = ? AND name = ? AND table_num = ?": {id2, name2, tableNum2},
  397. },
  398. PageNo: 1,
  399. PageSize: 1,
  400. }, &resultsMap).
  401. assertEqual(id2, resultsMap[0]["id"], "ID不一致").
  402. assertEqual(name2, resultsMap[0]["name"], "名称不一致").
  403. assertEqual(now2.UnixMilli(), resultsMap[0]["time"].(time.Time).Local().UnixMilli(), "时间不一致").
  404. assertEqual(tableNum2, resultsMap[0]["table_num"], "表数量不一致")
  405. }
  406. func TestUpdate(t *testing.T) {
  407. initClient(t, "localhost:30170", "2b78141779ee432295ca371b91c5cac7")
  408. defer destroyClient(t, "2b78141779ee432295ca371b91c5cac7")
  409. tablePrefix := "test." + simpleUUID()[0:8]
  410. id := simpleUUID()
  411. name := simpleUUID()
  412. now := time.Now().Local()
  413. tableNum := rand.New(rand.NewSource(now.Unix())).Intn(10)
  414. newName := simpleUUID()
  415. newNow := time.Now().Local()
  416. newTableNum := rand.New(rand.NewSource(now.Unix())).Intn(10)
  417. resultMap := make(map[string]any)
  418. newToolKit(t).
  419. autoMigrate(&client.AutoMigrateRequest{
  420. Items: []client.AutoMigrateItem{
  421. {
  422. TablePrefixWithSchema: tablePrefix,
  423. Version: "v1",
  424. TableModelDescribe: tableModelDescribe,
  425. },
  426. },
  427. }).
  428. insert(&client.InsertRequest{
  429. TablePrefixWithSchema: tablePrefix,
  430. Version: "v1",
  431. KeyColumns: []string{"id"},
  432. TableRow: map[string]any{
  433. "id": id,
  434. "name": name,
  435. "time": now,
  436. "table_num": tableNum,
  437. },
  438. UserID: "test",
  439. }).
  440. update(&client.UpdateRequest{
  441. TablePrefixWithSchema: tablePrefix,
  442. Version: "v1",
  443. KeyValues: map[string]string{"id": id},
  444. NewTableRow: map[string]any{
  445. "id": id,
  446. "name": newName,
  447. "time": newNow,
  448. "table_num": newTableNum,
  449. },
  450. UserID: "test",
  451. }).
  452. queryByKeys(&client.QueryByKeysRequest{
  453. TablePrefixWithSchema: tablePrefix,
  454. Version: "v1",
  455. KeyValues: map[string]string{"id": id},
  456. }, &resultMap).
  457. assertEqual(id, resultMap["id"], "ID不一致").
  458. assertEqual(newName, resultMap["name"], "名称不一致").
  459. assertEqual(newNow.UnixMilli(), resultMap["time"].(time.Time).Local().UnixMilli(), "时间不一致").
  460. assertEqual(newTableNum, resultMap["table_num"], "表数量不一致")
  461. }
  462. func TestDelete(t *testing.T) {
  463. initClient(t, "localhost:30170", "2b78141779ee432295ca371b91c5cac7")
  464. defer destroyClient(t, "2b78141779ee432295ca371b91c5cac7")
  465. tablePrefix := "test." + simpleUUID()[0:8]
  466. id := simpleUUID()
  467. name := simpleUUID()
  468. now := time.Now().Local()
  469. tableNum := rand.New(rand.NewSource(now.Unix())).Intn(10)
  470. var count int64
  471. newToolKit(t).
  472. autoMigrate(&client.AutoMigrateRequest{
  473. Items: []client.AutoMigrateItem{
  474. {
  475. TablePrefixWithSchema: tablePrefix,
  476. Version: "v1",
  477. TableModelDescribe: tableModelDescribe,
  478. },
  479. },
  480. }).
  481. insert(&client.InsertRequest{
  482. TablePrefixWithSchema: tablePrefix,
  483. Version: "v1",
  484. KeyColumns: []string{"id"},
  485. TableRow: map[string]any{
  486. "id": id,
  487. "name": name,
  488. "time": now,
  489. "table_num": tableNum,
  490. },
  491. UserID: "test",
  492. }).
  493. delete(&client.DeleteRequest{
  494. TablePrefixWithSchema: tablePrefix,
  495. Version: "v1",
  496. KeyValues: map[string]string{"id": id},
  497. UserID: "test",
  498. }).
  499. countWhere(&client.CountWhereRequest{
  500. TablePrefixWithSchema: tablePrefix,
  501. Version: "v1",
  502. Where: map[string][]any{
  503. "id = ?": {id},
  504. },
  505. }, &count).
  506. assertEqual(int64(0), count, "数量不一致")
  507. }
  508. func TestDeleteBatch(t *testing.T) {
  509. initClient(t, "localhost:30170", "2b78141779ee432295ca371b91c5cac7")
  510. defer destroyClient(t, "2b78141779ee432295ca371b91c5cac7")
  511. tablePrefix := "test." + simpleUUID()[0:8]
  512. id1 := simpleUUID()
  513. name1 := simpleUUID()
  514. now1 := time.Now().Local()
  515. tableNum1 := rand.New(rand.NewSource(now1.Unix())).Intn(10)
  516. id2 := simpleUUID()
  517. name2 := simpleUUID()
  518. now2 := time.Now().Local()
  519. tableNum2 := rand.New(rand.NewSource(now2.Unix())).Intn(10)
  520. var count int64
  521. newToolKit(t).
  522. autoMigrate(&client.AutoMigrateRequest{
  523. Items: []client.AutoMigrateItem{
  524. {
  525. TablePrefixWithSchema: tablePrefix,
  526. Version: "v1",
  527. TableModelDescribe: tableModelDescribe,
  528. },
  529. },
  530. }).
  531. insertBatch(&client.InsertBatchRequest{
  532. Items: []client.InsertTableRowItem{
  533. {
  534. TablePrefixWithSchema: tablePrefix,
  535. Version: "v1",
  536. KeyColumns: []string{"id"},
  537. TableRows: []map[string]any{
  538. {
  539. "id": id1,
  540. "name": name1,
  541. "time": now1,
  542. "table_num": tableNum1,
  543. },
  544. {
  545. "id": id2,
  546. "name": name2,
  547. "time": now2,
  548. "table_num": tableNum2,
  549. },
  550. },
  551. },
  552. },
  553. }).
  554. deleteBatch(&client.DeleteBatchRequest{
  555. Items: []client.DeleteTableRowItem{
  556. {
  557. TablePrefixWithSchema: tablePrefix,
  558. Version: "v1",
  559. KeyValues: []map[string]string{
  560. {"id": id1},
  561. {"id": id2},
  562. },
  563. },
  564. },
  565. UserID: "test",
  566. }).
  567. commonCount(&client.CommonCountRequest{
  568. TablePrefixWithSchema: tablePrefix,
  569. Version: "v1",
  570. }, &count).
  571. assertEqual(int64(0), count, "数量不一致")
  572. }
  573. func TestReply(t *testing.T) {
  574. initClient(t, "localhost:30170", "2b78141779ee432295ca371b91c5cac7")
  575. defer destroyClient(t, "2b78141779ee432295ca371b91c5cac7")
  576. tablePrefix := "test." + simpleUUID()[0:8]
  577. id := simpleUUID()
  578. name := simpleUUID()
  579. now := time.Now().Local()
  580. tableNum := rand.New(rand.NewSource(now.Unix())).Intn(10)
  581. resultMap := make(map[string]any)
  582. newToolKit(t).
  583. autoMigrate(&client.AutoMigrateRequest{
  584. Items: []client.AutoMigrateItem{
  585. {
  586. TablePrefixWithSchema: tablePrefix,
  587. Version: "v1",
  588. TableModelDescribe: tableModelDescribe,
  589. },
  590. },
  591. }).
  592. insert(&client.InsertRequest{
  593. TablePrefixWithSchema: tablePrefix,
  594. Version: "v1",
  595. KeyColumns: []string{"id"},
  596. TableRow: map[string]any{
  597. "id": id,
  598. "name": name,
  599. "time": now,
  600. "table_num": tableNum,
  601. },
  602. UserID: "test",
  603. }).
  604. reply(&client.ReplayRequest{
  605. TablePrefixWithSchema: tablePrefix,
  606. Version: "v1",
  607. KeyValues: map[string]string{"id": id},
  608. UserID: "test",
  609. }).
  610. queryByKeys(&client.QueryByKeysRequest{
  611. TablePrefixWithSchema: tablePrefix,
  612. Version: "v1",
  613. KeyValues: map[string]string{"id": id},
  614. }, &resultMap).
  615. assertEqual(id, resultMap["id"], "ID不一致").
  616. assertEqual(name, resultMap["name"], "名称不一致").
  617. assertEqual(now.UnixMilli(), resultMap["time"].(time.Time).Local().UnixMilli(), "时间不一致").
  618. assertEqual(tableNum, resultMap["table_num"], "表数量不一致")
  619. }
  620. func TestEventQuery(t *testing.T) {
  621. initClient(t, "localhost:30170", "2b78141779ee432295ca371b91c5cac7")
  622. defer destroyClient(t, "2b78141779ee432295ca371b91c5cac7")
  623. tablePrefix := "test." + simpleUUID()[0:8]
  624. id := simpleUUID()
  625. name := simpleUUID()
  626. now := time.Now().Local()
  627. tableNum := rand.New(rand.NewSource(now.Unix())).Intn(10)
  628. newName := simpleUUID()
  629. newNow := time.Now().Local()
  630. newTableNum := rand.New(rand.NewSource(now.Unix())).Intn(10)
  631. var totalCount int64
  632. eventInfos := make([]client.EventInfo, 0)
  633. newToolKit(t).
  634. autoMigrate(&client.AutoMigrateRequest{
  635. Items: []client.AutoMigrateItem{
  636. {
  637. TablePrefixWithSchema: tablePrefix,
  638. Version: "v1",
  639. TableModelDescribe: tableModelDescribe,
  640. },
  641. },
  642. }).
  643. insert(&client.InsertRequest{
  644. TablePrefixWithSchema: tablePrefix,
  645. Version: "v1",
  646. KeyColumns: []string{"id"},
  647. TableRow: map[string]any{
  648. "id": id,
  649. "name": name,
  650. "time": now,
  651. "table_num": tableNum,
  652. },
  653. UserID: "test",
  654. }).
  655. update(&client.UpdateRequest{
  656. TablePrefixWithSchema: tablePrefix,
  657. Version: "v1",
  658. KeyValues: map[string]string{"id": id},
  659. NewTableRow: map[string]any{
  660. "id": id,
  661. "name": newName,
  662. "time": newNow,
  663. "table_num": newTableNum,
  664. },
  665. UserID: "test",
  666. }).
  667. countEventByKeys(&client.CountEventByKeysRequest{
  668. TablePrefixWithSchema: tablePrefix,
  669. KeyValues: []string{id},
  670. }, &totalCount).
  671. assertEqual(2, int(totalCount), "总数不一致").
  672. commonCountEvent(&client.CommonCountEventRequest{
  673. TablePrefixWithSchema: tablePrefix,
  674. KeyValues: []string{id},
  675. Version: "v1",
  676. Operation: "create",
  677. CreatorID: "test",
  678. StartCreatedTime: now.Format(time.DateTime),
  679. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  680. }, &totalCount).
  681. assertEqual(1, int(totalCount), "总数不一致").
  682. commonCountEvent(&client.CommonCountEventRequest{
  683. TablePrefixWithSchema: tablePrefix,
  684. KeyValues: []string{id},
  685. Version: "v1",
  686. Operation: "update",
  687. CreatorID: "test",
  688. StartCreatedTime: now.Format(time.DateTime),
  689. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  690. }, &totalCount).
  691. assertEqual(1, int(totalCount), "总数不一致").
  692. eventQueryByKeys(&client.EventQueryByKeysRequest{
  693. TablePrefixWithSchema: tablePrefix,
  694. KeyValues: []string{id},
  695. PageNo: 0,
  696. PageSize: 0,
  697. }, &eventInfos, &totalCount).
  698. assertEqual(2, int(totalCount), "总数不一致").
  699. assertEqual(2, len(eventInfos), "事件数量不一致").
  700. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  701. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  702. assertEqual("create", eventInfos[0].Operation, "操作不一致").
  703. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  704. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  705. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  706. assertEqual(id, eventInfos[1].Key, "关键字段不一致").
  707. assertEqual("v1", eventInfos[1].Version, "版本不一致").
  708. assertEqual("update", eventInfos[1].Operation, "操作不一致").
  709. assertEqual("test", eventInfos[1].CreatorID, "创建者ID不一致").
  710. assertNotEmpty(eventInfos[1].CreateTime, "创建事件为空").
  711. assertNotEmpty(eventInfos[1].Value, "值为空不一致").
  712. eventQueryByKeys(&client.EventQueryByKeysRequest{
  713. TablePrefixWithSchema: tablePrefix,
  714. KeyValues: []string{id},
  715. PageNo: 1,
  716. PageSize: 1,
  717. }, &eventInfos, &totalCount).
  718. assertEqual(2, int(totalCount), "总数不一致").
  719. assertEqual(1, len(eventInfos), "事件数量不一致").
  720. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  721. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  722. assertEqual("create", eventInfos[0].Operation, "操作不一致").
  723. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  724. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  725. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  726. commonEventQuery(&client.CommonEventQueryRequest{
  727. TablePrefixWithSchema: tablePrefix,
  728. KeyValues: []string{id},
  729. Version: "v1",
  730. Operation: "create",
  731. CreatorID: "test",
  732. StartCreatedTime: now.Format(time.DateTime),
  733. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  734. PageNo: 0,
  735. PageSize: 0,
  736. }, &eventInfos, &totalCount).
  737. assertEqual(1, int(totalCount), "总数不一致").
  738. assertEqual(1, len(eventInfos), "事件数量不一致").
  739. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  740. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  741. assertEqual("create", eventInfos[0].Operation, "操作不一致").
  742. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  743. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  744. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  745. commonEventQuery(&client.CommonEventQueryRequest{
  746. TablePrefixWithSchema: tablePrefix,
  747. KeyValues: []string{id},
  748. Version: "v1",
  749. Operation: "update",
  750. CreatorID: "test",
  751. StartCreatedTime: now.Format(time.DateTime),
  752. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  753. PageNo: 0,
  754. PageSize: 0,
  755. }, &eventInfos, &totalCount).
  756. assertEqual(1, int(totalCount), "总数不一致").
  757. assertEqual(1, len(eventInfos), "事件数量不一致").
  758. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  759. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  760. assertEqual("update", eventInfos[0].Operation, "操作不一致").
  761. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  762. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  763. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  764. eventQueryOnlyByKeys(&client.EventQueryByKeysRequest{
  765. TablePrefixWithSchema: tablePrefix,
  766. KeyValues: []string{id},
  767. PageNo: 0,
  768. PageSize: 0,
  769. }, &eventInfos).
  770. assertEqual(2, len(eventInfos), "事件数量不一致").
  771. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  772. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  773. assertEqual("create", eventInfos[0].Operation, "操作不一致").
  774. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  775. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  776. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  777. assertEqual(id, eventInfos[1].Key, "关键字段不一致").
  778. assertEqual("v1", eventInfos[1].Version, "版本不一致").
  779. assertEqual("update", eventInfos[1].Operation, "操作不一致").
  780. assertEqual("test", eventInfos[1].CreatorID, "创建者ID不一致").
  781. assertNotEmpty(eventInfos[1].CreateTime, "创建事件为空").
  782. assertNotEmpty(eventInfos[1].Value, "值为空不一致").
  783. eventQueryOnlyByKeys(&client.EventQueryByKeysRequest{
  784. TablePrefixWithSchema: tablePrefix,
  785. KeyValues: []string{id},
  786. PageNo: 1,
  787. PageSize: 1,
  788. }, &eventInfos).
  789. assertEqual(1, len(eventInfos), "事件数量不一致").
  790. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  791. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  792. assertEqual("create", eventInfos[0].Operation, "操作不一致").
  793. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  794. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  795. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  796. commonEventQueryOnly(&client.CommonEventQueryRequest{
  797. TablePrefixWithSchema: tablePrefix,
  798. KeyValues: []string{id},
  799. Version: "v1",
  800. Operation: "create",
  801. CreatorID: "test",
  802. StartCreatedTime: now.Format(time.DateTime),
  803. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  804. PageNo: 0,
  805. PageSize: 0,
  806. }, &eventInfos).
  807. assertEqual(1, len(eventInfos), "事件数量不一致").
  808. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  809. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  810. assertEqual("create", eventInfos[0].Operation, "操作不一致").
  811. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  812. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  813. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  814. commonEventQueryOnly(&client.CommonEventQueryRequest{
  815. TablePrefixWithSchema: tablePrefix,
  816. KeyValues: []string{id},
  817. Version: "v1",
  818. Operation: "update",
  819. CreatorID: "test",
  820. StartCreatedTime: now.Format(time.DateTime),
  821. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  822. PageNo: 0,
  823. PageSize: 0,
  824. }, &eventInfos).
  825. assertEqual(1, len(eventInfos), "事件数量不一致").
  826. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  827. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  828. assertEqual("update", eventInfos[0].Operation, "操作不一致").
  829. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  830. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  831. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  832. delete(&client.DeleteRequest{
  833. TablePrefixWithSchema: tablePrefix,
  834. Version: "v1",
  835. KeyValues: map[string]string{"id": id},
  836. UserID: "test",
  837. }).
  838. countEventHistoryByKeys(&client.CountEventByKeysRequest{
  839. TablePrefixWithSchema: tablePrefix,
  840. KeyValues: []string{id},
  841. }, &totalCount).
  842. assertEqual(3, int(totalCount), "总数不一致").
  843. commonCountEventHistory(&client.CommonCountEventRequest{
  844. TablePrefixWithSchema: tablePrefix,
  845. KeyValues: []string{id},
  846. Version: "v1",
  847. Operation: "create",
  848. CreatorID: "test",
  849. StartCreatedTime: now.Format(time.DateTime),
  850. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  851. }, &totalCount).
  852. assertEqual(1, int(totalCount), "总数不一致").
  853. commonCountEventHistory(&client.CommonCountEventRequest{
  854. TablePrefixWithSchema: tablePrefix,
  855. KeyValues: []string{id},
  856. Version: "v1",
  857. Operation: "update",
  858. CreatorID: "test",
  859. StartCreatedTime: now.Format(time.DateTime),
  860. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  861. }, &totalCount).
  862. assertEqual(1, int(totalCount), "总数不一致").
  863. commonCountEventHistory(&client.CommonCountEventRequest{
  864. TablePrefixWithSchema: tablePrefix,
  865. KeyValues: []string{id},
  866. Version: "v1",
  867. Operation: "delete",
  868. CreatorID: "test",
  869. StartCreatedTime: now.Format(time.DateTime),
  870. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  871. }, &totalCount).
  872. assertEqual(1, int(totalCount), "总数不一致").
  873. eventHistoryQueryByKeys(&client.EventQueryByKeysRequest{
  874. TablePrefixWithSchema: tablePrefix,
  875. KeyValues: []string{id},
  876. PageNo: 0,
  877. PageSize: 0,
  878. }, &eventInfos, &totalCount).
  879. assertEqual(3, int(totalCount), "总数不一致").
  880. assertEqual(3, len(eventInfos), "事件数量不一致").
  881. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  882. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  883. assertEqual("create", eventInfos[0].Operation, "操作不一致").
  884. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  885. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  886. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  887. assertEqual(id, eventInfos[1].Key, "关键字段不一致").
  888. assertEqual("v1", eventInfos[1].Version, "版本不一致").
  889. assertEqual("update", eventInfos[1].Operation, "操作不一致").
  890. assertEqual("test", eventInfos[1].CreatorID, "创建者ID不一致").
  891. assertNotEmpty(eventInfos[1].CreateTime, "创建事件为空").
  892. assertNotEmpty(eventInfos[1].Value, "值为空不一致").
  893. assertEqual(id, eventInfos[2].Key, "关键字段不一致").
  894. assertEqual("v1", eventInfos[2].Version, "版本不一致").
  895. assertEqual("delete", eventInfos[2].Operation, "操作不一致").
  896. assertEqual("test", eventInfos[2].CreatorID, "创建者ID不一致").
  897. assertNotEmpty(eventInfos[2].CreateTime, "创建事件为空").
  898. assertEqual("", eventInfos[2].Value, "值为空不一致").
  899. eventHistoryQueryByKeys(&client.EventQueryByKeysRequest{
  900. TablePrefixWithSchema: tablePrefix,
  901. KeyValues: []string{id},
  902. PageNo: 1,
  903. PageSize: 1,
  904. }, &eventInfos, &totalCount).
  905. assertEqual(3, int(totalCount), "总数不一致").
  906. assertEqual(1, len(eventInfos), "事件数量不一致").
  907. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  908. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  909. assertEqual("create", eventInfos[0].Operation, "操作不一致").
  910. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  911. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  912. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  913. commonEventHistoryQuery(&client.CommonEventQueryRequest{
  914. TablePrefixWithSchema: tablePrefix,
  915. KeyValues: []string{id},
  916. Version: "v1",
  917. Operation: "create",
  918. CreatorID: "test",
  919. StartCreatedTime: now.Format(time.DateTime),
  920. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  921. PageNo: 0,
  922. PageSize: 0,
  923. }, &eventInfos, &totalCount).
  924. assertEqual(1, int(totalCount), "总数不一致").
  925. assertEqual(1, len(eventInfos), "事件数量不一致").
  926. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  927. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  928. assertEqual("create", eventInfos[0].Operation, "操作不一致").
  929. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  930. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  931. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  932. commonEventHistoryQuery(&client.CommonEventQueryRequest{
  933. TablePrefixWithSchema: tablePrefix,
  934. KeyValues: []string{id},
  935. Version: "v1",
  936. Operation: "update",
  937. CreatorID: "test",
  938. StartCreatedTime: now.Format(time.DateTime),
  939. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  940. PageNo: 0,
  941. PageSize: 0,
  942. }, &eventInfos, &totalCount).
  943. assertEqual(1, int(totalCount), "总数不一致").
  944. assertEqual(1, len(eventInfos), "事件数量不一致").
  945. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  946. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  947. assertEqual("update", eventInfos[0].Operation, "操作不一致").
  948. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  949. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  950. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  951. commonEventHistoryQuery(&client.CommonEventQueryRequest{
  952. TablePrefixWithSchema: tablePrefix,
  953. KeyValues: []string{id},
  954. Version: "v1",
  955. Operation: "delete",
  956. CreatorID: "test",
  957. StartCreatedTime: now.Format(time.DateTime),
  958. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  959. PageNo: 0,
  960. PageSize: 0,
  961. }, &eventInfos, &totalCount).
  962. assertEqual(1, int(totalCount), "总数不一致").
  963. assertEqual(1, len(eventInfos), "事件数量不一致").
  964. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  965. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  966. assertEqual("delete", eventInfos[0].Operation, "操作不一致").
  967. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  968. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  969. assertEqual("", eventInfos[0].Value, "值为空不一致").
  970. eventHistoryQueryOnlyByKeys(&client.EventQueryByKeysRequest{
  971. TablePrefixWithSchema: tablePrefix,
  972. KeyValues: []string{id},
  973. PageNo: 0,
  974. PageSize: 0,
  975. }, &eventInfos).
  976. assertEqual(3, len(eventInfos), "事件数量不一致").
  977. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  978. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  979. assertEqual("create", eventInfos[0].Operation, "操作不一致").
  980. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  981. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  982. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  983. assertEqual(id, eventInfos[1].Key, "关键字段不一致").
  984. assertEqual("v1", eventInfos[1].Version, "版本不一致").
  985. assertEqual("update", eventInfos[1].Operation, "操作不一致").
  986. assertEqual("test", eventInfos[1].CreatorID, "创建者ID不一致").
  987. assertNotEmpty(eventInfos[1].CreateTime, "创建事件为空").
  988. assertNotEmpty(eventInfos[1].Value, "值为空不一致").
  989. assertEqual(id, eventInfos[2].Key, "关键字段不一致").
  990. assertEqual("v1", eventInfos[2].Version, "版本不一致").
  991. assertEqual("delete", eventInfos[2].Operation, "操作不一致").
  992. assertEqual("test", eventInfos[2].CreatorID, "创建者ID不一致").
  993. assertNotEmpty(eventInfos[2].CreateTime, "创建事件为空").
  994. assertEqual("", eventInfos[2].Value, "值为空不一致").
  995. eventHistoryQueryOnlyByKeys(&client.EventQueryByKeysRequest{
  996. TablePrefixWithSchema: tablePrefix,
  997. KeyValues: []string{id},
  998. PageNo: 1,
  999. PageSize: 1,
  1000. }, &eventInfos).
  1001. assertEqual(1, len(eventInfos), "事件数量不一致").
  1002. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  1003. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  1004. assertEqual("create", eventInfos[0].Operation, "操作不一致").
  1005. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  1006. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  1007. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  1008. commonEventHistoryQueryOnly(&client.CommonEventQueryRequest{
  1009. TablePrefixWithSchema: tablePrefix,
  1010. KeyValues: []string{id},
  1011. Version: "v1",
  1012. Operation: "create",
  1013. CreatorID: "test",
  1014. StartCreatedTime: now.Format(time.DateTime),
  1015. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  1016. PageNo: 0,
  1017. PageSize: 0,
  1018. }, &eventInfos).
  1019. assertEqual(1, len(eventInfos), "事件数量不一致").
  1020. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  1021. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  1022. assertEqual("create", eventInfos[0].Operation, "操作不一致").
  1023. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  1024. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  1025. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  1026. commonEventHistoryQueryOnly(&client.CommonEventQueryRequest{
  1027. TablePrefixWithSchema: tablePrefix,
  1028. KeyValues: []string{id},
  1029. Version: "v1",
  1030. Operation: "update",
  1031. CreatorID: "test",
  1032. StartCreatedTime: now.Format(time.DateTime),
  1033. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  1034. PageNo: 0,
  1035. PageSize: 0,
  1036. }, &eventInfos).
  1037. assertEqual(1, len(eventInfos), "事件数量不一致").
  1038. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  1039. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  1040. assertEqual("update", eventInfos[0].Operation, "操作不一致").
  1041. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  1042. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  1043. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  1044. commonEventHistoryQueryOnly(&client.CommonEventQueryRequest{
  1045. TablePrefixWithSchema: tablePrefix,
  1046. KeyValues: []string{id},
  1047. Version: "v1",
  1048. Operation: "delete",
  1049. CreatorID: "test",
  1050. StartCreatedTime: now.Format(time.DateTime),
  1051. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  1052. PageNo: 0,
  1053. PageSize: 0,
  1054. }, &eventInfos).
  1055. assertEqual(1, len(eventInfos), "事件数量不一致").
  1056. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  1057. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  1058. assertEqual("delete", eventInfos[0].Operation, "操作不一致").
  1059. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  1060. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  1061. assertEqual("", eventInfos[0].Value, "值为空不一致")
  1062. }