service_test.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. package service
  2. import (
  3. "context"
  4. "flag"
  5. "fmt"
  6. "path/filepath"
  7. "testing"
  8. "time"
  9. "go-common/app/admin/main/manager/conf"
  10. . "github.com/smartystreets/goconvey/convey"
  11. )
  12. var (
  13. srv *Service
  14. ctx = context.Background()
  15. )
  16. func init() {
  17. dir, _ := filepath.Abs("../cmd/manager-admin-test.toml")
  18. flag.Set("conf", dir)
  19. conf.Init()
  20. srv = New(conf.Conf)
  21. time.Sleep(time.Second)
  22. }
  23. func WithService(f func(s *Service)) func() {
  24. return func() {
  25. // Reset(func() { CleanCache() })
  26. f(srv)
  27. }
  28. }
  29. func Test_Admins(t *testing.T) {
  30. Convey("admins", t, WithService(func(s *Service) {
  31. res, err := s.adms()
  32. So(err, ShouldBeNil)
  33. So(len(res), ShouldBeGreaterThan, 0)
  34. t.Logf("admins len(%d)", len(res))
  35. }))
  36. }
  37. func Test_Pointers(t *testing.T) {
  38. Convey("pointers", t, WithService(func(s *Service) {
  39. res, _, err := s.ptrs()
  40. So(err, ShouldBeNil)
  41. So(len(res), ShouldBeGreaterThan, 0)
  42. t.Logf("points len(%d)", len(res))
  43. }))
  44. }
  45. func Test_RoleAuths(t *testing.T) {
  46. Convey("role auths", t, WithService(func(s *Service) {
  47. res, err := s.roleAuths()
  48. So(err, ShouldBeNil)
  49. So(len(res), ShouldBeGreaterThan, 0)
  50. t.Logf("role auths len(%d)", len(res))
  51. }))
  52. }
  53. func Test_GroupAuths(t *testing.T) {
  54. Convey("group auths", t, WithService(func(s *Service) {
  55. res, err := s.groupAuths()
  56. So(err, ShouldBeNil)
  57. So(len(res), ShouldBeGreaterThan, 0)
  58. t.Logf("group auths len(%d)", len(res))
  59. }))
  60. }
  61. func TestService_Unames(t *testing.T) {
  62. Convey("unames check", t, WithService(func(s *Service) {
  63. var uids []int64
  64. uids = append(uids, 1, 2, 3)
  65. res := s.Unames(ctx, uids)
  66. So(len(res), ShouldBeGreaterThan, 0)
  67. }))
  68. }
  69. func TestService_UsersTotal(t *testing.T) {
  70. Convey("TestService_UsersTotal", t, WithService(func(s *Service) {
  71. res, err := s.UsersTotal(ctx)
  72. So(err, ShouldBeNil)
  73. So(res, ShouldBeGreaterThan, 0)
  74. }))
  75. }
  76. func TestService_Users(t *testing.T) {
  77. Convey("TestService_Users", t, WithService(func(s *Service) {
  78. res, err := s.Users(ctx, 1, 20)
  79. So(err, ShouldBeNil)
  80. So(len(res.Items), ShouldBeGreaterThan, 0)
  81. }))
  82. }
  83. func TestService_RankUsers(t *testing.T) {
  84. Convey("TestService_RankUsers", t, WithService(func(s *Service) {
  85. res, count, err := s.RankUsers(ctx, 1, 20, "zhaoshichen")
  86. So(err, ShouldBeNil)
  87. fmt.Println(res)
  88. fmt.Println(count)
  89. }))
  90. }
  91. func TestService_Ping(t *testing.T) {
  92. Convey("TestService_RankUsers", t, WithService(func(s *Service) {
  93. err := s.Ping(ctx)
  94. So(err, ShouldBeNil)
  95. }))
  96. }
  97. func TestService_Heartbeat(t *testing.T) {
  98. Convey("TestService_RankUsers", t, WithService(func(s *Service) {
  99. err := s.Heartbeat(ctx, "zhaoshichen")
  100. So(err, ShouldBeNil)
  101. }))
  102. }
  103. func TestService_Close(t *testing.T) {
  104. Convey("TestService_Close", t, WithService(func(s *Service) {
  105. s.Close()
  106. }))
  107. }
  108. func TestService_Wait(t *testing.T) {
  109. Convey("TestService_Wait", t, WithService(func(s *Service) {
  110. s.Wait()
  111. }))
  112. }