sdk.go 9.6 KB

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