archive_test.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. package archive
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "database/sql"
  7. "fmt"
  8. "go-common/app/service/main/videoup/model/archive"
  9. xsql "go-common/library/database/sql"
  10. "reflect"
  11. "github.com/bouk/monkey"
  12. . "github.com/smartystreets/goconvey/convey"
  13. )
  14. func TestDao_TxAddArchive(t *testing.T) {
  15. var (
  16. c = context.Background()
  17. tx, _ = d.BeginTran(c)
  18. a = &archive.Archive{
  19. Mid: 123,
  20. TypeID: 22,
  21. Title: "UT测试",
  22. Author: "ut",
  23. Desc: "UT测试UT测试",
  24. }
  25. )
  26. Convey("TxUpArchiveState", t, func(ctx C) {
  27. _, err := d.TxAddArchive(tx, a)
  28. if err != nil {
  29. tx.Rollback()
  30. } else {
  31. tx.Commit()
  32. }
  33. So(err, ShouldBeNil)
  34. })
  35. }
  36. func TestDao_TxAUpArchive(t *testing.T) {
  37. var (
  38. c = context.Background()
  39. tx, _ = d.BeginTran(c)
  40. a = &archive.Archive{
  41. Aid: 10111210,
  42. Mid: 123,
  43. TypeID: 22,
  44. Title: "UT测试",
  45. Author: "ut",
  46. Desc: "UT测试UT测试",
  47. }
  48. )
  49. Convey("TxUpArchiveState", t, func(ctx C) {
  50. _, err := d.TxUpArchive(tx, a)
  51. if err != nil {
  52. tx.Rollback()
  53. } else {
  54. tx.Commit()
  55. }
  56. So(err, ShouldBeNil)
  57. })
  58. }
  59. func TestDao_TxAUpArchiveMid(t *testing.T) {
  60. var (
  61. c = context.Background()
  62. tx, _ = d.BeginTran(c)
  63. a = &archive.Archive{
  64. Aid: 10111210,
  65. Mid: 123,
  66. TypeID: 22,
  67. Title: "UT测试",
  68. Author: "ut",
  69. Desc: "UT测试UT测试",
  70. }
  71. )
  72. Convey("TxUpArchiveState", t, func(ctx C) {
  73. _, err := d.TxUpArchiveMid(tx, a)
  74. if err != nil {
  75. tx.Rollback()
  76. } else {
  77. tx.Commit()
  78. }
  79. So(err, ShouldBeNil)
  80. })
  81. }
  82. func TestArchiveTxUpArchiveState(t *testing.T) {
  83. var (
  84. c = context.Background()
  85. tx, _ = d.BeginTran(c)
  86. aid = int64(233333)
  87. state = int8(0)
  88. )
  89. Convey("TxUpArchiveState", t, func(ctx C) {
  90. _, err := d.TxUpArchiveState(tx, aid, state)
  91. if err != nil {
  92. tx.Rollback()
  93. } else {
  94. tx.Commit()
  95. }
  96. So(err, ShouldBeNil)
  97. })
  98. }
  99. func TestDao_TxUpAddit(t *testing.T) {
  100. var (
  101. c = context.Background()
  102. tx, _ = d.BeginTran(c)
  103. aid = int64(233333)
  104. )
  105. Convey("TxUpAddit", t, func(ctx C) {
  106. _, err := d.TxUpAddit(tx, aid, 0, 0, 0, 0, []byte{}, "", "", "", "", "", 0)
  107. if err != nil {
  108. tx.Rollback()
  109. } else {
  110. tx.Commit()
  111. }
  112. So(err, ShouldBeNil)
  113. })
  114. }
  115. func TestDao_TxUpArchiveBiz(t *testing.T) {
  116. var (
  117. c = context.Background()
  118. tx, _ = d.BeginTran(c)
  119. aid = int64(233333)
  120. )
  121. Convey("TxUpArchiveBiz", t, func(ctx C) {
  122. _, err := d.TxUpArchiveBiz(tx, aid, 0, "")
  123. if err != nil {
  124. tx.Rollback()
  125. } else {
  126. tx.Commit()
  127. }
  128. So(err, ShouldBeNil)
  129. })
  130. }
  131. func TestDao_TxUpAdditReason(t *testing.T) {
  132. var (
  133. c = context.Background()
  134. tx, _ = d.BeginTran(c)
  135. aid = int64(233333)
  136. )
  137. Convey("TxUpAdditReason", t, func(ctx C) {
  138. _, err := d.TxUpAdditReason(tx, aid, "")
  139. if err != nil {
  140. tx.Rollback()
  141. } else {
  142. tx.Commit()
  143. }
  144. So(err, ShouldBeNil)
  145. })
  146. }
  147. func TestDao_TxUpAdditRedirect(t *testing.T) {
  148. var (
  149. c = context.Background()
  150. tx, _ = d.BeginTran(c)
  151. aid = int64(233333)
  152. )
  153. Convey("TxUpAdditRedirect", t, func(ctx C) {
  154. _, err := d.TxUpAdditRedirect(tx, aid, "")
  155. if err != nil {
  156. tx.Rollback()
  157. } else {
  158. tx.Commit()
  159. }
  160. So(err, ShouldBeNil)
  161. })
  162. }
  163. // func TestArchiveTxUpAdditReason(t *testing.T) {
  164. // var (
  165. // c = context.Background()
  166. // tx, _ = d.BeginTran(c)
  167. // aid = int64(233333)
  168. // reason = "2333"
  169. // )
  170. // Convey("TxUpAdditReason", t, func(ctx C) {
  171. // rows, err := d.TxUpAdditReason(tx, aid, reason)
  172. // ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx C) {
  173. // ctx.So(err, ShouldBeNil)
  174. // ctx.So(rows, ShouldNotBeNil)
  175. // })
  176. // })
  177. // }
  178. func TestArchiveTxUpAdditRedirect(t *testing.T) {
  179. var (
  180. c = context.Background()
  181. tx, _ = d.BeginTran(c)
  182. aid = int64(0)
  183. redirectURL = "233333"
  184. )
  185. Convey("TxUpAdditRedirect", t, func(ctx C) {
  186. rows, err := d.TxUpAdditRedirect(tx, aid, redirectURL)
  187. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx C) {
  188. ctx.So(err, ShouldBeNil)
  189. ctx.So(rows, ShouldNotBeNil)
  190. })
  191. })
  192. }
  193. func TestArchiveTxUpArcAttr(t *testing.T) {
  194. var (
  195. c = context.Background()
  196. tx, _ = d.BeginTran(c)
  197. aid = int64(0)
  198. bit = uint(0)
  199. val = int32(0)
  200. )
  201. Convey("TxUpArcAttr", t, func(ctx C) {
  202. rows, err := d.TxUpArcAttr(tx, aid, bit, val)
  203. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx C) {
  204. ctx.So(err, ShouldBeNil)
  205. ctx.So(rows, ShouldNotBeNil)
  206. })
  207. })
  208. }
  209. func TestArchiveTxUpTag(t *testing.T) {
  210. var (
  211. c = context.Background()
  212. tx, _ = d.BeginTran(c)
  213. aid = int64(22333)
  214. tag = "2333"
  215. )
  216. Convey("TxUpTag", t, func(ctx C) {
  217. rows, err := d.TxUpTag(tx, aid, tag)
  218. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx C) {
  219. ctx.So(err, ShouldBeNil)
  220. ctx.So(rows, ShouldNotBeNil)
  221. })
  222. })
  223. }
  224. func TestArchiveArchive(t *testing.T) {
  225. var (
  226. c = context.Background()
  227. aid = int64(22333)
  228. )
  229. Convey("Archive", t, func(ctx C) {
  230. _, err := d.Archive(c, aid)
  231. ctx.Convey("Then err should be nil.a should not be nil.", func(ctx C) {
  232. ctx.So(err, ShouldBeNil)
  233. })
  234. })
  235. }
  236. func TestArchiveAddit(t *testing.T) {
  237. var (
  238. c = context.Background()
  239. aid = int64(22333)
  240. aa = &archive.ArcMissionParam{}
  241. )
  242. Convey("Addit", t, func(ctx C) {
  243. _, err := d.Addit(c, aid)
  244. ctx.Convey("Then err should be nil.ad should not be nil.", func(ctx C) {
  245. ctx.So(err, ShouldBeNil)
  246. })
  247. })
  248. Convey("Vote", t, func(ctx C) {
  249. ad, err := d.Vote(c, aid)
  250. ctx.Convey("Then err should be nil.ad should not be nil.", func(ctx C) {
  251. ctx.So(err, ShouldBeNil)
  252. ctx.So(ad, ShouldBeNil)
  253. })
  254. })
  255. Convey("Recos", t, func(ctx C) {
  256. ad, err := d.Recos(c, aid)
  257. ctx.Convey("Then err should be nil.ad should not be nil.", func(ctx C) {
  258. ctx.So(err, ShouldBeNil)
  259. ctx.So(ad, ShouldBeNil)
  260. })
  261. })
  262. Convey("UpMissionID", t, func(ctx C) {
  263. guard := monkey.PatchInstanceMethod(reflect.TypeOf(d.db), "Exec", func(_ *xsql.DB, _ context.Context, _ string, _ ...interface{}) (sql.Result, error) {
  264. return nil, sql.ErrNoRows
  265. })
  266. defer guard.Unpatch()
  267. ad, err := d.UpMissionID(c, aa)
  268. ctx.Convey("Then err should be nil.ad should not be nil.", func(ctx C) {
  269. ctx.So(err, ShouldNotBeNil)
  270. ctx.So(ad, ShouldBeZeroValue)
  271. })
  272. })
  273. }
  274. func TestArchiveMids(t *testing.T) {
  275. var (
  276. c = context.Background()
  277. aids = []int64{222}
  278. )
  279. Convey("Mids", t, func(ctx C) {
  280. mm, err := d.Mids(c, aids)
  281. ctx.Convey("Then err should be nil.mm should not be nil.", func(ctx C) {
  282. ctx.So(err, ShouldBeNil)
  283. ctx.So(mm, ShouldNotBeNil)
  284. })
  285. })
  286. }
  287. func TestArchiveArchivesUpAll(t *testing.T) {
  288. var (
  289. c = context.Background()
  290. mid = int64(223345)
  291. offset = int(20)
  292. ps = int(1)
  293. )
  294. Convey("ArchivesUpAll", t, func(ctx C) {
  295. _, err := d.ArchivesUpAll(c, mid, offset, ps)
  296. ctx.Convey("Then err should be nil.aids should not be nil.", func(ctx C) {
  297. ctx.So(err, ShouldBeNil)
  298. })
  299. })
  300. }
  301. func TestArchiveArchivesUpOpen(t *testing.T) {
  302. var (
  303. c = context.Background()
  304. mid = int64(223345)
  305. offset = int(20)
  306. ps = int(1)
  307. )
  308. Convey("ArchivesUpOpen", t, func(ctx C) {
  309. _, err := d.ArchivesUpOpen(c, mid, offset, ps)
  310. ctx.Convey("Then err should be nil.aids should not be nil.", func(ctx C) {
  311. ctx.So(err, ShouldBeNil)
  312. })
  313. })
  314. }
  315. func TestArchiveArchivesUpUnOpen(t *testing.T) {
  316. var (
  317. c = context.Background()
  318. mid = int64(223345)
  319. offset = int(20)
  320. ps = int(1)
  321. )
  322. Convey("ArchivesUpUnOpen", t, func(ctx C) {
  323. _, err := d.ArchivesUpUnOpen(c, mid, offset, ps)
  324. ctx.Convey("Then err should be nil.aids should not be nil.", func(ctx C) {
  325. ctx.So(err, ShouldBeNil)
  326. })
  327. })
  328. }
  329. func TestArchiveArchiveAllUpCount(t *testing.T) {
  330. var (
  331. c = context.Background()
  332. mid = int64(223345)
  333. )
  334. Convey("ArchiveAllUpCount", t, func(ctx C) {
  335. count, err := d.ArchiveAllUpCount(c, mid)
  336. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx C) {
  337. ctx.So(err, ShouldBeNil)
  338. ctx.So(count, ShouldNotBeNil)
  339. })
  340. })
  341. }
  342. func TestArchiveArchiveOpenUpCount(t *testing.T) {
  343. var (
  344. c = context.Background()
  345. mid = int64(223345)
  346. )
  347. Convey("ArchiveOpenUpCount", t, func(ctx C) {
  348. count, err := d.ArchiveOpenUpCount(c, mid)
  349. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx C) {
  350. ctx.So(err, ShouldBeNil)
  351. ctx.So(count, ShouldNotBeNil)
  352. })
  353. })
  354. }
  355. func TestArchiveArchiveUnOpenUpCount(t *testing.T) {
  356. var (
  357. c = context.Background()
  358. mid = int64(223345)
  359. )
  360. Convey("ArchiveUnOpenUpCount", t, func(ctx C) {
  361. count, err := d.ArchiveUnOpenUpCount(c, mid)
  362. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx C) {
  363. ctx.So(err, ShouldBeNil)
  364. ctx.So(count, ShouldNotBeNil)
  365. })
  366. })
  367. }
  368. func TestArchiveSimpleArchive(t *testing.T) {
  369. var (
  370. c = context.Background()
  371. aid = int64(222)
  372. )
  373. Convey("SimpleArchive", t, func(ctx C) {
  374. _, err := d.SimpleArchive(c, aid)
  375. ctx.Convey("Then err should be nil.a should not be nil.", func(ctx C) {
  376. ctx.So(err, ShouldBeNil)
  377. })
  378. })
  379. }
  380. func TestArchivePOI(t *testing.T) {
  381. var (
  382. c = context.Background()
  383. aid = int64(222)
  384. )
  385. Convey("poi", t, func(ctx C) {
  386. data, err := d.POI(c, aid)
  387. fmt.Println(string(data))
  388. ctx.Convey("Then err should be nil.a should not be nil.", func(ctx C) {
  389. ctx.So(err, ShouldBeNil)
  390. })
  391. })
  392. }
  393. func TestArchivePOIAdd(t *testing.T) {
  394. var (
  395. c = context.Background()
  396. aid = int64(222)
  397. tx, _ = d.BeginTran(c)
  398. err error
  399. )
  400. Convey("add poi err", t, func(ctx C) {
  401. guard := monkey.PatchInstanceMethod(reflect.TypeOf(tx),
  402. "Exec",
  403. func(_ *xsql.Tx, _ string, _ ...interface{}) (sql.Result, error) {
  404. return nil, fmt.Errorf("tx.Exec error")
  405. })
  406. defer guard.Unpatch()
  407. _, err = d.TxUpArchiveBiz(tx, aid, 1, "2222")
  408. ctx.Convey("TestArchivePOIAdd.", func(ctx C) {
  409. ctx.So(err, ShouldNotBeNil)
  410. })
  411. })
  412. }
  413. func TestArchiverejectedArchives(t *testing.T) {
  414. Convey("rejectedArchives", t, func(ctx C) {
  415. var (
  416. c = context.Background()
  417. mid int64 = 2089809
  418. state int32 = -4
  419. offset int32
  420. limit int32 = 20
  421. start, _ = time.Parse("20060102", "20100101")
  422. )
  423. ctx.Convey("When everything gose positive", func(ctx C) {
  424. arcs, count, err := d.RejectedArchives(c, mid, state, offset, limit, &start)
  425. ctx.Convey("Then err should be nil.arcs should not be nil.", func(ctx C) {
  426. ctx.So(err, ShouldBeNil)
  427. ctx.So(arcs, ShouldNotBeNil)
  428. ShouldNotEqual(count, 0)
  429. })
  430. })
  431. ctx.Convey("When no rows found", func(ctx C) {
  432. guard := monkey.PatchInstanceMethod(reflect.TypeOf(d.slaveDB), "Query", func(_ *xsql.DB, _ context.Context, _ string, _ ...interface{}) (*xsql.Rows, error) {
  433. return nil, xsql.ErrNoRows
  434. })
  435. defer guard.Unpatch()
  436. arcs, _, err := d.RejectedArchives(c, mid, state, offset, limit, &start)
  437. ctx.Convey("Then err should be nil.arcs should not be nil.", func(ctx C) {
  438. ctx.So(err, ShouldNotBeNil)
  439. ctx.So(arcs, ShouldBeNil)
  440. })
  441. })
  442. })
  443. }