authority_test.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. package service
  2. import (
  3. "context"
  4. "testing"
  5. . "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestService_AddAuthorityUser(t *testing.T) {
  8. Convey("", t, WithService(func(s *Service) {
  9. s.dao.Exec(context.TODO(), "DELETE FROM authority_user WHERE username = 'maru'")
  10. err := s.AddAuthorityUser("maru", "maru")
  11. So(err, ShouldBeNil)
  12. }))
  13. }
  14. func TestService_AddAuthorityTaskRoleUser(t *testing.T) {
  15. Convey("", t, WithService(func(s *Service) {
  16. err := s.AddAuthorityTaskRoleUser("maru", "1")
  17. So(err, ShouldBeNil)
  18. }))
  19. }
  20. func TestService_AddAuthorityTaskGroupUser(t *testing.T) {
  21. Convey("", t, WithService(func(s *Service) {
  22. err := s.AddAuthorityTaskGroupUser("maru", "1")
  23. So(err, ShouldBeNil)
  24. }))
  25. }
  26. func TestService_AddAuthorityTaskRole(t *testing.T) {
  27. Convey("", t, WithService(func(s *Service) {
  28. s.dao.Exec(context.TODO(), "DELETE FROM authority_task_role WHERE name = 'test'")
  29. err := s.AddAuthorityTaskRole(1, "test", "test")
  30. So(err, ShouldBeNil)
  31. }))
  32. }
  33. func TestService_AddAuthorityTaskGroup(t *testing.T) {
  34. Convey("", t, WithService(func(s *Service) {
  35. s.dao.Exec(context.TODO(), "DELETE FROM authority_task_group WHERE name = 'test'")
  36. err := s.AddAuthorityTaskGroup("test", "test")
  37. So(err, ShouldBeNil)
  38. }))
  39. }
  40. func TestService_AddPrivilege(t *testing.T) {
  41. Convey("", t, WithService(func(s *Service) {
  42. s.dao.Exec(context.TODO(), "DELETE FROM authority_privilege WHERE name = 'test'")
  43. err := s.AddPrivilege("test", 1, 1, 1)
  44. So(err, ShouldBeNil)
  45. }))
  46. }
  47. func TestService_DeleteAuthorityTaskRoleUser(t *testing.T) {
  48. Convey("", t, WithService(func(s *Service) {
  49. err := s.DeleteAuthorityTaskRoleUser(11, 1)
  50. So(err, ShouldBeNil)
  51. }))
  52. }
  53. func TestService_DeleteAuthorityUser(t *testing.T) {
  54. Convey("", t, WithService(func(s *Service) {
  55. err := s.DeleteAuthorityUser(11)
  56. So(err, ShouldBeNil)
  57. }))
  58. }
  59. func TestService_DeleteAuthorityTaskRole(t *testing.T) {
  60. Convey("", t, WithService(func(s *Service) {
  61. err := s.DeleteAuthorityTaskRole(1)
  62. So(err, ShouldBeNil)
  63. }))
  64. }
  65. func TestService_DeleteAuthorityTaskGroupUser(t *testing.T) {
  66. Convey("", t, WithService(func(s *Service) {
  67. err := s.DeleteAuthorityTaskGroupUser(11, 1)
  68. So(err, ShouldBeNil)
  69. }))
  70. }
  71. func TestService_DeleteAuthorityTaskGroup(t *testing.T) {
  72. Convey("", t, WithService(func(s *Service) {
  73. err := s.DeleteAuthorityTaskGroup(1)
  74. So(err, ShouldBeNil)
  75. }))
  76. }
  77. func TestService_GetAuthorityUserPrivileges(t *testing.T) {
  78. Convey("", t, WithService(func(s *Service) {
  79. _, err := s.GetAuthorityUserPrivileges("maru")
  80. So(err, ShouldBeNil)
  81. }))
  82. }
  83. func TestService_ListPrivilege(t *testing.T) {
  84. Convey("", t, WithService(func(s *Service) {
  85. _, err := s.ListPrivilege()
  86. So(err, ShouldBeNil)
  87. }))
  88. }
  89. func TestService_ListGroupAndRole(t *testing.T) {
  90. Convey("", t, WithService(func(s *Service) {
  91. _, _, err := s.ListGroupAndRole()
  92. So(err, ShouldBeNil)
  93. }))
  94. }
  95. func TestService_ListAuthorityTaskRoles(t *testing.T) {
  96. Convey("", t, WithService(func(s *Service) {
  97. s.dao.Exec(context.TODO(), "UPDATE authority_user SET task_group = 1 WHERE username = 'test'")
  98. _, _, err := s.ListAuthorityTaskRoles("test", 0, 10, "id")
  99. So(err, ShouldBeNil)
  100. }))
  101. }
  102. func TestService_ListAuthorityTaskGroups(t *testing.T) {
  103. Convey("", t, WithService(func(s *Service) {
  104. _, _, err := s.ListAuthorityTaskGroups(0, 10, "id")
  105. So(err, ShouldBeNil)
  106. }))
  107. }
  108. func TestService_ListAuthorityRolePrivilege(t *testing.T) {
  109. Convey("", t, WithService(func(s *Service) {
  110. s.dao.Exec(context.TODO(), "UPDATE authority_task_group SET is_deleted = 0 WHERE id = 1")
  111. s.dao.Exec(context.TODO(), "UPDATE authority_task_role SET is_deleted = 0 WHERE id = 1")
  112. _, err := s.ListAuthorityRolePrivilege(1, 1, 2)
  113. So(err, ShouldBeNil)
  114. }))
  115. }
  116. func TestService_ListAuthorityGroupPrivilege(t *testing.T) {
  117. Convey("", t, WithService(func(s *Service) {
  118. s.dao.Exec(context.TODO(), "UPDATE authority_task_group SET is_deleted = 0 WHERE id = 1")
  119. _, err := s.ListAuthorityGroupPrivilege(1, 1)
  120. So(err, ShouldBeNil)
  121. }))
  122. }
  123. func TestService_ListAuthorityUsers(t *testing.T) {
  124. Convey("", t, WithService(func(s *Service) {
  125. _, _, err := s.ListAuthorityUsers("", 0, 0, "id")
  126. So(err, ShouldBeNil)
  127. }))
  128. }
  129. func TestService_UpdatePrivilege(t *testing.T) {
  130. Convey("", t, WithService(func(s *Service) {
  131. s.dao.Exec(context.TODO(), "DELETE FROM authority_privilege WHERE name = 'test'")
  132. err := s.UpdatePrivilege(1, "test", 1, 1, 1)
  133. So(err, ShouldBeNil)
  134. }))
  135. }
  136. func TestService_UpdateAuthorityUserInfo(t *testing.T) {
  137. Convey("", t, WithService(func(s *Service) {
  138. s.dao.Exec(context.TODO(), "UPDATE authority_user SET nickname = 'abc' WHERE id = 1")
  139. err := s.UpdateAuthorityUserInfo(1, "test")
  140. So(err, ShouldBeNil)
  141. }))
  142. }
  143. func TestService_UpdateAuthorityUserAuth(t *testing.T) {
  144. Convey("", t, WithService(func(s *Service) {
  145. err := s.UpdateAuthorityUserAuth(1, "1", "1")
  146. So(err, ShouldBeNil)
  147. }))
  148. }
  149. func TestService_UpdateAuthorityTaskRoleInfo(t *testing.T) {
  150. Convey("", t, WithService(func(s *Service) {
  151. err := s.UpdateAuthorityTaskRoleInfo(1, "maru", "test")
  152. So(err, ShouldBeNil)
  153. }))
  154. }
  155. func TestService_UpdateAuthorityRolePrivilege(t *testing.T) {
  156. Convey("", t, WithService(func(s *Service) {
  157. err := s.UpdateAuthorityRolePrivilege(1, "", "")
  158. So(err, ShouldBeNil)
  159. }))
  160. }
  161. func TestService_UpdateAuthorityTaskGroupInfo(t *testing.T) {
  162. Convey("", t, WithService(func(s *Service) {
  163. s.dao.Exec(context.TODO(), "UPDATE authority_task_group SET desc = 'tt' WHERE id = 1")
  164. err := s.UpdateAuthorityTaskGroupInfo(1, "", "test")
  165. So(err, ShouldBeNil)
  166. }))
  167. }
  168. func TestService_UpdateAuthorityGroupPrivilege(t *testing.T) {
  169. Convey("", t, WithService(func(s *Service) {
  170. err := s.UpdateAuthorityGroupPrivilege(1, "", "", 0)
  171. So(err, ShouldBeNil)
  172. }))
  173. }