admin_test.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package admin
  2. import (
  3. "context"
  4. "gd_admin/apis"
  5. "encoding/json"
  6. "testing"
  7. )
  8. var id int64
  9. func Test_AdminRegister(t *testing.T) {
  10. req := apis.AdminRegisterReq{
  11. AdminName: "test1",
  12. AdminPasswd: "admin",
  13. AdminPhone: "",
  14. AdminEmail: "",
  15. GroupId: 1,
  16. NodeId: "1,2,3,4,5",
  17. }
  18. reply := apis.AdminRegisterReply{}
  19. if err := xcli.Call(context.Background(), "AdminRegister", req, &reply); err != nil {
  20. t.Error("failed to call: ", err)
  21. } else {
  22. d, _ := json.Marshal(reply)
  23. t.Log(string(d))
  24. }
  25. }
  26. func Test_AdminLogin(t *testing.T) {
  27. req := apis.AdminLoginReq{AdminName: "admin", AdminPasswd: "zaq12EDC"}
  28. reply := apis.AdminLoginReply{}
  29. if err := xcli.Call(context.Background(), "AdminLogin", req, &reply); err != nil {
  30. t.Error("failed to call: ", err)
  31. } else {
  32. d, _ := json.Marshal(reply)
  33. t.Log(string(d))
  34. id = reply.AdminId
  35. }
  36. }
  37. func Test_AdminModify(t *testing.T) {
  38. req := apis.AdminModifyReq{
  39. AdminId: 14,
  40. AdminPasswd: "123456",
  41. AdminPhone: "18000000000",
  42. AdminEmail: "",
  43. GroupId: 1,
  44. NodeId: "1,2,3,4,5,6,7",
  45. }
  46. reply := apis.AdminModifyReply{}
  47. if err := xcli.Call(context.Background(), "AdminModify", req, &reply); err != nil {
  48. t.Error("failed to call: ", err)
  49. } else {
  50. d, _ := json.Marshal(reply)
  51. t.Log(string(d))
  52. }
  53. }
  54. func Test_AdminGetAll(t *testing.T) {
  55. req := apis.AdminGetAllReq{
  56. Search: "ep",
  57. }
  58. reply := apis.AdminGetAllReply{}
  59. if err := xcli.Call(context.Background(), "AdminGetAll", req, &reply); err != nil {
  60. t.Error("failed to call: ", err)
  61. } else {
  62. d, _ := json.Marshal(reply)
  63. t.Log(string(d))
  64. }
  65. }
  66. func Test_AdminDelete(t *testing.T) {
  67. req := apis.AdminDeleteReq{AdminId: id}
  68. reply := apis.AdminDeleteReply{}
  69. if err := xcli.Call(context.Background(), "AdminDelete", req, &reply); err != nil {
  70. t.Error("failed to call: ", err)
  71. } else {
  72. d, _ := json.Marshal(reply)
  73. t.Log(string(d))
  74. }
  75. }
  76. func Test_UpdateStatus(t *testing.T) {
  77. req := apis.UpdateStatusReq{AdminId: 5}
  78. reply := apis.UpdateStatusReply{}
  79. if err := xcli.Call(context.Background(), "UpdateAdminStatus", req, &reply); err != nil {
  80. t.Error("failed to call: ", err)
  81. } else {
  82. d, _ := json.Marshal(reply)
  83. t.Log(string(d))
  84. }
  85. }
  86. func Test_GetInfo(t *testing.T) {
  87. req := apis.GetInfoReq{Uid: 14}
  88. reply := apis.GetInfoReply{}
  89. if err := xcli.Call(context.Background(), "GetInfo", req, &reply); err != nil {
  90. t.Error("failed to call: ", err)
  91. } else {
  92. d, _ := json.Marshal(reply)
  93. t.Log(string(d))
  94. }
  95. }