report_test.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package archive
  2. import (
  3. "context"
  4. "database/sql"
  5. "fmt"
  6. "go-common/app/service/main/videoup/model/archive"
  7. xsql "go-common/library/database/sql"
  8. "go-common/library/time"
  9. "reflect"
  10. "testing"
  11. "github.com/bouk/monkey"
  12. "github.com/smartystreets/goconvey/convey"
  13. )
  14. func TestArchiveArcReport(t *testing.T) {
  15. var (
  16. c = context.Background()
  17. aid = int64(2333)
  18. mid = int64(23333)
  19. )
  20. convey.Convey("ArcReport", t, func(ctx convey.C) {
  21. _, err := d.ArcReport(c, aid, mid)
  22. ctx.Convey("Then err should be nil.aa should not be nil.", func(ctx convey.C) {
  23. ctx.So(err, convey.ShouldBeNil)
  24. })
  25. })
  26. }
  27. func TestTxAddRelation(t *testing.T) {
  28. var (
  29. c = context.Background()
  30. err error
  31. tx, _ = d.BeginTran(c)
  32. v = &archive.Video{
  33. Aid: int64(10110817),
  34. Cid: int64(10134702),
  35. Title: "iamtitle",
  36. Index: 1,
  37. }
  38. )
  39. convey.Convey("TestTxAddRelation", t, func(ctx convey.C) {
  40. guard := monkey.PatchInstanceMethod(reflect.TypeOf(tx),
  41. "Exec",
  42. func(_ *xsql.Tx, _ string, _ ...interface{}) (sql.Result, error) {
  43. return nil, fmt.Errorf("tx.Exec error")
  44. })
  45. defer guard.Unpatch()
  46. _, err = d.TxAddRelation(tx, v)
  47. ctx.Convey("TestArchivePOIAdd.", func(ctx convey.C) {
  48. ctx.So(err, convey.ShouldNotBeNil)
  49. })
  50. })
  51. }
  52. func TestTxUpForbid(t *testing.T) {
  53. var (
  54. c = context.Background()
  55. err error
  56. aid = int64(10110817)
  57. fid = int64(1)
  58. tx, _ = d.BeginTran(c)
  59. )
  60. convey.Convey("TestTxUpForbid", t, func(ctx convey.C) {
  61. guard := monkey.PatchInstanceMethod(reflect.TypeOf(tx),
  62. "Exec",
  63. func(_ *xsql.Tx, _ string, _ ...interface{}) (sql.Result, error) {
  64. return nil, fmt.Errorf("tx.Exec error")
  65. })
  66. defer guard.Unpatch()
  67. _, err = d.TxUpForbid(tx, aid, fid)
  68. ctx.Convey("TxUpForbid.", func(ctx convey.C) {
  69. ctx.So(err, convey.ShouldNotBeNil)
  70. })
  71. })
  72. }
  73. func TestTxUpForbidAttr(t *testing.T) {
  74. var (
  75. c = context.Background()
  76. err error
  77. tx, _ = d.BeginTran(c)
  78. af = &archive.ForbidAttr{}
  79. )
  80. convey.Convey("TestTxUpForbidAttr", t, func(ctx convey.C) {
  81. guard := monkey.PatchInstanceMethod(reflect.TypeOf(tx),
  82. "Exec",
  83. func(_ *xsql.Tx, _ string, _ ...interface{}) (sql.Result, error) {
  84. return nil, fmt.Errorf("tx.Exec error")
  85. })
  86. defer guard.Unpatch()
  87. _, err = d.TxUpForbidAttr(tx, af)
  88. ctx.Convey("TxUpForbidAttr.", func(ctx convey.C) {
  89. ctx.So(err, convey.ShouldNotBeNil)
  90. })
  91. })
  92. }
  93. func TestTxAddDelay(t *testing.T) {
  94. var (
  95. c = context.Background()
  96. err error
  97. tx, _ = d.BeginTran(c)
  98. aid = int64(2333)
  99. mid = int64(23333)
  100. state = int8(1)
  101. tp = int8(2)
  102. dtime time.Time
  103. )
  104. convey.Convey("TestTxAddDelay", t, func(ctx convey.C) {
  105. guard := monkey.PatchInstanceMethod(reflect.TypeOf(tx),
  106. "Exec",
  107. func(_ *xsql.Tx, _ string, _ ...interface{}) (sql.Result, error) {
  108. return nil, fmt.Errorf("tx.Exec error")
  109. })
  110. defer guard.Unpatch()
  111. _, err = d.TxAddDelay(tx, mid, aid, state, tp, dtime)
  112. ctx.Convey("TxAddDelay.", func(ctx convey.C) {
  113. ctx.So(err, convey.ShouldNotBeNil)
  114. })
  115. })
  116. }