manager_test.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestDaoUids(t *testing.T) {
  8. convey.Convey("Uids", t, func(ctx convey.C) {
  9. var (
  10. c = context.Background()
  11. )
  12. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  13. httpMock("GET", d.c.Host.Manager+_uidsURL).Reply(200).JSON(`{"code":0}`)
  14. _, err := d.Uids(c, []string{})
  15. ctx.Convey("Then nil should be nil.", func(ctx convey.C) {
  16. ctx.So(err, convey.ShouldBeNil)
  17. })
  18. })
  19. })
  20. }
  21. func TestDaoUnames(t *testing.T) {
  22. convey.Convey("Unames", t, func(ctx convey.C) {
  23. var (
  24. c = context.Background()
  25. )
  26. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  27. httpMock("GET", d.c.Host.Manager+_unamesURL).Reply(200).JSON(`{"code":0,"message":"0","data":{"10086":"cxf"}}`)
  28. _, err := d.Unames(c, []int64{})
  29. ctx.Convey("Then nil should be nil.", func(ctx convey.C) {
  30. ctx.So(err, convey.ShouldBeNil)
  31. })
  32. })
  33. })
  34. }
  35. func TestDaoGetUIDByName(t *testing.T) {
  36. convey.Convey("GetUIDByName", t, func(ctx convey.C) {
  37. var (
  38. c = context.Background()
  39. )
  40. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  41. httpMock("GET", d.c.Host.Manager+_uidsURL).Reply(200).JSON(`{"code":0,"message":"0","data":{"cxf":10086}}`)
  42. uid, err := d.GetUIDByName(c, "cxf")
  43. ctx.Convey("Then nil should be nil.", func(ctx convey.C) {
  44. ctx.So(err, convey.ShouldBeNil)
  45. ctx.So(uid, convey.ShouldEqual, 10086)
  46. })
  47. })
  48. })
  49. }
  50. func TestDaoGetNameByUID(t *testing.T) {
  51. convey.Convey("GetNameByUID", t, func(ctx convey.C) {
  52. var (
  53. c = context.Background()
  54. )
  55. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  56. httpMock("GET", d.c.Host.Manager+_unamesURL).Reply(200).JSON(`{"code":0,"message":"0","data":{"10086":"cxf"}}`)
  57. _, err := d.GetNameByUID(c, []int64{10086})
  58. ctx.Convey("Then nil should be nil.", func(ctx convey.C) {
  59. ctx.So(err, convey.ShouldBeNil)
  60. })
  61. })
  62. })
  63. }