aso_test.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package dao
  2. import (
  3. "context"
  4. "database/sql"
  5. "database/sql/driver"
  6. "reflect"
  7. "testing"
  8. "go-common/app/job/main/passport-sns/model"
  9. xsql "go-common/library/database/sql"
  10. "github.com/bouk/monkey"
  11. "github.com/smartystreets/goconvey/convey"
  12. )
  13. func TestDao_AddSnsLog(t *testing.T) {
  14. convey.Convey("AddSnsLog", t, func(ctx convey.C) {
  15. var (
  16. c = context.Background()
  17. a = &model.SnsLog{}
  18. )
  19. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  20. mock := monkey.PatchInstanceMethod(reflect.TypeOf(d.asoDB), "Exec", func(_ *xsql.DB, _ context.Context, _ string, _ ...interface{}) (res sql.Result, err error) {
  21. return driver.RowsAffected(1), nil
  22. })
  23. defer mock.Unpatch()
  24. affected, err := d.AddSnsLog(c, a)
  25. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  26. ctx.So(err, convey.ShouldBeNil)
  27. })
  28. ctx.Convey("Then affected should not be nil.", func(ctx convey.C) {
  29. ctx.So(affected, convey.ShouldNotBeNil)
  30. })
  31. })
  32. })
  33. }
  34. func TestDao_AsoAccountSns(t *testing.T) {
  35. convey.Convey("AsoAccountSns", t, func(ctx convey.C) {
  36. var (
  37. c = context.Background()
  38. start = int64(0)
  39. )
  40. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  41. res, err := d.AsoAccountSns(c, start)
  42. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  43. ctx.So(err, convey.ShouldBeNil)
  44. ctx.So(res, convey.ShouldNotBeNil)
  45. })
  46. })
  47. })
  48. }
  49. func TestDao_AsoAccountSnsAll(t *testing.T) {
  50. convey.Convey("AsoAccountSnsAll", t, func(ctx convey.C) {
  51. var (
  52. c = context.Background()
  53. start = int64(0)
  54. )
  55. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  56. res, err := d.AsoAccountSnsAll(c, start)
  57. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  58. ctx.So(err, convey.ShouldBeNil)
  59. ctx.So(res, convey.ShouldNotBeNil)
  60. })
  61. })
  62. })
  63. }