sdk.go 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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) deleteBatch(req *client.DeleteBatchRequest) *ToolKit {
  69. statement, err := clientInstance.DeleteBatch(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) reply(req *client.ReplayRequest) *ToolKit {
  85. statement, err := clientInstance.Replay(req)
  86. if err != nil {
  87. toolKit.t.Fatal(err)
  88. }
  89. fmt.Println(statement)
  90. return toolKit
  91. }
  92. func (toolKit *ToolKit) queryByWhereAndOrderBy(req *client.QueryByWhereAndOrderByRequest, retInfosMap *[]map[string]any, retTotalCount *int64) *ToolKit {
  93. statement, infosMap, totalCount, err := clientInstance.QueryByWhereAndOrderBy(req)
  94. if err != nil {
  95. toolKit.t.Fatal(err)
  96. }
  97. fmt.Println(statement)
  98. if retInfosMap != nil {
  99. *retInfosMap = make([]map[string]any, 0)
  100. *retInfosMap = infosMap
  101. }
  102. if retTotalCount != nil {
  103. *retTotalCount = totalCount
  104. }
  105. return toolKit
  106. }
  107. func (toolKit *ToolKit) commonQuery(req *client.CommonQueryRequest, retInfosMap *[]map[string]any, retTotalCount *int64) *ToolKit {
  108. statement, infosMap, totalCount, err := clientInstance.CommonQuery(req)
  109. if err != nil {
  110. toolKit.t.Fatal(err)
  111. }
  112. fmt.Println(statement)
  113. if retInfosMap != nil {
  114. *retInfosMap = make([]map[string]any, 0)
  115. *retInfosMap = infosMap
  116. }
  117. if retTotalCount != nil {
  118. *retTotalCount = totalCount
  119. }
  120. return toolKit
  121. }
  122. func (toolKit *ToolKit) queryByKeys(req *client.QueryByKeysRequest, retInfoMap *map[string]any) *ToolKit {
  123. statement, infoMap, err := clientInstance.QueryByKeys(req)
  124. if err != nil {
  125. toolKit.t.Fatal(err)
  126. }
  127. fmt.Println(statement)
  128. if retInfoMap != nil {
  129. *retInfoMap = make(map[string]any)
  130. *retInfoMap = infoMap
  131. }
  132. return toolKit
  133. }
  134. func (toolKit *ToolKit) countWhere(req *client.CountWhereRequest, retCount *int64) *ToolKit {
  135. statement, count, err := clientInstance.CountWhere(req)
  136. if err != nil {
  137. toolKit.t.Fatal(err)
  138. }
  139. fmt.Println(statement)
  140. if retCount != nil {
  141. *retCount = count
  142. }
  143. return toolKit
  144. }
  145. func (toolKit *ToolKit) commonCount(req *client.CommonCountRequest, retCount *int64) *ToolKit {
  146. statement, count, err := clientInstance.CommonCount(req)
  147. if err != nil {
  148. toolKit.t.Fatal(err)
  149. }
  150. fmt.Println(statement)
  151. if retCount != nil {
  152. *retCount = count
  153. }
  154. return toolKit
  155. }
  156. func (toolKit *ToolKit) eventQueryByKeys(req *client.EventQueryByKeysRequest, retInfos *[]client.EventInfo, retTotalCount *int64) *ToolKit {
  157. statement, infos, totalCount, err := clientInstance.EventQueryByKeys(req)
  158. if err != nil {
  159. toolKit.t.Fatal(err)
  160. }
  161. fmt.Println(statement)
  162. if retInfos != nil {
  163. *retInfos = make([]client.EventInfo, 0)
  164. *retInfos = infos
  165. }
  166. if retTotalCount != nil {
  167. *retTotalCount = totalCount
  168. }
  169. return toolKit
  170. }
  171. func (toolKit *ToolKit) commonEventQuery(req *client.CommonEventQueryRequest, retInfos *[]client.EventInfo, retTotalCount *int64) *ToolKit {
  172. statement, infos, totalCount, err := clientInstance.CommonEventQuery(req)
  173. if err != nil {
  174. toolKit.t.Fatal(err)
  175. }
  176. fmt.Println(statement)
  177. if retInfos != nil {
  178. *retInfos = make([]client.EventInfo, 0)
  179. *retInfos = infos
  180. }
  181. if retTotalCount != nil {
  182. *retTotalCount = totalCount
  183. }
  184. return toolKit
  185. }
  186. func (toolKit *ToolKit) countEventByKeys(req *client.CountEventByKeysRequest, retCount *int64) *ToolKit {
  187. statement, count, err := clientInstance.CountEventByKeys(req)
  188. if err != nil {
  189. toolKit.t.Fatal(err)
  190. }
  191. fmt.Println(statement)
  192. if retCount != nil {
  193. *retCount = count
  194. }
  195. return toolKit
  196. }
  197. func (toolKit *ToolKit) commonCountEvent(req *client.CommonCountEventRequest, retCount *int64) *ToolKit {
  198. statement, count, err := clientInstance.CommonCountEvent(req)
  199. if err != nil {
  200. toolKit.t.Fatal(err)
  201. }
  202. fmt.Println(statement)
  203. if retCount != nil {
  204. *retCount = count
  205. }
  206. return toolKit
  207. }
  208. func (toolKit *ToolKit) eventHistoryQueryByKeys(req *client.EventQueryByKeysRequest, retInfos *[]client.EventInfo, retTotalCount *int64) *ToolKit {
  209. statement, infos, totalCount, err := clientInstance.EventHistoryQueryByKeys(req)
  210. if err != nil {
  211. toolKit.t.Fatal(err)
  212. }
  213. fmt.Println(statement)
  214. if retInfos != nil {
  215. *retInfos = make([]client.EventInfo, 0)
  216. *retInfos = infos
  217. }
  218. if retTotalCount != nil {
  219. *retTotalCount = totalCount
  220. }
  221. return toolKit
  222. }
  223. func (toolKit *ToolKit) commonEventHistoryQuery(req *client.CommonEventQueryRequest, retInfos *[]client.EventInfo, retTotalCount *int64) *ToolKit {
  224. statement, infos, totalCount, err := clientInstance.CommonEventHistoryQuery(req)
  225. if err != nil {
  226. toolKit.t.Fatal(err)
  227. }
  228. fmt.Println(statement)
  229. if retInfos != nil {
  230. *retInfos = make([]client.EventInfo, 0)
  231. *retInfos = infos
  232. }
  233. if retTotalCount != nil {
  234. *retTotalCount = totalCount
  235. }
  236. return toolKit
  237. }
  238. func (toolKit *ToolKit) countEventHistoryByKeys(req *client.CountEventByKeysRequest, retCount *int64) *ToolKit {
  239. statement, count, err := clientInstance.CountEventHistoryByKeys(req)
  240. if err != nil {
  241. toolKit.t.Fatal(err)
  242. }
  243. fmt.Println(statement)
  244. if retCount != nil {
  245. *retCount = count
  246. }
  247. return toolKit
  248. }
  249. func (toolKit *ToolKit) commonCountEventHistory(req *client.CommonCountEventRequest, retCount *int64) *ToolKit {
  250. statement, count, err := clientInstance.CommonCountEventHistory(req)
  251. if err != nil {
  252. toolKit.t.Fatal(err)
  253. }
  254. fmt.Println(statement)
  255. if retCount != nil {
  256. *retCount = count
  257. }
  258. return toolKit
  259. }
  260. func (toolKit *ToolKit) assertEqual(expected interface{}, actual interface{}, msgAndArgs ...interface{}) *ToolKit {
  261. assert.Equal(toolKit.t, expected, actual, msgAndArgs)
  262. return toolKit
  263. }
  264. func (toolKit *ToolKit) assertNotEqual(expected interface{}, actual interface{}, msgAndArgs ...interface{}) *ToolKit {
  265. assert.NotEqual(toolKit.t, expected, actual, msgAndArgs)
  266. return toolKit
  267. }
  268. func (toolKit *ToolKit) assertNotEmpty(object interface{}, msgAndArgs ...interface{}) *ToolKit {
  269. assert.NotEmpty(toolKit.t, object, msgAndArgs)
  270. return toolKit
  271. }