scene_test.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/admin/ep/melloi/model"
  5. "testing"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestServiceQueryDraft(t *testing.T) {
  9. convey.Convey("QueryDraft", t, func(convCtx convey.C) {
  10. var (
  11. scene = &model.Scene{
  12. UserName: "chenmeng",
  13. }
  14. )
  15. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  16. p1, err := s.QueryDraft(scene)
  17. convCtx.Convey("Then err should be nil.p1 should not be nil.", func(convCtx convey.C) {
  18. convCtx.So(err, convey.ShouldBeNil)
  19. convCtx.So(p1, convey.ShouldNotBeNil)
  20. })
  21. })
  22. })
  23. }
  24. func TestServiceUpdateScene(t *testing.T) {
  25. convey.Convey("UpdateScene", t, func(convCtx convey.C) {
  26. var (
  27. scene = &model.Scene{
  28. ID: 66,
  29. }
  30. )
  31. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  32. fusing, err := s.UpdateScene(scene)
  33. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  34. convCtx.So(err, convey.ShouldBeNil)
  35. convCtx.So(fusing, convey.ShouldNotBeNil)
  36. })
  37. })
  38. })
  39. }
  40. func TestServiceAddScene(t *testing.T) {
  41. convey.Convey("AddScene", t, func(convCtx convey.C) {
  42. var (
  43. scene = &model.Scene{
  44. SceneName: "CMTest001",
  45. UserName: "chenmeng",
  46. Department: "test",
  47. Project: "ep",
  48. APP: "melloi",
  49. IsDraft: 1,
  50. }
  51. )
  52. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  53. id, err := s.AddScene(scene)
  54. convCtx.Convey("Then err should be nil.id should not be nil.", func(convCtx convey.C) {
  55. convCtx.So(err, convey.ShouldBeNil)
  56. convCtx.So(id, convey.ShouldNotBeNil)
  57. })
  58. })
  59. })
  60. }
  61. func TestServiceQueryAPI(t *testing.T) {
  62. convey.Convey("QueryAPI", t, func(convCtx convey.C) {
  63. var (
  64. scene = &model.Scene{
  65. ID: 325,
  66. SceneType: 1,
  67. }
  68. )
  69. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  70. p1, err := s.QueryAPI(scene)
  71. convCtx.Convey("Then err should be nil.p1 should not be nil.", func(convCtx convey.C) {
  72. convCtx.So(err, convey.ShouldBeNil)
  73. convCtx.So(p1, convey.ShouldNotBeNil)
  74. })
  75. })
  76. })
  77. }
  78. func TestServiceAddConfig(t *testing.T) {
  79. convey.Convey("AddConfig", t, func(convCtx convey.C) {
  80. var (
  81. script = &model.Script{
  82. ThreadsSum: 120,
  83. LoadTime: 300,
  84. ReadyTime: 10,
  85. SceneID: 325,
  86. GroupID: 1,
  87. }
  88. )
  89. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  90. err := s.AddConfig(script)
  91. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  92. convCtx.So(err, convey.ShouldBeNil)
  93. })
  94. })
  95. })
  96. }
  97. func TestServiceQueryTree(t *testing.T) {
  98. convey.Convey("QueryTree", t, func(convCtx convey.C) {
  99. var (
  100. script = &model.Script{
  101. SceneID: 325,
  102. }
  103. )
  104. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  105. p1, err := s.QueryTree(script)
  106. convCtx.Convey("Then err should be nil.p1 should not be nil.", func(convCtx convey.C) {
  107. convCtx.So(err, convey.ShouldBeNil)
  108. convCtx.So(p1, convey.ShouldNotBeNil)
  109. })
  110. })
  111. })
  112. }
  113. func TestServiceQueryScenesByPage(t *testing.T) {
  114. convey.Convey("QueryScenesByPage", t, func(convCtx convey.C) {
  115. var (
  116. c = context.Background()
  117. sessionID = ""
  118. scene = &model.Scene{
  119. Department: "test",
  120. Project: "ep",
  121. APP: "melloi",
  122. SceneName: "场景压测cmtest01",
  123. UserName: "chenmeng",
  124. }
  125. page = &model.Pagination{
  126. PageNum: int32(1),
  127. PageSize: int32(20),
  128. }
  129. qsrq = &model.QuerySceneRequest{
  130. Scene: *scene,
  131. Pagination: *page,
  132. Executor: "chenmeng",
  133. }
  134. )
  135. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  136. rsp, err := s.QueryScenesByPage(c, sessionID, qsrq)
  137. convCtx.Convey("Then err should be nil.rsp should not be nil.", func(convCtx convey.C) {
  138. convCtx.So(err, convey.ShouldBeNil)
  139. convCtx.So(rsp, convey.ShouldNotBeNil)
  140. })
  141. })
  142. })
  143. }
  144. //func TestServiceAddAndExecuScene(t *testing.T) {
  145. // convey.Convey("AddAndExecuScene", t, func(convCtx convey.C) {
  146. // var (
  147. // c = context.Background()
  148. // scene model.Scene
  149. // )
  150. // convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  151. // resp, err := s.AddAndExecuScene(c, scene)
  152. // convCtx.Convey("Then err should be nil.resp should not be nil.", func(convCtx convey.C) {
  153. // convCtx.So(err, convey.ShouldBeNil)
  154. // convCtx.So(resp, convey.ShouldNotBeNil)
  155. // })
  156. // })
  157. // })
  158. //}
  159. func TestServiceSaveScene(t *testing.T) {
  160. convey.Convey("SaveScene", t, func(convCtx convey.C) {
  161. var (
  162. scene = &model.Scene{
  163. ID: 66,
  164. IsDraft: 0,
  165. SceneType: 2,
  166. }
  167. )
  168. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  169. err := s.SaveScene(scene)
  170. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  171. convCtx.So(err, convey.ShouldBeNil)
  172. })
  173. })
  174. })
  175. }
  176. func TestServiceSaveOrder(t *testing.T) {
  177. convey.Convey("SaveOrder", t, func(convCtx convey.C) {
  178. var (
  179. reqList = []*model.GroupOrder{
  180. {
  181. GroupID: 1,
  182. RunOrder: 2,
  183. ID: 980,
  184. TestName: "cm-test",
  185. },
  186. {
  187. GroupID: 1,
  188. RunOrder: 1,
  189. ID: 973,
  190. TestName: "status111",
  191. },
  192. }
  193. req = model.SaveOrderReq{
  194. GroupOrderList: reqList,
  195. }
  196. scene = &model.Scene{
  197. SceneType: 1,
  198. }
  199. )
  200. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  201. err := s.SaveOrder(req, scene)
  202. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  203. convCtx.So(err, convey.ShouldBeNil)
  204. })
  205. })
  206. })
  207. }
  208. func TestServiceQueryRelation(t *testing.T) {
  209. convey.Convey("QueryRelation", t, func(convCtx convey.C) {
  210. var (
  211. script = &model.Script{
  212. ID: 1568,
  213. }
  214. )
  215. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  216. p1, err := s.QueryRelation(script)
  217. convCtx.Convey("Then err should be nil.p1 should not be nil.", func(convCtx convey.C) {
  218. convCtx.So(err, convey.ShouldBeNil)
  219. convCtx.So(p1, convey.ShouldNotBeNil)
  220. })
  221. })
  222. })
  223. }
  224. func TestServiceDeleteAPI(t *testing.T) {
  225. convey.Convey("DeleteAPI", t, func(convCtx convey.C) {
  226. var (
  227. script = &model.Script{
  228. ID: 1568,
  229. }
  230. )
  231. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  232. err := s.DeleteAPI(script)
  233. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  234. convCtx.So(err, convey.ShouldBeNil)
  235. })
  236. })
  237. })
  238. }
  239. //func TestServiceDoScenePtest(t *testing.T) {
  240. // convey.Convey("DoScenePtest", t, func(convCtx convey.C) {
  241. // var (
  242. // c = context.Background()
  243. // ptestScene model.DoPtestSceneParam
  244. // addPtest bool
  245. // )
  246. // convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  247. // resp, err := s.DoScenePtest(c, ptestScene, addPtest)
  248. // convCtx.Convey("Then err should be nil.resp should not be nil.", func(convCtx convey.C) {
  249. // convCtx.So(err, convey.ShouldBeNil)
  250. // convCtx.So(resp, convey.ShouldNotBeNil)
  251. // })
  252. // })
  253. // })
  254. //}
  255. func TestServiceDoScenePtestBatch(t *testing.T) {
  256. convey.Convey("DoScenePtestBatch", t, func(convCtx convey.C) {
  257. var (
  258. c = context.Background()
  259. ptestScenes model.DoPtestSceneParams
  260. )
  261. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  262. err := s.DoScenePtestBatch(c, ptestScenes, "")
  263. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  264. convCtx.So(err, convey.ShouldBeNil)
  265. })
  266. })
  267. })
  268. }
  269. //func TestServiceGetSceneInfo(t *testing.T) {
  270. // convey.Convey("GetSceneInfo", t, func(convCtx convey.C) {
  271. // var (
  272. // scene = &model.Scene{}
  273. // )
  274. // convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  275. // sceneInfo := GetSceneInfo(scene)
  276. // convCtx.Convey("Then sceneInfo should not be nil.", func(convCtx convey.C) {
  277. // convCtx.So(sceneInfo, convey.ShouldNotBeNil)
  278. // })
  279. // })
  280. // })
  281. //}
  282. func TestServiceQueryExistAPI(t *testing.T) {
  283. convey.Convey("QueryExistAPI", t, func(convCtx convey.C) {
  284. var (
  285. c = context.Background()
  286. sessionID = "24133ff6e561c0cdd0bfb1a8e7802f1c"
  287. script = &model.Script{
  288. SceneID: 325,
  289. }
  290. page = &model.Pagination{
  291. PageNum: int32(1),
  292. PageSize: int32(10),
  293. }
  294. req = &model.APIInfoRequest{
  295. Script: *script,
  296. Pagination: *page,
  297. }
  298. )
  299. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  300. res, err := s.QueryExistAPI(c, sessionID, req)
  301. convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
  302. convCtx.So(err, convey.ShouldBeNil)
  303. convCtx.So(res, convey.ShouldNotBeNil)
  304. })
  305. })
  306. })
  307. }
  308. func TestServiceQueryPreview(t *testing.T) {
  309. convey.Convey("QueryPreview", t, func(convCtx convey.C) {
  310. var (
  311. req = &model.Script{
  312. SceneID: 325,
  313. GroupID: 1,
  314. }
  315. )
  316. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  317. preRes, err := s.QueryPreview(req)
  318. convCtx.Convey("Then err should be nil.preRes should not be nil.", func(convCtx convey.C) {
  319. convCtx.So(err, convey.ShouldBeNil)
  320. convCtx.So(preRes, convey.ShouldNotBeNil)
  321. })
  322. })
  323. })
  324. }
  325. func TestServiceQueryParams(t *testing.T) {
  326. convey.Convey("QueryParams", t, func(convCtx convey.C) {
  327. var (
  328. req = &model.Script{
  329. SceneID: 325,
  330. }
  331. )
  332. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  333. res, tempRes, err := s.QueryParams(req)
  334. convCtx.Convey("Then err should be nil.res,tempRes should not be nil.", func(convCtx convey.C) {
  335. convCtx.So(err, convey.ShouldBeNil)
  336. convCtx.So(tempRes, convey.ShouldNotBeNil)
  337. convCtx.So(res, convey.ShouldNotBeNil)
  338. })
  339. })
  340. })
  341. }
  342. func TestServiceUpdateBindScene(t *testing.T) {
  343. convey.Convey("UpdateBindScene", t, func(convCtx convey.C) {
  344. var (
  345. bindScene = &model.BindScene{
  346. SceneID: 325,
  347. ID: "2000",
  348. }
  349. )
  350. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  351. err := s.UpdateBindScene(bindScene)
  352. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  353. convCtx.So(err, convey.ShouldBeNil)
  354. })
  355. })
  356. })
  357. }
  358. func TestServiceQueryDrawRelation(t *testing.T) {
  359. convey.Convey("QueryDrawRelation", t, func(convCtx convey.C) {
  360. var (
  361. scene = &model.Scene{
  362. ID: 980,
  363. }
  364. )
  365. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  366. res, tempRes, err := s.QueryDrawRelation(scene)
  367. convCtx.Convey("Then err should be nil.res,tempRes should not be nil.", func(convCtx convey.C) {
  368. convCtx.So(err, convey.ShouldBeNil)
  369. convCtx.So(tempRes, convey.ShouldNotBeNil)
  370. convCtx.So(res, convey.ShouldNotBeNil)
  371. })
  372. })
  373. })
  374. }
  375. func TestServiceDeleteDraft(t *testing.T) {
  376. convey.Convey("DeleteDraft", t, func(convCtx convey.C) {
  377. var (
  378. scene = &model.Scene{
  379. UserName: "chenmeng",
  380. ID: 980,
  381. }
  382. )
  383. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  384. err := s.DeleteDraft(scene)
  385. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  386. convCtx.So(err, convey.ShouldBeNil)
  387. })
  388. })
  389. })
  390. }
  391. func TestServiceQueryConfig(t *testing.T) {
  392. convey.Convey("QueryConfig", t, func(convCtx convey.C) {
  393. var (
  394. script = &model.Script{
  395. SceneID: 325,
  396. GroupID: 1,
  397. }
  398. )
  399. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  400. p1, err := s.QueryConfig(script)
  401. convCtx.Convey("Then err should be nil.p1 should not be nil.", func(convCtx convey.C) {
  402. convCtx.So(err, convey.ShouldBeNil)
  403. convCtx.So(p1, convey.ShouldNotBeNil)
  404. })
  405. })
  406. })
  407. }
  408. func TestServiceDeleteScene(t *testing.T) {
  409. convey.Convey("DeleteScene", t, func(convCtx convey.C) {
  410. var (
  411. scene = &model.Scene{
  412. ID: 325,
  413. }
  414. )
  415. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  416. err := s.DeleteScene(scene)
  417. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  418. convCtx.So(err, convey.ShouldBeNil)
  419. })
  420. })
  421. })
  422. }