sdk.go 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. package instance
  2. import (
  3. "git.sxidc.com/service-supports/dps-sdk"
  4. "git.sxidc.com/service-supports/dps-sdk/client"
  5. "github.com/stretchr/testify/assert"
  6. "testing"
  7. )
  8. func initClient(t *testing.T, address string, databaseID string) {
  9. err := dps.InitInstance(address, "v1", databaseID)
  10. if err != nil {
  11. t.Fatal(err)
  12. }
  13. }
  14. func destroyClient(t *testing.T, databaseID string) {
  15. err := dps.DestroyInstance("v1", databaseID)
  16. if err != nil {
  17. t.Fatal(err)
  18. }
  19. }
  20. type ToolKit struct {
  21. t *testing.T
  22. }
  23. func newToolKit(t *testing.T) *ToolKit {
  24. return &ToolKit{t: t}
  25. }
  26. func (toolKit *ToolKit) autoMigrate(items []client.AutoMigrateItem) *ToolKit {
  27. err := dps.AutoMigrate(items...)
  28. if err != nil {
  29. toolKit.t.Fatal(err)
  30. }
  31. return toolKit
  32. }
  33. func (toolKit *ToolKit) transaction(txFunc client.TransactionFunc) *ToolKit {
  34. err := dps.Transaction(txFunc)
  35. if err != nil {
  36. toolKit.t.Fatal(err)
  37. }
  38. return toolKit
  39. }
  40. func (toolKit *ToolKit) insert(req *client.InsertRequest) *ToolKit {
  41. err := dps.Insert(req, nil)
  42. if err != nil {
  43. toolKit.t.Fatal(err)
  44. }
  45. return toolKit
  46. }
  47. func (toolKit *ToolKit) insertBatch(req *client.InsertBatchRequest) *ToolKit {
  48. err := dps.InsertBatch(req, nil)
  49. if err != nil {
  50. toolKit.t.Fatal(err)
  51. }
  52. return toolKit
  53. }
  54. func (toolKit *ToolKit) delete(req *client.DeleteRequest) *ToolKit {
  55. err := dps.Delete(req, nil)
  56. if err != nil {
  57. toolKit.t.Fatal(err)
  58. }
  59. return toolKit
  60. }
  61. func (toolKit *ToolKit) deleteBatch(req *client.DeleteBatchRequest) *ToolKit {
  62. err := dps.DeleteBatch(req, nil)
  63. if err != nil {
  64. toolKit.t.Fatal(err)
  65. }
  66. return toolKit
  67. }
  68. func (toolKit *ToolKit) update(req *client.UpdateRequest) *ToolKit {
  69. err := dps.Update(req, nil)
  70. if err != nil {
  71. toolKit.t.Fatal(err)
  72. }
  73. return toolKit
  74. }
  75. func (toolKit *ToolKit) reply(req *client.ReplayRequest) *ToolKit {
  76. err := dps.Replay(req)
  77. if err != nil {
  78. toolKit.t.Fatal(err)
  79. }
  80. return toolKit
  81. }
  82. func (toolKit *ToolKit) queryByWhereAndOrderBy(req *client.QueryByWhereAndOrderByRequest, retTableRows *[]client.TableRow, retTotalCount *int64) *ToolKit {
  83. tableRows, totalCount, err := dps.QueryByWhereAndOrderBy(req)
  84. if err != nil {
  85. toolKit.t.Fatal(err)
  86. }
  87. if retTableRows != nil {
  88. *retTableRows = tableRows
  89. }
  90. if retTotalCount != nil {
  91. *retTotalCount = totalCount
  92. }
  93. return toolKit
  94. }
  95. func (toolKit *ToolKit) commonQuery(req *client.CommonQueryRequest, retTableRows *[]client.TableRow, retTotalCount *int64) *ToolKit {
  96. tableRows, totalCount, err := dps.CommonQuery(req)
  97. if err != nil {
  98. toolKit.t.Fatal(err)
  99. }
  100. if retTableRows != nil {
  101. *retTableRows = tableRows
  102. }
  103. if retTotalCount != nil {
  104. *retTotalCount = totalCount
  105. }
  106. return toolKit
  107. }
  108. func (toolKit *ToolKit) queryOnlyByWhereAndOrderBy(req *client.QueryByWhereAndOrderByRequest, retTableRows *[]client.TableRow) *ToolKit {
  109. tableRows, err := dps.QueryOnlyByWhereAndOrderBy(req)
  110. if err != nil {
  111. toolKit.t.Fatal(err)
  112. }
  113. if retTableRows != nil {
  114. *retTableRows = tableRows
  115. }
  116. return toolKit
  117. }
  118. func (toolKit *ToolKit) commonQueryOnly(req *client.CommonQueryRequest, retTableRows *[]client.TableRow) *ToolKit {
  119. tableRows, err := dps.CommonQueryOnly(req)
  120. if err != nil {
  121. toolKit.t.Fatal(err)
  122. }
  123. if retTableRows != nil {
  124. *retTableRows = tableRows
  125. }
  126. return toolKit
  127. }
  128. func (toolKit *ToolKit) queryByKeys(req *client.QueryByKeysRequest, retTableRow *client.TableRow) *ToolKit {
  129. tableRow, err := dps.QueryByKeys(req)
  130. if err != nil {
  131. toolKit.t.Fatal(err)
  132. }
  133. if retTableRow != nil {
  134. *retTableRow = *tableRow
  135. }
  136. return toolKit
  137. }
  138. func (toolKit *ToolKit) countWhere(req *client.CountWhereRequest, retCount *int64) *ToolKit {
  139. count, err := dps.CountWhere(req)
  140. if err != nil {
  141. toolKit.t.Fatal(err)
  142. }
  143. if retCount != nil {
  144. *retCount = count
  145. }
  146. return toolKit
  147. }
  148. func (toolKit *ToolKit) commonCount(req *client.CommonCountRequest, retCount *int64) *ToolKit {
  149. count, err := dps.CommonCount(req)
  150. if err != nil {
  151. toolKit.t.Fatal(err)
  152. }
  153. if retCount != nil {
  154. *retCount = count
  155. }
  156. return toolKit
  157. }
  158. func (toolKit *ToolKit) checkExistWhere(req *client.CountWhereRequest, retExist *bool) *ToolKit {
  159. exist, err := dps.CheckExistWhere(req)
  160. if err != nil {
  161. toolKit.t.Fatal(err)
  162. }
  163. if retExist != nil {
  164. *retExist = exist
  165. }
  166. return toolKit
  167. }
  168. func (toolKit *ToolKit) commonCheckExist(req *client.CommonCountRequest, retExist *bool) *ToolKit {
  169. exist, err := dps.CommonCheckExist(req)
  170. if err != nil {
  171. toolKit.t.Fatal(err)
  172. }
  173. if retExist != nil {
  174. *retExist = exist
  175. }
  176. return toolKit
  177. }
  178. func (toolKit *ToolKit) eventQueryByKeys(req *client.EventQueryByKeysRequest, retInfos *[]client.EventInfo, retTotalCount *int64) *ToolKit {
  179. infos, totalCount, err := dps.EventQueryByKeys(req)
  180. if err != nil {
  181. toolKit.t.Fatal(err)
  182. }
  183. if retInfos != nil {
  184. *retInfos = make([]client.EventInfo, 0)
  185. *retInfos = infos
  186. }
  187. if retTotalCount != nil {
  188. *retTotalCount = totalCount
  189. }
  190. return toolKit
  191. }
  192. func (toolKit *ToolKit) commonEventQuery(req *client.CommonEventQueryRequest, retInfos *[]client.EventInfo, retTotalCount *int64) *ToolKit {
  193. infos, totalCount, err := dps.CommonEventQuery(req)
  194. if err != nil {
  195. toolKit.t.Fatal(err)
  196. }
  197. if retInfos != nil {
  198. *retInfos = infos
  199. }
  200. if retTotalCount != nil {
  201. *retTotalCount = totalCount
  202. }
  203. return toolKit
  204. }
  205. func (toolKit *ToolKit) eventQueryOnlyByKeys(req *client.EventQueryByKeysRequest, retInfos *[]client.EventInfo) *ToolKit {
  206. infos, err := dps.EventQueryOnlyByKeys(req)
  207. if err != nil {
  208. toolKit.t.Fatal(err)
  209. }
  210. if retInfos != nil {
  211. *retInfos = infos
  212. }
  213. return toolKit
  214. }
  215. func (toolKit *ToolKit) commonEventQueryOnly(req *client.CommonEventQueryRequest, retInfos *[]client.EventInfo) *ToolKit {
  216. infos, err := dps.CommonEventQueryOnly(req)
  217. if err != nil {
  218. toolKit.t.Fatal(err)
  219. }
  220. if retInfos != nil {
  221. *retInfos = infos
  222. }
  223. return toolKit
  224. }
  225. func (toolKit *ToolKit) countEventByKeys(req *client.CountEventByKeysRequest, retCount *int64) *ToolKit {
  226. count, err := dps.CountEventByKeys(req)
  227. if err != nil {
  228. toolKit.t.Fatal(err)
  229. }
  230. if retCount != nil {
  231. *retCount = count
  232. }
  233. return toolKit
  234. }
  235. func (toolKit *ToolKit) commonCountEvent(req *client.CommonCountEventRequest, retCount *int64) *ToolKit {
  236. count, err := dps.CommonCountEvent(req)
  237. if err != nil {
  238. toolKit.t.Fatal(err)
  239. }
  240. if retCount != nil {
  241. *retCount = count
  242. }
  243. return toolKit
  244. }
  245. func (toolKit *ToolKit) checkEventExistByKeys(req *client.CountEventByKeysRequest, retExist *bool) *ToolKit {
  246. exist, err := dps.CheckEventExistByKeys(req)
  247. if err != nil {
  248. toolKit.t.Fatal(err)
  249. }
  250. if retExist != nil {
  251. *retExist = exist
  252. }
  253. return toolKit
  254. }
  255. func (toolKit *ToolKit) commonCheckEventExist(req *client.CommonCountEventRequest, retExist *bool) *ToolKit {
  256. exist, err := dps.CommonCheckEventExist(req)
  257. if err != nil {
  258. toolKit.t.Fatal(err)
  259. }
  260. if retExist != nil {
  261. *retExist = exist
  262. }
  263. return toolKit
  264. }
  265. func (toolKit *ToolKit) eventHistoryQueryByKeys(req *client.EventQueryByKeysRequest, retInfos *[]client.EventInfo, retTotalCount *int64) *ToolKit {
  266. infos, totalCount, err := dps.EventHistoryQueryByKeys(req)
  267. if err != nil {
  268. toolKit.t.Fatal(err)
  269. }
  270. if retInfos != nil {
  271. *retInfos = infos
  272. }
  273. if retTotalCount != nil {
  274. *retTotalCount = totalCount
  275. }
  276. return toolKit
  277. }
  278. func (toolKit *ToolKit) commonEventHistoryQuery(req *client.CommonEventQueryRequest, retInfos *[]client.EventInfo, retTotalCount *int64) *ToolKit {
  279. infos, totalCount, err := dps.CommonEventHistoryQuery(req)
  280. if err != nil {
  281. toolKit.t.Fatal(err)
  282. }
  283. if retInfos != nil {
  284. *retInfos = infos
  285. }
  286. if retTotalCount != nil {
  287. *retTotalCount = totalCount
  288. }
  289. return toolKit
  290. }
  291. func (toolKit *ToolKit) eventHistoryQueryOnlyByKeys(req *client.EventQueryByKeysRequest, retInfos *[]client.EventInfo) *ToolKit {
  292. infos, err := dps.EventHistoryQueryOnlyByKeys(req)
  293. if err != nil {
  294. toolKit.t.Fatal(err)
  295. }
  296. if retInfos != nil {
  297. *retInfos = infos
  298. }
  299. return toolKit
  300. }
  301. func (toolKit *ToolKit) commonEventHistoryQueryOnly(req *client.CommonEventQueryRequest, retInfos *[]client.EventInfo) *ToolKit {
  302. infos, err := dps.CommonEventHistoryQueryOnly(req)
  303. if err != nil {
  304. toolKit.t.Fatal(err)
  305. }
  306. if retInfos != nil {
  307. *retInfos = infos
  308. }
  309. return toolKit
  310. }
  311. func (toolKit *ToolKit) countEventHistoryByKeys(req *client.CountEventByKeysRequest, retCount *int64) *ToolKit {
  312. count, err := dps.CountEventHistoryByKeys(req)
  313. if err != nil {
  314. toolKit.t.Fatal(err)
  315. }
  316. if retCount != nil {
  317. *retCount = count
  318. }
  319. return toolKit
  320. }
  321. func (toolKit *ToolKit) commonCountEventHistory(req *client.CommonCountEventRequest, retCount *int64) *ToolKit {
  322. count, err := dps.CommonCountEventHistory(req)
  323. if err != nil {
  324. toolKit.t.Fatal(err)
  325. }
  326. if retCount != nil {
  327. *retCount = count
  328. }
  329. return toolKit
  330. }
  331. func (toolKit *ToolKit) checkEventHistoryExistByKeys(req *client.CountEventByKeysRequest, retExist *bool) *ToolKit {
  332. exist, err := dps.CheckEventHistoryExistByKeys(req)
  333. if err != nil {
  334. toolKit.t.Fatal(err)
  335. }
  336. if retExist != nil {
  337. *retExist = exist
  338. }
  339. return toolKit
  340. }
  341. func (toolKit *ToolKit) commonCheckEventHistoryExist(req *client.CommonCountEventRequest, retExist *bool) *ToolKit {
  342. exist, err := dps.CommonCheckEventHistoryExist(req)
  343. if err != nil {
  344. toolKit.t.Fatal(err)
  345. }
  346. if retExist != nil {
  347. *retExist = exist
  348. }
  349. return toolKit
  350. }
  351. func (toolKit *ToolKit) assertEqual(expected interface{}, actual interface{}, msgAndArgs ...interface{}) *ToolKit {
  352. assert.Equal(toolKit.t, expected, actual, msgAndArgs)
  353. return toolKit
  354. }
  355. func (toolKit *ToolKit) assertNotEqual(expected interface{}, actual interface{}, msgAndArgs ...interface{}) *ToolKit {
  356. assert.NotEqual(toolKit.t, expected, actual, msgAndArgs)
  357. return toolKit
  358. }
  359. func (toolKit *ToolKit) assertNotEmpty(object interface{}, msgAndArgs ...interface{}) *ToolKit {
  360. assert.NotEmpty(toolKit.t, object, msgAndArgs)
  361. return toolKit
  362. }