shelve_test.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package cms
  2. import (
  3. "context"
  4. "fmt"
  5. "testing"
  6. "go-common/library/database/sql"
  7. "github.com/smartystreets/goconvey/convey"
  8. )
  9. func TestCmsValidSns(t *testing.T) {
  10. var (
  11. ctx = context.Background()
  12. )
  13. convey.Convey("ValidSns", t, func(cx convey.C) {
  14. res, err := d.ValidSns(ctx, false)
  15. cx.Convey("Consider Audited, Then err should be nil.res should not be nil.", func(ctx convey.C) {
  16. ctx.So(err, convey.ShouldBeNil)
  17. ctx.So(res, convey.ShouldNotBeNil)
  18. fmt.Println(len(res))
  19. })
  20. res, err = d.ValidSns(ctx, true)
  21. cx.Convey("Consider Audited and Free, Then err should be nil.res should not be nil.", func(ctx convey.C) {
  22. ctx.So(err, convey.ShouldBeNil)
  23. ctx.So(res, convey.ShouldNotBeNil)
  24. fmt.Println(len(res))
  25. })
  26. })
  27. }
  28. func TestCmsShelveOp(t *testing.T) {
  29. var (
  30. ctx = context.Background()
  31. validSns, _ = d.ValidSns(ctx, true)
  32. )
  33. convey.Convey("ShelveOp", t, func(cx convey.C) {
  34. onIDs, offIDs, err := d.ShelveOp(ctx, validSns)
  35. cx.Convey("Then err should be nil.onIDs,offIDs should not be nil.", func(ctx convey.C) {
  36. ctx.So(err, convey.ShouldBeNil)
  37. ctx.So(offIDs, convey.ShouldNotBeNil)
  38. ctx.So(onIDs, convey.ShouldNotBeNil)
  39. fmt.Println(offIDs)
  40. fmt.Println(onIDs)
  41. })
  42. })
  43. }
  44. func TestCmsActOps(t *testing.T) {
  45. var (
  46. ctx = context.Background()
  47. sid int64
  48. )
  49. d.DB.QueryRow(ctx, "SELECT id FROM tv_ep_season WHERE valid = 1 and is_deleted = 0 AND `check` = 1 LIMIT 1").Scan(&sid)
  50. convey.Convey("ActOps", t, func(cx convey.C) {
  51. err := d.ActOps(ctx, []int64{sid}, false)
  52. cx.Convey("Action 0 Then err should be nil.", func(ctx convey.C) {
  53. ctx.So(err, convey.ShouldBeNil)
  54. })
  55. err = d.ActOps(ctx, []int64{sid}, true)
  56. cx.Convey("Action 1 Then err should be nil.", func(ctx convey.C) {
  57. ctx.So(err, convey.ShouldBeNil)
  58. })
  59. fmt.Println(sid)
  60. })
  61. }
  62. func TestCmsOffArcs(t *testing.T) {
  63. var (
  64. ctx = context.Background()
  65. aid int64
  66. )
  67. convey.Convey("OffArcs", t, func(cx convey.C) {
  68. cx.Convey("Then err should be nil.offAids should not be nil.", func(cx convey.C) {
  69. if err := d.DB.QueryRow(ctx, "select aid from ugc_archive where deleted = 0 and valid = 0 and result = 1 limit 1").Scan(&aid); err != nil {
  70. offAids, err := d.OffArcs(context.Background(), []int64{1, 2, 3})
  71. cx.So(err, convey.ShouldBeNil)
  72. cx.So(offAids, convey.ShouldBeNil)
  73. } else {
  74. fmt.Println("Have Aid ", aid)
  75. offAids, err := d.OffArcs(context.Background(), []int64{1, 2, 3, aid})
  76. cx.So(err, convey.ShouldBeNil)
  77. cx.So(offAids, convey.ShouldNotBeNil)
  78. }
  79. })
  80. cx.Convey("Arg Error", func(cx convey.C) {
  81. _, err := d.OffArcs(context.Background(), []int64{})
  82. cx.So(err, convey.ShouldNotBeNil)
  83. })
  84. cx.Convey("DB Error", func(cx convey.C) {
  85. d.DB.Close()
  86. _, err := d.OffArcs(context.Background(), []int64{1, 2, 3})
  87. cx.So(err, convey.ShouldNotBeNil)
  88. d.DB = sql.NewMySQL(d.conf.Mysql)
  89. })
  90. })
  91. }
  92. func TestCmsReshelfArcs(t *testing.T) {
  93. convey.Convey("OffArcs", t, func(cx convey.C) {
  94. cx.Convey("Then err should be nil.offAids should not be nil.", func(cx convey.C) {
  95. err := d.ReshelfArcs(context.Background(), []int64{1, 2, 3})
  96. cx.So(err, convey.ShouldBeNil)
  97. })
  98. cx.Convey("Arg Error", func(cx convey.C) {
  99. err := d.ReshelfArcs(context.Background(), []int64{})
  100. cx.So(err, convey.ShouldNotBeNil)
  101. })
  102. cx.Convey("DB Error", func(cx convey.C) {
  103. d.DB.Close()
  104. err := d.ReshelfArcs(context.Background(), []int64{1, 2, 3})
  105. cx.So(err, convey.ShouldNotBeNil)
  106. d.DB = sql.NewMySQL(d.conf.Mysql)
  107. })
  108. })
  109. }