backsource_test.go 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. package cms
  2. import (
  3. "context"
  4. "fmt"
  5. "testing"
  6. "go-common/app/interface/main/tv/model"
  7. "go-common/library/database/sql"
  8. "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestCmsVideoMetaDB(t *testing.T) {
  11. var (
  12. c = context.Background()
  13. cid = int64(0)
  14. )
  15. convey.Convey("VideoMetaDB", t, func(ctx convey.C) {
  16. ctx.Convey("Then err should be nil.meta should not be nil.", func(ctx convey.C) {
  17. sids, err := pickIDs(d.db, _pickCids)
  18. if err != nil || len(sids) == 0 {
  19. fmt.Println("Empty Sids ", err)
  20. return
  21. }
  22. cid = sids[0]
  23. meta, err := d.VideoMetaDB(c, cid)
  24. ctx.So(err, convey.ShouldBeNil)
  25. ctx.So(meta, convey.ShouldNotBeNil)
  26. })
  27. ctx.Convey("Db Error", func(ctx convey.C) {
  28. d.db.Close()
  29. _, err := d.VideoMetaDB(c, cid)
  30. ctx.So(err, convey.ShouldNotBeNil)
  31. d.db = sql.NewMySQL(d.conf.Mysql)
  32. })
  33. })
  34. }
  35. func TestCmsArcMetaDB(t *testing.T) {
  36. var (
  37. c = context.Background()
  38. aid = int64(0)
  39. )
  40. convey.Convey("ArcMetaDB", t, func(ctx convey.C) {
  41. ctx.Convey("Then err should be nil.meta should not be nil.", func(ctx convey.C) {
  42. sids, err := pickIDs(d.db, _pickAids)
  43. if err != nil || len(sids) == 0 {
  44. fmt.Println("Empty Sids ", err)
  45. return
  46. }
  47. aid = sids[0]
  48. meta, err := d.ArcMetaDB(c, aid)
  49. ctx.So(err, convey.ShouldBeNil)
  50. ctx.So(meta, convey.ShouldNotBeNil)
  51. })
  52. ctx.Convey("Db Error", func(ctx convey.C) {
  53. d.db.Close()
  54. _, err := d.ArcMetaDB(c, aid)
  55. ctx.So(err, convey.ShouldNotBeNil)
  56. d.db = sql.NewMySQL(d.conf.Mysql)
  57. })
  58. })
  59. }
  60. func TestCmsVideoMetas(t *testing.T) {
  61. var (
  62. c = context.Background()
  63. cids = []int64{}
  64. err error
  65. )
  66. convey.Convey("VideoMetas", t, func(ctx convey.C) {
  67. ctx.Convey("Then err should be nil.meta should not be nil.", func(ctx convey.C) {
  68. if cids, err = pickIDs(d.db, _pickCids); err != nil || len(cids) == 0 {
  69. fmt.Println("Empty Sids ", err)
  70. return
  71. }
  72. meta, err := d.VideoMetas(c, cids)
  73. ctx.So(err, convey.ShouldBeNil)
  74. ctx.So(meta, convey.ShouldNotBeNil)
  75. })
  76. ctx.Convey("Db Error", func(ctx convey.C) {
  77. d.db.Close()
  78. _, err := d.VideoMetas(c, cids)
  79. ctx.So(err, convey.ShouldNotBeNil)
  80. d.db = sql.NewMySQL(d.conf.Mysql)
  81. })
  82. })
  83. }
  84. func TestCmsArcMetas(t *testing.T) {
  85. var (
  86. c = context.Background()
  87. aids = []int64{}
  88. err error
  89. )
  90. convey.Convey("ArcMetas", t, func(ctx convey.C) {
  91. ctx.Convey("Then err should be nil.metas should not be nil.", func(ctx convey.C) {
  92. if aids, err = pickIDs(d.db, _pickAids); err != nil || len(aids) == 0 {
  93. fmt.Println("Empty Sids ", err)
  94. return
  95. }
  96. metas, err := d.ArcMetas(c, aids)
  97. ctx.So(err, convey.ShouldBeNil)
  98. ctx.So(metas, convey.ShouldNotBeNil)
  99. })
  100. ctx.Convey("Db Error", func(ctx convey.C) {
  101. d.db.Close()
  102. _, err := d.ArcMetas(c, aids)
  103. ctx.So(err, convey.ShouldNotBeNil)
  104. d.db = sql.NewMySQL(d.conf.Mysql)
  105. })
  106. })
  107. }
  108. func TestCmsSeasonMetas(t *testing.T) {
  109. var (
  110. c = context.Background()
  111. sids = []int64{}
  112. err error
  113. )
  114. convey.Convey("SeasonMetas", t, func(ctx convey.C) {
  115. ctx.Convey("Then err should be nil.metas should not be nil.", func(ctx convey.C) {
  116. if sids, err = pickIDs(d.db, _pickSids); err != nil || len(sids) == 0 {
  117. fmt.Println("Empty Sids ", err)
  118. return
  119. }
  120. metas, err := d.SeasonMetas(c, sids)
  121. ctx.So(err, convey.ShouldBeNil)
  122. ctx.So(metas, convey.ShouldNotBeNil)
  123. })
  124. ctx.Convey("Db Error", func(ctx convey.C) {
  125. d.db.Close()
  126. _, err := d.SeasonMetas(c, sids)
  127. ctx.So(err, convey.ShouldNotBeNil)
  128. d.db = sql.NewMySQL(d.conf.Mysql)
  129. })
  130. })
  131. }
  132. func TestCmsNewestOrder(t *testing.T) {
  133. var (
  134. c = context.Background()
  135. sid = int64(0)
  136. )
  137. convey.Convey("NewestOrder", t, func(ctx convey.C) {
  138. ctx.Convey("Then err should be nil.epid,newestOrder should not be nil.", func(ctx convey.C) {
  139. epid, newestOrder, err := d.NewestOrder(c, sid)
  140. if err != nil {
  141. ctx.So(err, convey.ShouldEqual, sql.ErrNoRows)
  142. } else {
  143. ctx.So(err, convey.ShouldBeNil)
  144. ctx.So(newestOrder, convey.ShouldNotBeNil)
  145. ctx.So(epid, convey.ShouldNotBeNil)
  146. }
  147. })
  148. })
  149. }
  150. func TestCmsEpMetas(t *testing.T) {
  151. var (
  152. c = context.Background()
  153. epids = []int64{}
  154. err error
  155. )
  156. convey.Convey("EpMetas", t, func(ctx convey.C) {
  157. ctx.Convey("Then err should be nil.metas should not be nil.", func(ctx convey.C) {
  158. if epids, err = pickIDs(d.db, _pickEpids); err != nil || len(epids) == 0 {
  159. fmt.Println("Empty epids ", err)
  160. return
  161. }
  162. metas, err := d.EpMetas(c, epids)
  163. ctx.So(err, convey.ShouldBeNil)
  164. ctx.So(metas, convey.ShouldNotBeNil)
  165. })
  166. ctx.Convey("Db Error", func(ctx convey.C) {
  167. d.db.Close()
  168. _, err := d.EpMetas(c, epids)
  169. ctx.So(err, convey.ShouldNotBeNil)
  170. d.db = sql.NewMySQL(d.conf.Mysql)
  171. })
  172. })
  173. }
  174. func TestCmsEpAuthDB(t *testing.T) {
  175. var (
  176. c = context.Background()
  177. epid = int64(0)
  178. )
  179. convey.Convey("EpAuthDB", t, func(ctx convey.C) {
  180. ctx.Convey("Then err should be nil.ep should not be nil.", func(ctx convey.C) {
  181. epids, err := pickIDs(d.db, _pickEpids)
  182. if err != nil || len(epids) == 0 {
  183. fmt.Println("Empty epids ", err)
  184. return
  185. }
  186. epid = epids[0]
  187. ep, err := d.EpAuthDB(c, epid)
  188. ctx.So(err, convey.ShouldBeNil)
  189. ctx.So(ep, convey.ShouldNotBeNil)
  190. })
  191. ctx.Convey("Db Error", func(ctx convey.C) {
  192. d.db.Close()
  193. _, err := d.EpAuthDB(c, epid)
  194. ctx.So(err, convey.ShouldNotBeNil)
  195. d.db = sql.NewMySQL(d.conf.Mysql)
  196. })
  197. })
  198. }
  199. func TestCmsSnAuthDB(t *testing.T) {
  200. var (
  201. c = context.Background()
  202. sids []int64
  203. sid int64
  204. err error
  205. )
  206. convey.Convey("SnAuthDB", t, func(ctx convey.C) {
  207. ctx.Convey("Then err should be nil.s should not be nil.", func(ctx convey.C) {
  208. if sids, err = pickIDs(d.db, _pickSids); err != nil || len(sids) == 0 {
  209. fmt.Println("Empty Sids ", err)
  210. return
  211. }
  212. sid = sids[0]
  213. s, err := d.SnAuthDB(c, sid)
  214. ctx.So(err, convey.ShouldBeNil)
  215. ctx.So(s, convey.ShouldNotBeNil)
  216. })
  217. ctx.Convey("Db Error", func(ctx convey.C) {
  218. d.db.Close()
  219. _, err := d.SnAuthDB(c, sid)
  220. ctx.So(err, convey.ShouldNotBeNil)
  221. d.db = sql.NewMySQL(d.conf.Mysql)
  222. })
  223. })
  224. }
  225. func TestCmsSnsAuthDB(t *testing.T) {
  226. var (
  227. c = context.Background()
  228. sids []int64
  229. err error
  230. snsAuth map[int64]*model.SnAuth
  231. )
  232. convey.Convey("SnsAuthDB", t, func(ctx convey.C) {
  233. ctx.Convey("Then err should be nil.snsAuth should not be nil.", func(ctx convey.C) {
  234. if sids, err = pickIDs(d.db, _pickSids); err != nil || len(sids) == 0 {
  235. fmt.Println("Empty Sids ", err)
  236. return
  237. }
  238. snsAuth, err = d.SnsAuthDB(c, sids)
  239. ctx.So(err, convey.ShouldBeNil)
  240. ctx.So(snsAuth, convey.ShouldNotBeNil)
  241. })
  242. ctx.Convey("Db Error", func(ctx convey.C) {
  243. d.db.Close()
  244. _, err = d.SnsAuthDB(c, sids)
  245. ctx.So(err, convey.ShouldNotBeNil)
  246. d.db = sql.NewMySQL(d.conf.Mysql)
  247. })
  248. })
  249. }
  250. func TestCmsEpsAuthDB(t *testing.T) {
  251. var (
  252. c = context.Background()
  253. epids []int64
  254. err error
  255. epsAuth map[int64]*model.EpAuth
  256. )
  257. convey.Convey("EpsAuthDB", t, func(ctx convey.C) {
  258. ctx.Convey("Then err should be nil.epsAuth should not be nil.", func(ctx convey.C) {
  259. epids, err = pickIDs(d.db, _pickEpids)
  260. if err != nil || len(epids) == 0 {
  261. fmt.Println("Empty epids ", err)
  262. return
  263. }
  264. epsAuth, err = d.EpsAuthDB(c, epids)
  265. ctx.So(err, convey.ShouldBeNil)
  266. ctx.So(epsAuth, convey.ShouldNotBeNil)
  267. })
  268. ctx.Convey("Db Error", func(ctx convey.C) {
  269. d.db.Close()
  270. _, err = d.EpsAuthDB(c, epids)
  271. ctx.So(err, convey.ShouldNotBeNil)
  272. d.db = sql.NewMySQL(d.conf.Mysql)
  273. })
  274. })
  275. }
  276. func TestCmsSeasonCMS(t *testing.T) {
  277. var (
  278. c = context.Background()
  279. sids []int64
  280. sid = int64(0)
  281. err error
  282. season *model.SeasonCMS
  283. )
  284. convey.Convey("SeasonCMS", t, func(ctx convey.C) {
  285. ctx.Convey("Then err should be nil.season should not be nil.", func(ctx convey.C) {
  286. sids, err = pickIDs(d.db, _pickSids)
  287. if err != nil || len(sids) == 0 {
  288. fmt.Println("Empty Sids ", err)
  289. return
  290. }
  291. sid = sids[0]
  292. season, err = d.SeasonCMS(c, sid)
  293. ctx.So(err, convey.ShouldBeNil)
  294. ctx.So(season, convey.ShouldNotBeNil)
  295. })
  296. ctx.Convey("Db Error", func(ctx convey.C) {
  297. d.db.Close()
  298. _, err = d.SeasonCMS(c, sid)
  299. ctx.So(err, convey.ShouldNotBeNil)
  300. d.db = sql.NewMySQL(d.conf.Mysql)
  301. })
  302. })
  303. }
  304. func TestCmsEpCMS(t *testing.T) {
  305. var (
  306. c = context.Background()
  307. epid = int64(0)
  308. )
  309. convey.Convey("EpCMS", t, func(ctx convey.C) {
  310. ctx.Convey("Then err should be nil.ep should not be nil.", func(ctx convey.C) {
  311. epids, err := pickIDs(d.db, _pickEpids)
  312. if err != nil || len(epids) == 0 {
  313. fmt.Println("Empty epids ", err)
  314. return
  315. }
  316. epid = epids[0]
  317. ep, err := d.EpCMS(c, epid)
  318. ctx.So(err, convey.ShouldBeNil)
  319. ctx.So(ep, convey.ShouldNotBeNil)
  320. })
  321. ctx.Convey("Db Error", func(ctx convey.C) {
  322. d.db.Close()
  323. _, err := d.EpCMS(c, epid)
  324. ctx.So(err, convey.ShouldNotBeNil)
  325. d.db = sql.NewMySQL(d.conf.Mysql)
  326. })
  327. })
  328. }