v1_test.go 42 KB

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