ctl_v3_endpoint_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2016 The etcd Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package e2e
  15. import (
  16. "net/url"
  17. "testing"
  18. )
  19. func TestCtlV3EndpointHealth(t *testing.T) { testCtl(t, endpointHealthTest, withQuorum()) }
  20. func TestCtlV3EndpointStatus(t *testing.T) { testCtl(t, endpointStatusTest, withQuorum()) }
  21. func endpointHealthTest(cx ctlCtx) {
  22. if err := ctlV3EndpointHealth(cx); err != nil {
  23. cx.t.Fatalf("endpointStatusTest ctlV3EndpointHealth error (%v)", err)
  24. }
  25. }
  26. func ctlV3EndpointHealth(cx ctlCtx) error {
  27. cmdArgs := append(cx.PrefixArgs(), "endpoint", "health")
  28. lines := make([]string, cx.epc.cfg.clusterSize)
  29. for i := range lines {
  30. lines[i] = "is healthy"
  31. }
  32. return spawnWithExpects(cmdArgs, lines...)
  33. }
  34. func endpointStatusTest(cx ctlCtx) {
  35. if err := ctlV3EndpointStatus(cx); err != nil {
  36. cx.t.Fatalf("endpointStatusTest ctlV3EndpointStatus error (%v)", err)
  37. }
  38. }
  39. func ctlV3EndpointStatus(cx ctlCtx) error {
  40. cmdArgs := append(cx.PrefixArgs(), "endpoint", "status")
  41. var eps []string
  42. for _, ep := range cx.epc.endpoints() {
  43. u, _ := url.Parse(ep)
  44. eps = append(eps, u.Host)
  45. }
  46. return spawnWithExpects(cmdArgs, eps...)
  47. }