playerCheck_test.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package dao
  2. import (
  3. "context"
  4. xsql "database/sql"
  5. "fmt"
  6. "reflect"
  7. "testing"
  8. "go-common/library/database/sql"
  9. "github.com/bouk/monkey"
  10. "github.com/smartystreets/goconvey/convey"
  11. )
  12. func TestDaoInPlayCheck(t *testing.T) {
  13. convey.Convey("InPlayCheck", t, func(ctx convey.C) {
  14. var (
  15. c = context.TODO()
  16. platform = int(0)
  17. isp = int(0)
  18. ipChangeTimes = int(0)
  19. mid = int64(0)
  20. checkTime = int64(0)
  21. aid = int64(0)
  22. connectSpeed = int64(0)
  23. ioSpeed = int64(0)
  24. region = ""
  25. school = ""
  26. ip = ""
  27. cdn = ""
  28. )
  29. ctx.Convey("When everything is correct", func(ctx convey.C) {
  30. rows, err := d.InPlayCheck(c, platform, isp, ipChangeTimes, mid, checkTime, aid, connectSpeed, ioSpeed, region, school, ip, cdn)
  31. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  32. ctx.So(err, convey.ShouldBeNil)
  33. ctx.So(rows, convey.ShouldNotBeNil)
  34. })
  35. })
  36. ctx.Convey("When d.dbMs.Query gets error", func(ctx convey.C) {
  37. guard := monkey.PatchInstanceMethod(reflect.TypeOf(d.dbMs), "Exec",
  38. func(_ *sql.DB, _ context.Context, _ string, _ ...interface{}) (xsql.Result, error) {
  39. return nil, fmt.Errorf("d.dbMs.Exec Error")
  40. })
  41. defer guard.Unpatch()
  42. _, err := d.InPlayCheck(c, platform, isp, ipChangeTimes, mid, checkTime, aid, connectSpeed, ioSpeed, region, school, ip, cdn)
  43. ctx.Convey("Then err should not be nil.", func(ctx convey.C) {
  44. ctx.So(err, convey.ShouldNotBeNil)
  45. })
  46. })
  47. })
  48. }