sdk.go 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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) autoMigrateBatch(req *client.AutoMigrateBatchRequest) *ToolKit {
  38. err := clientInstance.AutoMigrateBatch(req)
  39. if err != nil {
  40. toolKit.t.Fatal(err)
  41. }
  42. return toolKit
  43. }
  44. func (toolKit *ToolKit) transaction(txFunc client.TransactionFunc) *ToolKit {
  45. err := clientInstance.Transaction(txFunc)
  46. if err != nil {
  47. toolKit.t.Fatal(err)
  48. }
  49. return toolKit
  50. }
  51. func (toolKit *ToolKit) insert(req *client.InsertRequest) *ToolKit {
  52. statement, err := clientInstance.Insert(req)
  53. if err != nil {
  54. toolKit.t.Fatal(err)
  55. }
  56. fmt.Println(statement)
  57. return toolKit
  58. }
  59. func (toolKit *ToolKit) insertBatch(req *client.InsertBatchRequest) *ToolKit {
  60. statement, err := clientInstance.InsertBatch(req)
  61. if err != nil {
  62. toolKit.t.Fatal(err)
  63. }
  64. fmt.Println(statement)
  65. return toolKit
  66. }
  67. func (toolKit *ToolKit) delete(req *client.DeleteRequest) *ToolKit {
  68. statement, err := clientInstance.Delete(req)
  69. if err != nil {
  70. toolKit.t.Fatal(err)
  71. }
  72. fmt.Println(statement)
  73. return toolKit
  74. }
  75. func (toolKit *ToolKit) deleteBatch(req *client.DeleteBatchRequest) *ToolKit {
  76. statement, err := clientInstance.DeleteBatch(req)
  77. if err != nil {
  78. toolKit.t.Fatal(err)
  79. }
  80. fmt.Println(statement)
  81. return toolKit
  82. }
  83. func (toolKit *ToolKit) update(req *client.UpdateRequest) *ToolKit {
  84. statement, err := clientInstance.Update(req)
  85. if err != nil {
  86. toolKit.t.Fatal(err)
  87. }
  88. fmt.Println(statement)
  89. return toolKit
  90. }
  91. func (toolKit *ToolKit) reply(req *client.ReplayRequest) *ToolKit {
  92. statement, err := clientInstance.Replay(req)
  93. if err != nil {
  94. toolKit.t.Fatal(err)
  95. }
  96. fmt.Println(statement)
  97. return toolKit
  98. }
  99. func (toolKit *ToolKit) queryByWhereAndOrderBy(req *client.QueryByWhereAndOrderByRequest, retInfosMap *[]map[string]any, retTotalCount *int64) *ToolKit {
  100. statement, infosMap, totalCount, err := clientInstance.QueryByWhereAndOrderBy(req)
  101. if err != nil {
  102. toolKit.t.Fatal(err)
  103. }
  104. fmt.Println(statement)
  105. if retInfosMap != nil {
  106. *retInfosMap = make([]map[string]any, 0)
  107. *retInfosMap = infosMap
  108. }
  109. if retTotalCount != nil {
  110. *retTotalCount = totalCount
  111. }
  112. return toolKit
  113. }
  114. func (toolKit *ToolKit) commonQuery(req *client.CommonQueryRequest, retInfosMap *[]map[string]any, retTotalCount *int64) *ToolKit {
  115. statement, infosMap, totalCount, err := clientInstance.CommonQuery(req)
  116. if err != nil {
  117. toolKit.t.Fatal(err)
  118. }
  119. fmt.Println(statement)
  120. if retInfosMap != nil {
  121. *retInfosMap = make([]map[string]any, 0)
  122. *retInfosMap = infosMap
  123. }
  124. if retTotalCount != nil {
  125. *retTotalCount = totalCount
  126. }
  127. return toolKit
  128. }
  129. func (toolKit *ToolKit) queryByKeys(req *client.QueryByKeysRequest, retInfoMap *map[string]any) *ToolKit {
  130. statement, infoMap, err := clientInstance.QueryByKeys(req)
  131. if err != nil {
  132. toolKit.t.Fatal(err)
  133. }
  134. fmt.Println(statement)
  135. if retInfoMap != nil {
  136. *retInfoMap = make(map[string]any)
  137. *retInfoMap = infoMap
  138. }
  139. return toolKit
  140. }
  141. func (toolKit *ToolKit) countWhere(req *client.CountWhereRequest, retCount *int64) *ToolKit {
  142. statement, count, err := clientInstance.CountWhere(req)
  143. if err != nil {
  144. toolKit.t.Fatal(err)
  145. }
  146. fmt.Println(statement)
  147. if retCount != nil {
  148. *retCount = count
  149. }
  150. return toolKit
  151. }
  152. func (toolKit *ToolKit) commonCount(req *client.CommonCountRequest, retCount *int64) *ToolKit {
  153. statement, count, err := clientInstance.CommonCount(req)
  154. if err != nil {
  155. toolKit.t.Fatal(err)
  156. }
  157. fmt.Println(statement)
  158. if retCount != nil {
  159. *retCount = count
  160. }
  161. return toolKit
  162. }
  163. func (toolKit *ToolKit) eventQueryByKeys(req *client.EventQueryByKeysRequest, retInfos *[]client.EventInfo, retTotalCount *int64) *ToolKit {
  164. statement, infos, totalCount, err := clientInstance.EventQueryByKeys(req)
  165. if err != nil {
  166. toolKit.t.Fatal(err)
  167. }
  168. fmt.Println(statement)
  169. if retInfos != nil {
  170. *retInfos = make([]client.EventInfo, 0)
  171. *retInfos = infos
  172. }
  173. if retTotalCount != nil {
  174. *retTotalCount = totalCount
  175. }
  176. return toolKit
  177. }
  178. func (toolKit *ToolKit) commonEventQuery(req *client.CommonEventQueryRequest, retInfos *[]client.EventInfo, retTotalCount *int64) *ToolKit {
  179. statement, infos, totalCount, err := clientInstance.CommonEventQuery(req)
  180. if err != nil {
  181. toolKit.t.Fatal(err)
  182. }
  183. fmt.Println(statement)
  184. if retInfos != nil {
  185. *retInfos = make([]client.EventInfo, 0)
  186. *retInfos = infos
  187. }
  188. if retTotalCount != nil {
  189. *retTotalCount = totalCount
  190. }
  191. return toolKit
  192. }
  193. func (toolKit *ToolKit) countEventByKeys(req *client.CountEventByKeysRequest, retCount *int64) *ToolKit {
  194. statement, count, err := clientInstance.CountEventByKeys(req)
  195. if err != nil {
  196. toolKit.t.Fatal(err)
  197. }
  198. fmt.Println(statement)
  199. if retCount != nil {
  200. *retCount = count
  201. }
  202. return toolKit
  203. }
  204. func (toolKit *ToolKit) commonCountEvent(req *client.CommonCountEventRequest, retCount *int64) *ToolKit {
  205. statement, count, err := clientInstance.CommonCountEvent(req)
  206. if err != nil {
  207. toolKit.t.Fatal(err)
  208. }
  209. fmt.Println(statement)
  210. if retCount != nil {
  211. *retCount = count
  212. }
  213. return toolKit
  214. }
  215. func (toolKit *ToolKit) eventHistoryQueryByKeys(req *client.EventQueryByKeysRequest, retInfos *[]client.EventInfo, retTotalCount *int64) *ToolKit {
  216. statement, infos, totalCount, err := clientInstance.EventHistoryQueryByKeys(req)
  217. if err != nil {
  218. toolKit.t.Fatal(err)
  219. }
  220. fmt.Println(statement)
  221. if retInfos != nil {
  222. *retInfos = make([]client.EventInfo, 0)
  223. *retInfos = infos
  224. }
  225. if retTotalCount != nil {
  226. *retTotalCount = totalCount
  227. }
  228. return toolKit
  229. }
  230. func (toolKit *ToolKit) commonEventHistoryQuery(req *client.CommonEventQueryRequest, retInfos *[]client.EventInfo, retTotalCount *int64) *ToolKit {
  231. statement, infos, totalCount, err := clientInstance.CommonEventHistoryQuery(req)
  232. if err != nil {
  233. toolKit.t.Fatal(err)
  234. }
  235. fmt.Println(statement)
  236. if retInfos != nil {
  237. *retInfos = make([]client.EventInfo, 0)
  238. *retInfos = infos
  239. }
  240. if retTotalCount != nil {
  241. *retTotalCount = totalCount
  242. }
  243. return toolKit
  244. }
  245. func (toolKit *ToolKit) countEventHistoryByKeys(req *client.CountEventByKeysRequest, retCount *int64) *ToolKit {
  246. statement, count, err := clientInstance.CountEventHistoryByKeys(req)
  247. if err != nil {
  248. toolKit.t.Fatal(err)
  249. }
  250. fmt.Println(statement)
  251. if retCount != nil {
  252. *retCount = count
  253. }
  254. return toolKit
  255. }
  256. func (toolKit *ToolKit) commonCountEventHistory(req *client.CommonCountEventRequest, retCount *int64) *ToolKit {
  257. statement, count, err := clientInstance.CommonCountEventHistory(req)
  258. if err != nil {
  259. toolKit.t.Fatal(err)
  260. }
  261. fmt.Println(statement)
  262. if retCount != nil {
  263. *retCount = count
  264. }
  265. return toolKit
  266. }
  267. func (toolKit *ToolKit) assertEqual(expected interface{}, actual interface{}, msgAndArgs ...interface{}) *ToolKit {
  268. assert.Equal(toolKit.t, expected, actual, msgAndArgs)
  269. return toolKit
  270. }
  271. func (toolKit *ToolKit) assertNotEqual(expected interface{}, actual interface{}, msgAndArgs ...interface{}) *ToolKit {
  272. assert.NotEqual(toolKit.t, expected, actual, msgAndArgs)
  273. return toolKit
  274. }
  275. func (toolKit *ToolKit) assertNotEmpty(object interface{}, msgAndArgs ...interface{}) *ToolKit {
  276. assert.NotEmpty(toolKit.t, object, msgAndArgs)
  277. return toolKit
  278. }