role_test.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package http
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestHttpGetRole(t *testing.T) {
  8. var (
  9. c = context.TODO()
  10. bid = int64(0)
  11. uid = int64(0)
  12. )
  13. convey.Convey("GetRole", t, func(ctx convey.C) {
  14. httpMock("GET", d.c.Host.Manager+_getRole).Reply(200).JSON(`{"code":0,"data":[{"id":0}]}`)
  15. roles, err := d.GetRole(c, bid, uid)
  16. ctx.Convey("Then err should be nil.roles should not be nil.", func(ctx convey.C) {
  17. ctx.So(err, convey.ShouldBeNil)
  18. ctx.So(roles, convey.ShouldNotBeNil)
  19. })
  20. })
  21. }
  22. func TestHttpGetUserRoles(t *testing.T) {
  23. var (
  24. c = context.TODO()
  25. )
  26. convey.Convey("GetUserRoles", t, func(ctx convey.C) {
  27. httpMock("GET", d.c.Host.Manager+_getRoles).Reply(200).JSON(`{"code":0,"data":[{"id":0}]}`)
  28. roles, err := d.GetUserRoles(c, 421)
  29. ctx.Convey("Then err should be nil.roles should not be nil.", func(ctx convey.C) {
  30. ctx.So(err, convey.ShouldBeNil)
  31. ctx.So(roles, convey.ShouldNotBeNil)
  32. })
  33. })
  34. }
  35. func TestHttpGetUnames(t *testing.T) {
  36. var (
  37. c = context.TODO()
  38. uids = []int64{421}
  39. )
  40. convey.Convey("GetUnames", t, func(ctx convey.C) {
  41. httpMock("GET", d.c.Host.Manager+_getUname).Reply(200).JSON(`{"code":0,"data":{"421":"丝瓜"}}`)
  42. unames, err := d.GetUnames(c, uids)
  43. ctx.Convey("Then err should be nil.unames should not be nil.", func(ctx convey.C) {
  44. ctx.So(err, convey.ShouldBeNil)
  45. ctx.So(unames, convey.ShouldNotBeNil)
  46. })
  47. })
  48. }
  49. func TestHttpGetUIDs(t *testing.T) {
  50. convey.Convey("GetUIDs", t, func(ctx convey.C) {
  51. httpMock("GET", d.c.Host.Manager+_getUIDs).Reply(200).JSON(`{"code":0,"data":{"cxf":481}}`)
  52. uids, err := d.GetUIDs(cntx, "cxf")
  53. ctx.Convey("Then err should be nil.unames should not be nil.", func(ctx convey.C) {
  54. ctx.So(err, convey.ShouldBeNil)
  55. ctx.So(uids, convey.ShouldNotBeNil)
  56. })
  57. })
  58. }
  59. func TestHttpGetUdepartment(t *testing.T) {
  60. convey.Convey("GetUdepartment", t, func(ctx convey.C) {
  61. httpMock("GET", d.c.Host.Manager+_getUdepartment).Reply(200).JSON(`{"code":0,"data":{"481":"CTO"}}`)
  62. depart, err := d.GetUdepartment(cntx, []int64{481})
  63. ctx.Convey("Then err should be nil.unames should not be nil.", func(ctx convey.C) {
  64. ctx.So(err, convey.ShouldBeNil)
  65. ctx.So(depart, convey.ShouldNotBeNil)
  66. })
  67. })
  68. }