indices_close_test.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright 2012-present 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. "context"
  7. "testing"
  8. )
  9. // TODO(oe): Find out why this test fails on Travis CI.
  10. /*
  11. func TestIndicesOpenAndClose(t *testing.T) {
  12. client := setupTestClient(t)
  13. // Create index
  14. createIndex, err := client.CreateIndex(testIndexName).Do(context.TODO())
  15. if err != nil {
  16. t.Fatal(err)
  17. }
  18. if !createIndex.Acknowledged {
  19. t.Errorf("expected CreateIndexResult.Acknowledged %v; got %v", true, createIndex.Acknowledged)
  20. }
  21. defer func() {
  22. // Delete index
  23. deleteIndex, err := client.DeleteIndex(testIndexName).Do(context.TODO())
  24. if err != nil {
  25. t.Fatal(err)
  26. }
  27. if !deleteIndex.Acknowledged {
  28. t.Errorf("expected DeleteIndexResult.Acknowledged %v; got %v", true, deleteIndex.Acknowledged)
  29. }
  30. }()
  31. waitForYellow := func() {
  32. // Wait for status yellow
  33. res, err := client.ClusterHealth().WaitForStatus("yellow").Timeout("15s").Do(context.TODO())
  34. if err != nil {
  35. t.Fatal(err)
  36. }
  37. if res != nil && res.TimedOut {
  38. t.Fatalf("cluster time out waiting for status %q", "yellow")
  39. }
  40. }
  41. // Wait for cluster
  42. waitForYellow()
  43. // Close index
  44. cresp, err := client.CloseIndex(testIndexName).Do(context.TODO())
  45. if err != nil {
  46. t.Fatal(err)
  47. }
  48. if !cresp.Acknowledged {
  49. t.Fatalf("expected close index of %q to be acknowledged\n", testIndexName)
  50. }
  51. // Wait for cluster
  52. waitForYellow()
  53. // Open index again
  54. oresp, err := client.OpenIndex(testIndexName).Do(context.TODO())
  55. if err != nil {
  56. t.Fatal(err)
  57. }
  58. if !oresp.Acknowledged {
  59. t.Fatalf("expected open index of %q to be acknowledged\n", testIndexName)
  60. }
  61. }
  62. */
  63. func TestIndicesCloseValidate(t *testing.T) {
  64. client := setupTestClient(t)
  65. // No index name -> fail with error
  66. res, err := NewIndicesCloseService(client).Do(context.TODO())
  67. if err == nil {
  68. t.Fatalf("expected IndicesClose to fail without index name")
  69. }
  70. if res != nil {
  71. t.Fatalf("expected result to be == nil; got: %v", res)
  72. }
  73. }