canal_test.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. package http
  2. import (
  3. "fmt"
  4. "net/url"
  5. "testing"
  6. "go-common/app/admin/main/apm/model/canal"
  7. . "github.com/smartystreets/goconvey/convey"
  8. )
  9. var (
  10. _listuri = "%s/x/admin/apm/canal"
  11. _scanurl = "%s/x/admin/apm/canal/scan"
  12. _canalediturl = "%s/x/admin/apm/canal/apply/edit"
  13. _addrallurl = "%s/x/admin/apm/canal/addrs"
  14. _adduri = "%s/x/admin/apm/canal/add"
  15. _deleteuri = "%s/x/admin/apm/canal/delete"
  16. _edituri = "%s/x/admin/apm/canal/edit"
  17. _applyurl = "%s/x/admin/apm/canal/apply"
  18. )
  19. func TestCanalList(t *testing.T) {
  20. Convey("TestCanalList", t, func() {
  21. params := url.Values{}
  22. params.Set("project", "main.web-svr")
  23. res := new(struct {
  24. Code int `json:"code"`
  25. Message string `json:"message"`
  26. Data *canal.Paper `json:"data"`
  27. })
  28. _ = requests("GET", fmt.Sprintf(_listuri, _domain), "", params, &res)
  29. t.Logf("res:%+v", res.Data)
  30. So(res.Code, ShouldEqual, 0)
  31. })
  32. }
  33. func TestCanalAdd(t *testing.T) {
  34. Convey("TestCanalAdd exists", t, func() {
  35. params := url.Values{}
  36. params.Set("addr", "172.16.33.866:3308")
  37. params.Set("bin_name", "fss")
  38. params.Set("bin_pos", "1")
  39. params.Set("remark", "admin")
  40. params.Set("project", "main.web-svr")
  41. params.Set("leader", "fss")
  42. res := Response{}
  43. _ = requests("POST", fmt.Sprintf(_adduri, _domain), "", params, &res)
  44. t.Logf("res:%+v", res)
  45. //So(res.Message, ShouldContainSubstring, "exist")
  46. //So(res.Code, ShouldEqual, -400)
  47. })
  48. }
  49. func TestCanalEdit(t *testing.T) {
  50. Convey("TestCanalEdit", t, func() {
  51. params := url.Values{}
  52. params.Set("id", "8384")
  53. params.Set("bin_name", "rtwew")
  54. params.Set("bin_pos", "20")
  55. params.Set("remark", "inesww")
  56. params.Set("project", "main.web-svrq")
  57. params.Set("leader", "dsa")
  58. res := Response{}
  59. _ = requests("POST", fmt.Sprintf(_edituri, _domain), "", params, &res)
  60. t.Logf("res:%+v", res)
  61. })
  62. }
  63. func TestCanalDelete(t *testing.T) {
  64. Convey("TestCanalDelete", t, func() {
  65. params := url.Values{}
  66. params.Set("addr", "ewe")
  67. res := Response{}
  68. _ = requests("POST", fmt.Sprintf(_deleteuri, _domain), "", params, &res)
  69. t.Logf("res:%+v", res)
  70. })
  71. }
  72. func TestScanFromConfig(t *testing.T) {
  73. Convey("TestScanFromConfig", t, func() {
  74. params := url.Values{}
  75. params.Set("addr", "10.20.30.34:8902")
  76. res := new(struct {
  77. Code int `json:"code"`
  78. Message string `json:"message"`
  79. Data *canal.Results `json:"data"`
  80. })
  81. _ = requests("GET", fmt.Sprintf(_scanurl, _domain), "", params, &res)
  82. t.Logf("res:%+v", res.Data.Document)
  83. })
  84. }
  85. func TestApplyLists(t *testing.T) {
  86. Convey("TestApplyList", t, func() {
  87. params := url.Values{}
  88. //params.Set("addr", "172.16.33.243:3308")
  89. params.Set("project", "main.web-svr")
  90. params.Set("status", "1")
  91. res := new(struct {
  92. Code int `json:"code"`
  93. Message string `json:"message"`
  94. Data *canal.Paper `json:"data"`
  95. })
  96. _ = requests("GET", fmt.Sprintf(_applyurl, _domain), "", params, &res)
  97. t.Logf("res:%v", res.Data)
  98. })
  99. }
  100. func TestApplyConfigEdit(t *testing.T) {
  101. Convey("TestApplyConfigEdit", t, func() {
  102. params := url.Values{}
  103. params.Set("addr", "10.20.30.37:8902")
  104. params.Set("databases", _jsonstring)
  105. params.Set("mark", "fss")
  106. params.Set("user", "admin")
  107. params.Set("password", "admin")
  108. params.Set("project", "main.web-svr")
  109. params.Set("leader", "fss")
  110. res := Response{}
  111. _ = requests("POST", fmt.Sprintf(_canalediturl, _domain), "", params, &res)
  112. t.Logf("res:%v", res)
  113. })
  114. }
  115. func TestCanalAddrAll(t *testing.T) {
  116. Convey("TestCanalAddrAll", t, func() {
  117. params := url.Values{}
  118. res := new(struct {
  119. Code int `json:"code"`
  120. Message string `json:"message"`
  121. Data []string `json:"data"`
  122. })
  123. _ = requests("GET", fmt.Sprintf(_addrallurl, _domain), "", params, &res)
  124. t.Logf("res:%v", res.Data)
  125. })
  126. }