vdoad_test.go 1018 B

1234567891011121314151617181920212223242526272829303132333435
  1. package ads
  2. import (
  3. "context"
  4. "fmt"
  5. "reflect"
  6. "testing"
  7. xsql "go-common/library/database/sql"
  8. "github.com/bouk/monkey"
  9. "github.com/smartystreets/goconvey/convey"
  10. )
  11. func TestAdsVideoAds(t *testing.T) {
  12. convey.Convey("VideoAds", t, func(ctx convey.C) {
  13. ctx.Convey("When everything is correct", func(ctx convey.C) {
  14. res, err := d.VideoAds(context.Background())
  15. ctx.Convey("Error should be nil, res should not be empty(No Data)", func(ctx convey.C) {
  16. ctx.So(err, convey.ShouldBeNil)
  17. ctx.SkipSo(res, convey.ShouldNotBeEmpty)
  18. })
  19. })
  20. ctx.Convey("When db.Query gets error", func(ctx convey.C) {
  21. guard := monkey.PatchInstanceMethod(reflect.TypeOf(d.db), "Query", func(_ *xsql.DB, _ context.Context, _ string, _ ...interface{}) (*xsql.Rows, error) {
  22. return nil, fmt.Errorf("db.Query error")
  23. })
  24. defer guard.Unpatch()
  25. _, err := d.VideoAds(context.Background())
  26. ctx.Convey("Error should not be nil", func(ctx convey.C) {
  27. ctx.So(err, convey.ShouldNotBeNil)
  28. })
  29. })
  30. })
  31. }