passport_test.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "testing"
  6. "time"
  7. "github.com/smartystreets/goconvey/convey"
  8. "gopkg.in/h2non/gock.v1"
  9. )
  10. func TestDaoUpdateUname(t *testing.T) {
  11. convey.Convey("UpdateUname", t, func(ctx convey.C) {
  12. var (
  13. mid = int64(321)
  14. name = fmt.Sprintf("321testName%v%v", time.Now().Minute(), time.Now().Second())
  15. )
  16. ctx.Convey("UpdateUname success", func(ctx convey.C) {
  17. defer gock.OffAll()
  18. httpMock("POST", d.upUnameURL).Reply(200).JSON(`{"code":0}`)
  19. err := d.UpdateUname(context.Background(), mid, name)
  20. ctx.So(err, convey.ShouldBeNil)
  21. })
  22. ctx.Convey("UpdateUname failed", func(ctx convey.C) {
  23. defer gock.OffAll()
  24. httpMock("POST", d.upUnameURL).Reply(200).JSON(`{"code":500}`)
  25. err := d.UpdateUname(context.Background(), mid, name)
  26. ctx.So(err, convey.ShouldNotBeNil)
  27. })
  28. })
  29. }
  30. func TestDaoPassportQueryByMids(t *testing.T) {
  31. convey.Convey("PassportQueryByMids", t, func(ctx convey.C) {
  32. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  33. p, err := d.PassportQueryByMids(context.Background(), []int64{1, 2, 3})
  34. ctx.Convey("Then err should be nil.p should not be nil.", func(ctx convey.C) {
  35. ctx.So(err, convey.ShouldBeNil)
  36. ctx.So(p, convey.ShouldNotBeNil)
  37. })
  38. })
  39. })
  40. }
  41. func TestDaoPassportQueryByMidsChunked(t *testing.T) {
  42. convey.Convey("PassportQueryByMidsChunked", t, func(ctx convey.C) {
  43. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  44. p, err := d.PassportQueryByMidsChunked(context.Background(), []int64{1, 2, 3}, 50)
  45. ctx.Convey("Then err should be nil.p should not be nil.", func(ctx convey.C) {
  46. ctx.So(err, convey.ShouldBeNil)
  47. ctx.So(p, convey.ShouldNotBeNil)
  48. })
  49. })
  50. })
  51. }