authority_test.go 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "go-common/app/admin/main/growup/model"
  7. xtime "go-common/library/time"
  8. . "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestDao_AddAuthorityTaskGroup(t *testing.T) {
  11. Convey("", t, func() {
  12. now := xtime.Time(time.Now().Unix())
  13. user := &model.SUser{
  14. Name: "admin",
  15. }
  16. sUser := []*model.SUser{user}
  17. group := &model.TaskGroup{
  18. Name: "test-dao",
  19. Desc: "test",
  20. Privileges: "test",
  21. ATime: now,
  22. Users: sUser,
  23. IsDeleted: 0,
  24. }
  25. Exec(context.Background(), "DELETE FROM authority_task_group WHERE name = 'test-dao'")
  26. err := d.AddAuthorityTaskGroup(group)
  27. So(err, ShouldBeNil)
  28. group.Desc = "test1"
  29. Exec(context.Background(), "UPDATE authority_task_group SET is_deleted = 1 WHERE name = 'test-dao'")
  30. err = d.AddAuthorityTaskGroup(group)
  31. So(err, ShouldBeNil)
  32. })
  33. }
  34. func TestDao_AddAuthorityTaskRole(t *testing.T) {
  35. Convey("", t, func() {
  36. now := xtime.Time(time.Now().Unix())
  37. user := &model.SUser{
  38. Name: "admin",
  39. }
  40. users := []*model.SUser{user}
  41. role := &model.TaskRole{
  42. Name: "test-dao",
  43. Desc: "test",
  44. GroupID: 1,
  45. Privileges: "test",
  46. ATime: now,
  47. GroupName: "test",
  48. Users: users,
  49. }
  50. Exec(context.Background(), "DELETE FROM authority_task_role WHERE name = 'test-dao'")
  51. err := d.AddAuthorityTaskRole(role)
  52. So(err, ShouldBeNil)
  53. Exec(context.Background(), "UPDATE authority_task_role SET is_deleted = 1 WHERE name = 'test-dao'")
  54. role.Desc = "test1"
  55. err = d.AddAuthorityTaskRole(role)
  56. So(err, ShouldBeNil)
  57. })
  58. }
  59. func TestDao_AddAuthorityUser(t *testing.T) {
  60. Convey("", t, func() {
  61. now := xtime.Time(time.Now().Unix())
  62. group := &model.Group{
  63. Name: "TEST_GROUP",
  64. }
  65. role := &model.Role{
  66. Name: "test_role",
  67. }
  68. user := &model.User{
  69. Username: "test-dao",
  70. Nickname: "test",
  71. TaskGroup: "test",
  72. TaskRole: "test",
  73. ATime: now,
  74. IsDeleted: 0,
  75. Groups: []*model.Group{group},
  76. Roles: []*model.Role{role},
  77. }
  78. Exec(context.Background(), "DELETE FROM authority_user WHERE username = 'test-dao'")
  79. err := d.AddAuthorityUser(user)
  80. So(err, ShouldBeNil)
  81. Exec(context.Background(), "UPDATE authority_user SET is_deleted = 1 WHERE username = 'test-dao'")
  82. user.Nickname = "test1"
  83. err = d.AddAuthorityUser(user)
  84. So(err, ShouldBeNil)
  85. })
  86. }
  87. func TestDao_AddPrivilege(t *testing.T) {
  88. Convey("", t, func() {
  89. privilege := &model.Privilege{
  90. Name: "test-dao",
  91. Level: 1,
  92. FatherID: 2,
  93. IsRouter: 1,
  94. IsDeleted: 0,
  95. }
  96. Exec(context.Background(), "DELETE FROM authority_privilege WHERE name = 'test-dao'")
  97. err := d.AddPrivilege(privilege)
  98. So(err, ShouldBeNil)
  99. Exec(context.Background(), "UPDATE authority_privilege SET is_deleted = 1 WHERE name = 'test-dao'")
  100. privilege.IsRouter = 0
  101. err = d.AddPrivilege(privilege)
  102. So(err, ShouldBeNil)
  103. })
  104. }
  105. func TestDao_DeleteAuthorityTaskGroup(t *testing.T) {
  106. Convey("", t, func() {
  107. Exec(context.Background(), "INSERT INTO authority_task_group(id) VALUES(9999)")
  108. err := d.DeleteAuthorityTaskGroup(9999)
  109. So(err, ShouldBeNil)
  110. })
  111. }
  112. func TestDao_DeleteAuthorityTaskRole(t *testing.T) {
  113. Convey("", t, func() {
  114. Exec(context.Background(), "INSERT INTO authority_task_role(id) VALUES(9999)")
  115. err := d.DeleteAuthorityTaskRole(9999)
  116. So(err, ShouldBeNil)
  117. })
  118. }
  119. func TestDao_DeleteAuthorityUser(t *testing.T) {
  120. Convey("", t, func() {
  121. Exec(context.Background(), "INSERT INTO authority_user(id) VALUES(9999)")
  122. err := d.DeleteAuthorityUser(1)
  123. So(err, ShouldBeNil)
  124. })
  125. }
  126. func TestDao_GetAuthorityTaskGroupName(t *testing.T) {
  127. Convey("", t, func() {
  128. Exec(context.Background(), "UPDATE authority_task_group SET is_deleted = 0 WHERE id = 1")
  129. _, err := d.GetAuthorityTaskGroupName(1)
  130. So(err, ShouldBeNil)
  131. })
  132. }
  133. func TestDao_GetAuthorityTaskGroupNames(t *testing.T) {
  134. Convey("", t, func() {
  135. _, err := d.GetAuthorityTaskGroupNames([]string{"1"})
  136. So(err, ShouldBeNil)
  137. })
  138. }
  139. func TestDao_GetAuthorityTaskGroup(t *testing.T) {
  140. Convey("", t, func() {
  141. _, err := d.GetAuthorityTaskGroup("id > 0")
  142. So(err, ShouldBeNil)
  143. })
  144. }
  145. func TestDao_GetAuthorityTaskGroupPrivileges(t *testing.T) {
  146. Convey("", t, func() {
  147. Exec(context.Background(), "insert into authority_task_group(id,name,privileges) values(1001, '12131','1,2,3,4,5,6,7')")
  148. _, err := d.GetAuthorityTaskGroupPrivileges(1001)
  149. So(err, ShouldBeNil)
  150. })
  151. }
  152. func TestDao_GetAuthorityTaskGroups(t *testing.T) {
  153. Convey("", t, func() {
  154. _, err := d.GetAuthorityTaskGroups("")
  155. So(err, ShouldBeNil)
  156. })
  157. }
  158. func TestDao_GetAuthorityTaskRolePrivileges(t *testing.T) {
  159. Convey("", t, func() {
  160. Exec(context.Background(), "insert into authority_task_role(id,name,group_id,privileges) values(1000, '12312',1001, '1,2,3,4,5,6,7')")
  161. _, err := d.GetAuthorityTaskRolePrivileges(1000)
  162. So(err, ShouldBeNil)
  163. })
  164. }
  165. func TestDao_GetAuthorityTaskRoles(t *testing.T) {
  166. Convey("", t, func() {
  167. _, err := d.GetAuthorityTaskRoles("")
  168. So(err, ShouldBeNil)
  169. })
  170. }
  171. func TestDao_GetAuthorityUsersInfo(t *testing.T) {
  172. Convey("", t, func() {
  173. _, err := d.GetAuthorityUsersInfo("", "id")
  174. So(err, ShouldBeNil)
  175. })
  176. }
  177. func TestDao_GetLevelPrivileges(t *testing.T) {
  178. Convey("", t, func() {
  179. _, err := d.GetLevelPrivileges("")
  180. So(err, ShouldBeNil)
  181. })
  182. }
  183. func TestDao_ListAuthorityTaskGroups(t *testing.T) {
  184. Convey("", t, func() {
  185. _, _, err := d.ListAuthorityTaskGroups("", 0, 0, "-id")
  186. So(err, ShouldBeNil)
  187. })
  188. }
  189. func TestDao_ListAuthorityTaskRoles(t *testing.T) {
  190. Convey("", t, func() {
  191. _, _, err := d.ListAuthorityTaskRoles("", 0, 0, "-id")
  192. So(err, ShouldBeNil)
  193. })
  194. }
  195. func TestDao_ListAuthorityUsers(t *testing.T) {
  196. Convey("", t, func() {
  197. _, _, err := d.ListAuthorityUsers("", 0, 0, "-id")
  198. So(err, ShouldBeNil)
  199. })
  200. }
  201. func TestDao_UpdateAuthorityTaskGroup(t *testing.T) {
  202. Convey("", t, func() {
  203. updates := map[string]interface{}{
  204. "desc": "test11",
  205. }
  206. Exec(context.Background(), "UPDATE authority_task_group SET desc = 'aaa' WHERE id = 1")
  207. err := d.UpdateAuthorityTaskGroup(1, updates)
  208. So(err, ShouldBeNil)
  209. })
  210. }
  211. func TestDao_UpdateAuthorityTaskRole(t *testing.T) {
  212. Convey("", t, func() {
  213. updates := map[string]interface{}{
  214. "desc": "test",
  215. }
  216. Exec(context.Background(), "UPDATE authority_task_role SET desc = 'aaa' WHERE id = 1")
  217. err := d.UpdateAuthorityTaskRole(1, updates)
  218. So(err, ShouldBeNil)
  219. })
  220. }
  221. func TestDao_UpdateAuthorityUser(t *testing.T) {
  222. Convey("", t, func() {
  223. updates := map[string]interface{}{
  224. "username": "test",
  225. }
  226. err := d.UpdateAuthorityUser(1, updates)
  227. So(err, ShouldBeNil)
  228. })
  229. }
  230. func TestDao_UpdatePrivilege(t *testing.T) {
  231. Convey("", t, func() {
  232. updates := map[string]interface{}{
  233. "name": "test",
  234. }
  235. err := d.UpdatePrivilege(1, updates)
  236. So(err, ShouldBeNil)
  237. })
  238. }