cluster_health_test.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2012-2014 Oliver Eilhard. All rights reserved.
  2. // Use of this source code is governed by a MIT-license.
  3. // See http://olivere.mit-license.org/license.txt for details.
  4. package elastic
  5. import (
  6. "testing"
  7. )
  8. func TestClusterHealth(t *testing.T) {
  9. client := setupTestClientAndCreateIndex(t)
  10. // Get cluster health
  11. res, err := client.ClusterHealth().Index(testIndexName).Do()
  12. if err != nil {
  13. t.Fatal(err)
  14. }
  15. if res == nil {
  16. t.Fatalf("expected res to be != nil; got: %v", res)
  17. }
  18. if res.Status != "green" && res.Status != "red" && res.Status != "yellow" {
  19. t.Fatalf("expected status \"green\", \"red\", or \"yellow\"; got: %q", res.Status)
  20. }
  21. }
  22. func TestClusterHealthURLs(t *testing.T) {
  23. tests := []struct {
  24. Service *ClusterHealthService
  25. Expected string
  26. }{
  27. {
  28. Service: &ClusterHealthService{
  29. indices: []string{},
  30. },
  31. Expected: "/_cluster/health/",
  32. },
  33. {
  34. Service: &ClusterHealthService{
  35. indices: []string{"twitter"},
  36. },
  37. Expected: "/_cluster/health/twitter",
  38. },
  39. {
  40. Service: &ClusterHealthService{
  41. indices: []string{"twitter", "gplus"},
  42. },
  43. Expected: "/_cluster/health/twitter%2Cgplus",
  44. },
  45. {
  46. Service: &ClusterHealthService{
  47. indices: []string{"twitter"},
  48. waitForStatus: "yellow",
  49. },
  50. Expected: "/_cluster/health/twitter?wait_for_status=yellow",
  51. },
  52. }
  53. for _, test := range tests {
  54. got, err := test.Service.buildURL()
  55. if err != nil {
  56. t.Fatalf("expected no error; got: %v", err)
  57. }
  58. if got != test.Expected {
  59. t.Errorf("expected URL = %q; got: %q", test.Expected, got)
  60. }
  61. }
  62. }