client_v2_test.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package conf
  2. import (
  3. "net/http"
  4. "testing"
  5. )
  6. func TestConf_client2(t *testing.T) {
  7. c := initConf2()
  8. testClientValue2(t, c)
  9. testCheckVersion2(t, c)
  10. testDownload2(t, c)
  11. testGetConfig2(t, c)
  12. }
  13. func testClientValue2(t *testing.T, c *Client) {
  14. key := "test.toml"
  15. testDownload2(t, c)
  16. test1, ok := c.Value2(key)
  17. if !ok {
  18. t.Errorf("client.Value() error")
  19. t.FailNow()
  20. }
  21. t.Logf("get the result test1(%s)", test1)
  22. }
  23. func testCheckVersion2(t *testing.T, c *Client) {
  24. unknow := &ver{Version: _unknownVersion}
  25. ver, err := c.checkVersion2(unknow)
  26. if err != nil {
  27. t.Errorf("client.checkVersion() error(%v) ver(%d)", err, ver)
  28. t.FailNow()
  29. }
  30. }
  31. func testDownload2(t *testing.T, c *Client) {
  32. ver := &ver{Version: 13}
  33. if err := c.download2(ver, true); err != nil {
  34. t.Errorf("client.downloda() error(%v) ", err)
  35. t.FailNow()
  36. }
  37. }
  38. func testGetConfig2(t *testing.T, c *Client) {
  39. ver := &ver{Version: 13}
  40. data, err := c.getConfig2(ver)
  41. if err != nil {
  42. t.Errorf("client.getconfiig() error(%v)", err)
  43. t.FailNow()
  44. }
  45. t.Logf("get the result data(%v)", data)
  46. }
  47. func TestClient_Create(t *testing.T) {
  48. c := initConf2()
  49. if err := c.Create("zjx11.toml", "test comment", "zjx", "mark"); err != nil {
  50. t.Errorf("client.Create() error(%v)", err)
  51. t.FailNow()
  52. }
  53. }
  54. func TestClient_Update(t *testing.T) {
  55. c := initConf2()
  56. if err := c.Update(21, "test comment11", "zjx", "mark"); err != nil {
  57. t.Errorf("client.Create() error(%v)", err)
  58. t.FailNow()
  59. }
  60. }
  61. func TestClient_ConfIng(t *testing.T) {
  62. c := initConf2()
  63. if val, err := c.ConfIng("zjx1.toml"); err != nil {
  64. t.Errorf("client.Create() error(%v)", err)
  65. t.FailNow()
  66. } else {
  67. t.Logf("%v", val)
  68. }
  69. }
  70. func initConf2() (c *Client) {
  71. conf.Addr = "172.16.33.134:9011"
  72. conf.Host = "testHost"
  73. conf.Path = "./"
  74. conf.AppID = "main.common-arch.msm-service"
  75. conf.Svr = "msm-service"
  76. conf.Ver = "server-1"
  77. conf.DeployEnv = "dev"
  78. conf.Zone = "sh001"
  79. conf.Token = "45338e440bdc11e880ce02420a0a0204"
  80. conf.TreeID = "2888"
  81. c = &Client{
  82. httpCli: &http.Client{Timeout: _httpTimeout},
  83. event: make(chan string, 10),
  84. }
  85. return
  86. }