music_test.go 954 B

123456789101112131415161718192021222324252627282930313233343536
  1. package archive
  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 TestMusics(t *testing.T) {
  12. convey.Convey("Musics", t, func(ctx convey.C) {
  13. var (
  14. c = context.Background()
  15. )
  16. ctx.Convey("uat db ok", func(ctx convey.C) {
  17. _, err := d.AllMusics(c)
  18. ctx.Convey("Then err should be nil.bizs should not be nil.", func(ctx convey.C) {
  19. ctx.So(err, convey.ShouldBeNil)
  20. })
  21. })
  22. ctx.Convey("db error", func(ctx convey.C) {
  23. guard := monkey.PatchInstanceMethod(reflect.TypeOf(d.db), "Query", func(_ *xsql.DB, _ context.Context, _ string, _ ...interface{}) (*xsql.Rows, error) {
  24. return nil, fmt.Errorf("db.Query error")
  25. })
  26. defer guard.Unpatch()
  27. _, err := d.AllMusics(c)
  28. ctx.Convey("Then err should be nil.bizs should not be nil.", func(ctx convey.C) {
  29. ctx.So(err, convey.ShouldNotBeNil)
  30. })
  31. })
  32. })
  33. }