sdk.go 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  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) deleteWhere(req *client.DeleteWhereRequest) *ToolKit {
  62. err := dps.DeleteWhere(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) updateWhere(req *client.UpdateWhereRequest) *ToolKit {
  76. err := dps.UpdateWhere(req, nil)
  77. if err != nil {
  78. toolKit.t.Fatal(err)
  79. }
  80. return toolKit
  81. }
  82. func (toolKit *ToolKit) reply(req *client.ReplayRequest) *ToolKit {
  83. err := dps.Replay(req)
  84. if err != nil {
  85. toolKit.t.Fatal(err)
  86. }
  87. return toolKit
  88. }
  89. func (toolKit *ToolKit) queryByWhereAndOrderBy(req *client.QueryByWhereAndOrderByRequest, retTableRows *[]client.TableRow, retTotalCount *int64) *ToolKit {
  90. tableRows, totalCount, err := dps.QueryByWhereAndOrderBy(req)
  91. if err != nil {
  92. toolKit.t.Fatal(err)
  93. }
  94. if retTableRows != nil {
  95. *retTableRows = tableRows
  96. }
  97. if retTotalCount != nil {
  98. *retTotalCount = totalCount
  99. }
  100. return toolKit
  101. }
  102. func (toolKit *ToolKit) commonQuery(req *client.CommonQueryRequest, retTableRows *[]client.TableRow, retTotalCount *int64) *ToolKit {
  103. tableRows, totalCount, err := dps.CommonQuery(req)
  104. if err != nil {
  105. toolKit.t.Fatal(err)
  106. }
  107. if retTableRows != nil {
  108. *retTableRows = tableRows
  109. }
  110. if retTotalCount != nil {
  111. *retTotalCount = totalCount
  112. }
  113. return toolKit
  114. }
  115. func (toolKit *ToolKit) queryOnlyByWhereAndOrderBy(req *client.QueryByWhereAndOrderByRequest, retTableRows *[]client.TableRow) *ToolKit {
  116. tableRows, err := dps.QueryOnlyByWhereAndOrderBy(req)
  117. if err != nil {
  118. toolKit.t.Fatal(err)
  119. }
  120. if retTableRows != nil {
  121. *retTableRows = tableRows
  122. }
  123. return toolKit
  124. }
  125. func (toolKit *ToolKit) commonQueryOnly(req *client.CommonQueryRequest, retTableRows *[]client.TableRow) *ToolKit {
  126. tableRows, err := dps.CommonQueryOnly(req)
  127. if err != nil {
  128. toolKit.t.Fatal(err)
  129. }
  130. if retTableRows != nil {
  131. *retTableRows = tableRows
  132. }
  133. return toolKit
  134. }
  135. func (toolKit *ToolKit) queryByKeys(req *client.QueryByKeysRequest, retTableRow *client.TableRow) *ToolKit {
  136. tableRow, err := dps.QueryByKeys(req)
  137. if err != nil {
  138. toolKit.t.Fatal(err)
  139. }
  140. if retTableRow != nil {
  141. *retTableRow = *tableRow
  142. }
  143. return toolKit
  144. }
  145. func (toolKit *ToolKit) countWhere(req *client.CountWhereRequest, retCount *int64) *ToolKit {
  146. count, err := dps.CountWhere(req)
  147. if err != nil {
  148. toolKit.t.Fatal(err)
  149. }
  150. if retCount != nil {
  151. *retCount = count
  152. }
  153. return toolKit
  154. }
  155. func (toolKit *ToolKit) commonCount(req *client.CommonCountRequest, retCount *int64) *ToolKit {
  156. count, err := dps.CommonCount(req)
  157. if err != nil {
  158. toolKit.t.Fatal(err)
  159. }
  160. if retCount != nil {
  161. *retCount = count
  162. }
  163. return toolKit
  164. }
  165. func (toolKit *ToolKit) checkExistWhere(req *client.CountWhereRequest, retExist *bool) *ToolKit {
  166. exist, err := dps.CheckExistWhere(req)
  167. if err != nil {
  168. toolKit.t.Fatal(err)
  169. }
  170. if retExist != nil {
  171. *retExist = exist
  172. }
  173. return toolKit
  174. }
  175. func (toolKit *ToolKit) commonCheckExist(req *client.CommonCountRequest, retExist *bool) *ToolKit {
  176. exist, err := dps.CommonCheckExist(req)
  177. if err != nil {
  178. toolKit.t.Fatal(err)
  179. }
  180. if retExist != nil {
  181. *retExist = exist
  182. }
  183. return toolKit
  184. }
  185. func (toolKit *ToolKit) eventQueryByKeys(req *client.EventQueryByKeysRequest, retInfos *[]client.EventInfo, retTotalCount *int64) *ToolKit {
  186. infos, totalCount, err := dps.EventQueryByKeys(req)
  187. if err != nil {
  188. toolKit.t.Fatal(err)
  189. }
  190. if retInfos != nil {
  191. *retInfos = make([]client.EventInfo, 0)
  192. *retInfos = infos
  193. }
  194. if retTotalCount != nil {
  195. *retTotalCount = totalCount
  196. }
  197. return toolKit
  198. }
  199. func (toolKit *ToolKit) commonEventQuery(req *client.CommonEventQueryRequest, retInfos *[]client.EventInfo, retTotalCount *int64) *ToolKit {
  200. infos, totalCount, err := dps.CommonEventQuery(req)
  201. if err != nil {
  202. toolKit.t.Fatal(err)
  203. }
  204. if retInfos != nil {
  205. *retInfos = infos
  206. }
  207. if retTotalCount != nil {
  208. *retTotalCount = totalCount
  209. }
  210. return toolKit
  211. }
  212. func (toolKit *ToolKit) eventQueryOnlyByKeys(req *client.EventQueryByKeysRequest, retInfos *[]client.EventInfo) *ToolKit {
  213. infos, err := dps.EventQueryOnlyByKeys(req)
  214. if err != nil {
  215. toolKit.t.Fatal(err)
  216. }
  217. if retInfos != nil {
  218. *retInfos = infos
  219. }
  220. return toolKit
  221. }
  222. func (toolKit *ToolKit) commonEventQueryOnly(req *client.CommonEventQueryRequest, retInfos *[]client.EventInfo) *ToolKit {
  223. infos, err := dps.CommonEventQueryOnly(req)
  224. if err != nil {
  225. toolKit.t.Fatal(err)
  226. }
  227. if retInfos != nil {
  228. *retInfos = infos
  229. }
  230. return toolKit
  231. }
  232. func (toolKit *ToolKit) countEventByKeys(req *client.CountEventByKeysRequest, retCount *int64) *ToolKit {
  233. count, err := dps.CountEventByKeys(req)
  234. if err != nil {
  235. toolKit.t.Fatal(err)
  236. }
  237. if retCount != nil {
  238. *retCount = count
  239. }
  240. return toolKit
  241. }
  242. func (toolKit *ToolKit) commonCountEvent(req *client.CommonCountEventRequest, retCount *int64) *ToolKit {
  243. count, err := dps.CommonCountEvent(req)
  244. if err != nil {
  245. toolKit.t.Fatal(err)
  246. }
  247. if retCount != nil {
  248. *retCount = count
  249. }
  250. return toolKit
  251. }
  252. func (toolKit *ToolKit) checkEventExistByKeys(req *client.CountEventByKeysRequest, retExist *bool) *ToolKit {
  253. exist, err := dps.CheckEventExistByKeys(req)
  254. if err != nil {
  255. toolKit.t.Fatal(err)
  256. }
  257. if retExist != nil {
  258. *retExist = exist
  259. }
  260. return toolKit
  261. }
  262. func (toolKit *ToolKit) commonCheckEventExist(req *client.CommonCountEventRequest, retExist *bool) *ToolKit {
  263. exist, err := dps.CommonCheckEventExist(req)
  264. if err != nil {
  265. toolKit.t.Fatal(err)
  266. }
  267. if retExist != nil {
  268. *retExist = exist
  269. }
  270. return toolKit
  271. }
  272. func (toolKit *ToolKit) eventHistoryQueryByKeys(req *client.EventQueryByKeysRequest, retInfos *[]client.EventInfo, retTotalCount *int64) *ToolKit {
  273. infos, totalCount, err := dps.EventHistoryQueryByKeys(req)
  274. if err != nil {
  275. toolKit.t.Fatal(err)
  276. }
  277. if retInfos != nil {
  278. *retInfos = infos
  279. }
  280. if retTotalCount != nil {
  281. *retTotalCount = totalCount
  282. }
  283. return toolKit
  284. }
  285. func (toolKit *ToolKit) commonEventHistoryQuery(req *client.CommonEventQueryRequest, retInfos *[]client.EventInfo, retTotalCount *int64) *ToolKit {
  286. infos, totalCount, err := dps.CommonEventHistoryQuery(req)
  287. if err != nil {
  288. toolKit.t.Fatal(err)
  289. }
  290. if retInfos != nil {
  291. *retInfos = infos
  292. }
  293. if retTotalCount != nil {
  294. *retTotalCount = totalCount
  295. }
  296. return toolKit
  297. }
  298. func (toolKit *ToolKit) eventHistoryQueryOnlyByKeys(req *client.EventQueryByKeysRequest, retInfos *[]client.EventInfo) *ToolKit {
  299. infos, err := dps.EventHistoryQueryOnlyByKeys(req)
  300. if err != nil {
  301. toolKit.t.Fatal(err)
  302. }
  303. if retInfos != nil {
  304. *retInfos = infos
  305. }
  306. return toolKit
  307. }
  308. func (toolKit *ToolKit) commonEventHistoryQueryOnly(req *client.CommonEventQueryRequest, retInfos *[]client.EventInfo) *ToolKit {
  309. infos, err := dps.CommonEventHistoryQueryOnly(req)
  310. if err != nil {
  311. toolKit.t.Fatal(err)
  312. }
  313. if retInfos != nil {
  314. *retInfos = infos
  315. }
  316. return toolKit
  317. }
  318. func (toolKit *ToolKit) countEventHistoryByKeys(req *client.CountEventByKeysRequest, retCount *int64) *ToolKit {
  319. count, err := dps.CountEventHistoryByKeys(req)
  320. if err != nil {
  321. toolKit.t.Fatal(err)
  322. }
  323. if retCount != nil {
  324. *retCount = count
  325. }
  326. return toolKit
  327. }
  328. func (toolKit *ToolKit) commonCountEventHistory(req *client.CommonCountEventRequest, retCount *int64) *ToolKit {
  329. count, err := dps.CommonCountEventHistory(req)
  330. if err != nil {
  331. toolKit.t.Fatal(err)
  332. }
  333. if retCount != nil {
  334. *retCount = count
  335. }
  336. return toolKit
  337. }
  338. func (toolKit *ToolKit) checkEventHistoryExistByKeys(req *client.CountEventByKeysRequest, retExist *bool) *ToolKit {
  339. exist, err := dps.CheckEventHistoryExistByKeys(req)
  340. if err != nil {
  341. toolKit.t.Fatal(err)
  342. }
  343. if retExist != nil {
  344. *retExist = exist
  345. }
  346. return toolKit
  347. }
  348. func (toolKit *ToolKit) commonCheckEventHistoryExist(req *client.CommonCountEventRequest, retExist *bool) *ToolKit {
  349. exist, err := dps.CommonCheckEventHistoryExist(req)
  350. if err != nil {
  351. toolKit.t.Fatal(err)
  352. }
  353. if retExist != nil {
  354. *retExist = exist
  355. }
  356. return toolKit
  357. }
  358. func (toolKit *ToolKit) assertEqual(expected interface{}, actual interface{}, msgAndArgs ...interface{}) *ToolKit {
  359. assert.Equal(toolKit.t, expected, actual, msgAndArgs)
  360. return toolKit
  361. }
  362. func (toolKit *ToolKit) assertNotEqual(expected interface{}, actual interface{}, msgAndArgs ...interface{}) *ToolKit {
  363. assert.NotEqual(toolKit.t, expected, actual, msgAndArgs)
  364. return toolKit
  365. }
  366. func (toolKit *ToolKit) assertNotEmpty(object interface{}, msgAndArgs ...interface{}) *ToolKit {
  367. assert.NotEmpty(toolKit.t, object, msgAndArgs)
  368. return toolKit
  369. }