scene_test.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. package dao
  2. import (
  3. "go-common/app/admin/ep/melloi/model"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestDaoAddScene(t *testing.T) {
  8. convey.Convey("AddScene", t, func(convCtx convey.C) {
  9. var (
  10. scene = &model.Scene{
  11. SceneName: "CMTest001",
  12. UserName: "chenmeng",
  13. Department: "test",
  14. Project: "ep",
  15. APP: "melloi",
  16. IsDraft: 1,
  17. }
  18. )
  19. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  20. sceneId, err := d.AddScene(scene)
  21. convCtx.Convey("Then err should be nil.sceneId should not be nil.", func(convCtx convey.C) {
  22. convCtx.So(err, convey.ShouldBeNil)
  23. convCtx.So(sceneId, convey.ShouldNotBeNil)
  24. })
  25. })
  26. })
  27. }
  28. func TestDaoQueryDraft(t *testing.T) {
  29. convey.Convey("QueryDraft", t, func(convCtx convey.C) {
  30. var (
  31. scene = &model.Scene{
  32. UserName: "chenmeng",
  33. }
  34. )
  35. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  36. res, err := d.QueryDraft(scene)
  37. convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
  38. convCtx.So(err, convey.ShouldBeNil)
  39. convCtx.So(res, convey.ShouldNotBeNil)
  40. })
  41. })
  42. })
  43. }
  44. func TestDaoUpdateScene(t *testing.T) {
  45. convey.Convey("UpdateScene", t, func(convCtx convey.C) {
  46. var (
  47. scene = &model.Scene{
  48. ID: 66,
  49. }
  50. scriptIDList = []int{1831, 1832, 1833, 1834, 1835}
  51. )
  52. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  53. fusing, err := d.UpdateScene(scene, scriptIDList)
  54. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  55. convCtx.So(err, convey.ShouldBeNil)
  56. convCtx.So(fusing, convey.ShouldNotBeNil)
  57. })
  58. })
  59. })
  60. }
  61. func TestDaoSaveScene(t *testing.T) {
  62. convey.Convey("SaveScene", t, func(convCtx convey.C) {
  63. var (
  64. scene = &model.Scene{
  65. ID: 66,
  66. IsDraft: 0,
  67. SceneType: 2,
  68. }
  69. )
  70. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  71. err := d.SaveScene(scene)
  72. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  73. convCtx.So(err, convey.ShouldBeNil)
  74. })
  75. })
  76. })
  77. }
  78. func TestDaoSaveOrderAuto(t *testing.T) {
  79. convey.Convey("SaveOrder", t, func(convCtx convey.C) {
  80. var (
  81. reqList = []*model.GroupOrder{
  82. {
  83. GroupID: 1,
  84. RunOrder: 2,
  85. ID: 980,
  86. TestName: "cm-test",
  87. },
  88. {
  89. GroupID: 1,
  90. RunOrder: 1,
  91. ID: 973,
  92. TestName: "status111",
  93. },
  94. }
  95. sceneAuto = &model.Scene{
  96. SceneType: 1,
  97. }
  98. )
  99. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  100. err := d.SaveOrder(reqList, sceneAuto)
  101. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  102. convCtx.So(err, convey.ShouldBeNil)
  103. })
  104. })
  105. })
  106. }
  107. func TestDaoSaveOrderGroup(t *testing.T) {
  108. convey.Convey("SaveOrder", t, func(convCtx convey.C) {
  109. var (
  110. reqList = []*model.GroupOrder{
  111. {
  112. GroupID: 1,
  113. RunOrder: 2,
  114. ID: 980,
  115. TestName: "cm-test",
  116. },
  117. {
  118. GroupID: 1,
  119. RunOrder: 1,
  120. ID: 973,
  121. TestName: "status111",
  122. },
  123. }
  124. sceneGroup = &model.Scene{
  125. SceneType: 2,
  126. }
  127. )
  128. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  129. err := d.SaveOrder(reqList, sceneGroup)
  130. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  131. convCtx.So(err, convey.ShouldBeNil)
  132. })
  133. })
  134. })
  135. }
  136. func TestDaoQueryGroupId(t *testing.T) {
  137. convey.Convey("QueryGroupId", t, func(convCtx convey.C) {
  138. var (
  139. script = &model.Script{
  140. ID: 1568,
  141. }
  142. )
  143. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  144. res, groupId, err := d.QueryGroupId(script)
  145. convCtx.Convey("Then err should be nil.res,groupId should not be nil.", func(convCtx convey.C) {
  146. convCtx.So(err, convey.ShouldBeNil)
  147. convCtx.So(groupId, convey.ShouldNotBeNil)
  148. convCtx.So(res, convey.ShouldNotBeNil)
  149. })
  150. })
  151. })
  152. }
  153. func TestDaoQueryRelation(t *testing.T) {
  154. convey.Convey("QueryRelation", t, func(convCtx convey.C) {
  155. var (
  156. groupId = 11
  157. script = &model.Script{
  158. ID: 1568,
  159. }
  160. )
  161. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  162. res, err := d.QueryRelation(groupId, script)
  163. convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
  164. convCtx.So(err, convey.ShouldBeNil)
  165. convCtx.So(res, convey.ShouldNotBeNil)
  166. })
  167. })
  168. })
  169. }
  170. func TestDaoQueryAPI(t *testing.T) {
  171. convey.Convey("QueryAPI", t, func(convCtx convey.C) {
  172. var (
  173. scene = &model.Scene{
  174. ID: 325,
  175. SceneType: 1,
  176. }
  177. )
  178. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  179. res, err := d.QueryAPI(scene)
  180. convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
  181. convCtx.So(err, convey.ShouldBeNil)
  182. convCtx.So(res, convey.ShouldNotBeNil)
  183. })
  184. })
  185. })
  186. }
  187. func TestDaoDeleteAPI(t *testing.T) {
  188. d.DB.Model(&model.Script{}).Where("ID = 1568").Update("active", 1)
  189. convey.Convey("DeleteAPI", t, func(convCtx convey.C) {
  190. var (
  191. script = &model.Script{
  192. ID: 1568,
  193. }
  194. )
  195. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  196. err := d.DeleteAPI(script)
  197. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  198. convCtx.So(err, convey.ShouldBeNil)
  199. })
  200. })
  201. })
  202. }
  203. func TestDaoAddConfig(t *testing.T) {
  204. d.DB.Exec("update script set threads_sum = 10, load_time = 10, ready_time = 10 where scene_id = 325 and group_id = 1")
  205. convey.Convey("AddConfig", t, func(convCtx convey.C) {
  206. var (
  207. script = &model.Script{
  208. ThreadsSum: 120,
  209. LoadTime: 300,
  210. ReadyTime: 10,
  211. SceneID: 325,
  212. GroupID: 1,
  213. }
  214. )
  215. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  216. err := d.AddConfig(script)
  217. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  218. convCtx.So(err, convey.ShouldBeNil)
  219. })
  220. })
  221. })
  222. }
  223. func TestDaoQueryTree(t *testing.T) {
  224. convey.Convey("QueryTree", t, func(convCtx convey.C) {
  225. var (
  226. script = &model.Script{
  227. SceneID: 325,
  228. }
  229. )
  230. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  231. res, err := d.QueryTree(script)
  232. convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
  233. convCtx.So(err, convey.ShouldBeNil)
  234. convCtx.So(res, convey.ShouldNotBeNil)
  235. })
  236. })
  237. })
  238. }
  239. func TestDaoQueryScenesByPage(t *testing.T) {
  240. convey.Convey("QueryScenesByPage", t, func(convCtx convey.C) {
  241. var (
  242. scene = &model.Scene{
  243. Department: "test",
  244. Project: "ep",
  245. APP: "melloi",
  246. SceneName: "场景压测cmtest01",
  247. UserName: "chenmeng",
  248. }
  249. pn = int32(1)
  250. ps = int32(20)
  251. treeNodes = []string{}
  252. )
  253. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  254. qsr, err := d.QueryScenesByPage(scene, pn, ps, treeNodes)
  255. convCtx.Convey("Then err should be nil.qsr should not be nil.", func(convCtx convey.C) {
  256. convCtx.So(err, convey.ShouldBeNil)
  257. convCtx.So(qsr, convey.ShouldNotBeNil)
  258. })
  259. })
  260. })
  261. }
  262. func TestDaoQueryScenesByPageWhiteName(t *testing.T) {
  263. convey.Convey("QueryScenesByPageWhiteName", t, func(convCtx convey.C) {
  264. var (
  265. scene = &model.Scene{
  266. Department: "test",
  267. Project: "ep",
  268. APP: "melloi",
  269. SceneName: "场景压测cmtest01",
  270. UserName: "chenmeng",
  271. }
  272. pn = int32(1)
  273. ps = int32(20)
  274. )
  275. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  276. qsr, err := d.QueryScenesByPageWhiteName(scene, pn, ps)
  277. convCtx.Convey("Then err should be nil.qsr should not be nil.", func(convCtx convey.C) {
  278. convCtx.So(err, convey.ShouldBeNil)
  279. convCtx.So(qsr, convey.ShouldNotBeNil)
  280. })
  281. })
  282. })
  283. }
  284. func TestDaoQueryScenes(t *testing.T) {
  285. convey.Convey("QueryScenes", t, func(convCtx convey.C) {
  286. var (
  287. scene = &model.Scene{
  288. UserName: "chenmeng",
  289. }
  290. pn = 1
  291. ps = 10
  292. )
  293. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  294. scenes, err := d.QueryScenes(scene, pn, ps)
  295. convCtx.Convey("Then err should be nil.scenes should not be nil.", func(convCtx convey.C) {
  296. convCtx.So(err, convey.ShouldBeNil)
  297. convCtx.So(scenes, convey.ShouldNotBeNil)
  298. })
  299. })
  300. })
  301. }
  302. func TestDaoQueryExistAPI(t *testing.T) {
  303. convey.Convey("QueryExistAPI", t, func(convCtx convey.C) {
  304. var (
  305. script = &model.Script{
  306. SceneID: 325,
  307. }
  308. pageNum = int32(1)
  309. pageSize = int32(10)
  310. sceneId = int(325)
  311. treeNodes = []string{}
  312. )
  313. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  314. res, err := d.QueryExistAPI(script, pageNum, pageSize, sceneId, treeNodes)
  315. convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
  316. convCtx.So(err, convey.ShouldBeNil)
  317. convCtx.So(res, convey.ShouldNotBeNil)
  318. })
  319. })
  320. })
  321. }
  322. func TestDaoQueryGroup(t *testing.T) {
  323. convey.Convey("QueryGroup", t, func(convCtx convey.C) {
  324. var (
  325. sceneId = 325
  326. )
  327. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  328. res, err := d.QueryGroup(sceneId)
  329. convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
  330. convCtx.So(err, convey.ShouldBeNil)
  331. convCtx.So(res, convey.ShouldNotBeNil)
  332. })
  333. })
  334. })
  335. }
  336. func TestDaoQueryPreview(t *testing.T) {
  337. convey.Convey("QueryPreview", t, func(convCtx convey.C) {
  338. var (
  339. sceneId = 325
  340. groupId = 1
  341. )
  342. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  343. res, err := d.QueryPreview(sceneId, groupId)
  344. convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
  345. convCtx.So(err, convey.ShouldBeNil)
  346. convCtx.So(res, convey.ShouldNotBeNil)
  347. })
  348. })
  349. })
  350. }
  351. func TestDaoQueryUsefulParams(t *testing.T) {
  352. convey.Convey("QueryUsefulParams", t, func(convCtx convey.C) {
  353. var (
  354. sceneId = 325
  355. )
  356. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  357. res, err := d.QueryUsefulParams(sceneId)
  358. convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
  359. convCtx.So(err, convey.ShouldBeNil)
  360. convCtx.So(res, convey.ShouldNotBeNil)
  361. })
  362. })
  363. })
  364. }
  365. func TestDaoUpdateBindScene(t *testing.T) {
  366. convey.Convey("UpdateBindScene", t, func(convCtx convey.C) {
  367. var (
  368. bindScene = &model.BindScene{
  369. SceneID: 325,
  370. ID: "2000",
  371. }
  372. )
  373. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  374. err := d.UpdateBindScene(bindScene)
  375. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  376. convCtx.So(err, convey.ShouldBeNil)
  377. })
  378. })
  379. })
  380. }
  381. func TestDaoQueryDrawRelation(t *testing.T) {
  382. convey.Convey("QueryDrawRelation", t, func(convCtx convey.C) {
  383. var (
  384. scene = &model.Scene{
  385. ID: 980,
  386. }
  387. )
  388. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  389. res, err := d.QueryDrawRelation(scene)
  390. convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
  391. convCtx.So(err, convey.ShouldBeNil)
  392. convCtx.So(res, convey.ShouldNotBeNil)
  393. })
  394. })
  395. })
  396. }
  397. func TestDaoDeleteDraft(t *testing.T) {
  398. convey.Convey("DeleteDraft", t, func(convCtx convey.C) {
  399. var (
  400. scene = &model.Scene{
  401. UserName: "chenmeng",
  402. ID: 980,
  403. }
  404. )
  405. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  406. err := d.DeleteDraft(scene)
  407. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  408. convCtx.So(err, convey.ShouldBeNil)
  409. })
  410. })
  411. })
  412. }
  413. func TestDaoQueryConfig(t *testing.T) {
  414. convey.Convey("QueryConfig", t, func(convCtx convey.C) {
  415. var (
  416. script = &model.Script{
  417. SceneID: 325,
  418. GroupID: 1,
  419. }
  420. )
  421. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  422. res, err := d.QueryConfig(script)
  423. convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
  424. convCtx.So(err, convey.ShouldBeNil)
  425. convCtx.So(res, convey.ShouldNotBeNil)
  426. })
  427. })
  428. })
  429. }
  430. func TestDaoDeleteScene(t *testing.T) {
  431. convey.Convey("DeleteScene", t, func(convCtx convey.C) {
  432. var (
  433. scene = &model.Scene{
  434. ID: 325,
  435. }
  436. )
  437. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  438. err := d.DeleteScene(scene)
  439. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  440. convCtx.So(err, convey.ShouldBeNil)
  441. })
  442. })
  443. })
  444. }