material_test.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package material
  2. import (
  3. "context"
  4. "fmt"
  5. xsql "go-common/library/database/sql"
  6. "reflect"
  7. "testing"
  8. "github.com/bouk/monkey"
  9. "github.com/smartystreets/goconvey/convey"
  10. )
  11. func TestFilterCategoryBind(t *testing.T) {
  12. var (
  13. c = context.TODO()
  14. tp = int8(7)
  15. )
  16. convey.Convey("CategoryBind", t, func(ctx convey.C) {
  17. res, err := d.CategoryBind(c, tp)
  18. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  19. ctx.So(err, convey.ShouldBeNil)
  20. ctx.So(res, convey.ShouldNotBeNil)
  21. })
  22. })
  23. }
  24. func TestMaterialSubtitles(t *testing.T) {
  25. var (
  26. c = context.TODO()
  27. )
  28. convey.Convey("Subtitles", t, func(ctx convey.C) {
  29. res, err := d.Basic(c)
  30. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  31. ctx.So(err, convey.ShouldBeNil)
  32. ctx.So(res, convey.ShouldNotBeNil)
  33. })
  34. })
  35. }
  36. func TestMaterialFilters(t *testing.T) {
  37. var (
  38. c = context.TODO()
  39. )
  40. convey.Convey("Filters", t, func(ctx convey.C) {
  41. res, resMap, err := d.Filters(c)
  42. ctx.Convey("Then err should be nil.res,resMap should not be nil.", func(ctx convey.C) {
  43. ctx.So(err, convey.ShouldBeNil)
  44. ctx.So(resMap, convey.ShouldNotBeNil)
  45. ctx.So(res, convey.ShouldNotBeNil)
  46. })
  47. })
  48. }
  49. func TestMaterialVstickers(t *testing.T) {
  50. var (
  51. c = context.TODO()
  52. )
  53. convey.Convey("Vstickers", t, func(ctx convey.C) {
  54. guard := monkey.PatchInstanceMethod(reflect.TypeOf(d.db), "Query", func(_ *xsql.DB, _ context.Context, _ string, _ ...interface{}) (*xsql.Rows, error) {
  55. return nil, fmt.Errorf("db.Query error")
  56. })
  57. defer guard.Unpatch()
  58. res, resMap, err := d.Vstickers(c)
  59. ctx.Convey("Then err should be nil.res,resMap should not be nil.", func(ctx convey.C) {
  60. ctx.So(err, convey.ShouldNotBeNil)
  61. ctx.So(len(resMap), convey.ShouldEqual, 0)
  62. ctx.So(len(res), convey.ShouldEqual, 0)
  63. })
  64. })
  65. }
  66. func TestCooperates(t *testing.T) {
  67. var (
  68. c = context.TODO()
  69. )
  70. convey.Convey("Cooperates", t, func(ctx convey.C) {
  71. guard := monkey.PatchInstanceMethod(reflect.TypeOf(d.db), "Query", func(_ *xsql.DB, _ context.Context, _ string, _ ...interface{}) (*xsql.Rows, error) {
  72. return nil, fmt.Errorf("db.Query error")
  73. })
  74. defer guard.Unpatch()
  75. res, resMap, err := d.Cooperates(c)
  76. ctx.Convey("Then err should be nil.res,resMap should not be nil.", func(ctx convey.C) {
  77. ctx.So(err, convey.ShouldNotBeNil)
  78. ctx.So(len(resMap), convey.ShouldEqual, 0)
  79. ctx.So(len(res), convey.ShouldEqual, 0)
  80. })
  81. })
  82. }
  83. func TestBasic(t *testing.T) {
  84. var (
  85. err error
  86. c = context.TODO()
  87. res = make(map[string]interface{})
  88. )
  89. convey.Convey("Basic", t, func(ctx convey.C) {
  90. guard := monkey.PatchInstanceMethod(reflect.TypeOf(d.db), "Query", func(_ *xsql.DB, _ context.Context, _ string, _ ...interface{}) (*xsql.Rows, error) {
  91. return nil, fmt.Errorf("db.Query error")
  92. })
  93. defer guard.Unpatch()
  94. res, err = d.Basic(c)
  95. ctx.Convey("Then err should be nil.res,resMap should not be nil.", func(ctx convey.C) {
  96. ctx.So(err, convey.ShouldNotBeNil)
  97. ctx.So(len(res), convey.ShouldEqual, 0)
  98. })
  99. })
  100. }