instance_test.go 40 KB

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