cat_indices_test.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. func TestCatIndices(t *testing.T) {
  10. client := setupTestClientAndCreateIndexAndAddDocs(t, SetDecoder(&strictDecoder{})) // , SetTraceLog(log.New(os.Stdout, "", 0)))
  11. ctx := context.Background()
  12. res, err := client.CatIndices().Columns("*").Do(ctx)
  13. if err != nil {
  14. t.Fatal(err)
  15. }
  16. if res == nil {
  17. t.Fatal("want response, have nil")
  18. }
  19. if len(res) == 0 {
  20. t.Fatalf("want response, have: %v", res)
  21. }
  22. if have := res[0].Index; have == "" {
  23. t.Fatalf("Index[0]: want != %q, have %q", "", have)
  24. }
  25. }
  26. // TestCatIndicesResponseRowAliasesMap tests if catIndicesResponseRowAliasesMap is declared
  27. func TestCatIndicesResponseRowAliasesMap(t *testing.T) {
  28. if catIndicesResponseRowAliasesMap == nil {
  29. t.Fatal("want catIndicesResponseRowAliasesMap to be not nil")
  30. }
  31. if len(catIndicesResponseRowAliasesMap) == 0 {
  32. t.Fatal("want catIndicesResponseRowAliasesMap to be not empty")
  33. }
  34. }
  35. // TestCatIndicesWithAliases makes a simple test (if ?h=h will be the same as ?h=health)
  36. func TestCatIndicesWithAliases(t *testing.T) {
  37. client := setupTestClientAndCreateIndexAndAddDocs(t, SetDecoder(&strictDecoder{})) // , SetTraceLog(log.New(os.Stdout, "", 0)))
  38. ctx := context.Background()
  39. res, err := client.CatIndices().Columns("h").Do(ctx)
  40. if err != nil {
  41. t.Fatal(err)
  42. }
  43. if res == nil {
  44. t.Fatal("want response, have nil")
  45. }
  46. if len(res) == 0 {
  47. t.Fatalf("want response, have: %v", res)
  48. }
  49. if have := res[0].Health; have == "" {
  50. t.Fatalf("Index[0]: want != %q, have %q", "", have)
  51. }
  52. }
  53. // TestCatIndicesWithAliases makes a test with a double-alias
  54. // asking `?h=rti` will fill one of the refresh.external_time/refresh.time fields (depending on elasticsearch version)
  55. func TestCatIndicesWithAliases_Double(t *testing.T) {
  56. client := setupTestClientAndCreateIndexAndAddDocs(t, SetDecoder(&strictDecoder{})) // , SetTraceLog(log.New(os.Stdout, "", 0)))
  57. ctx := context.Background()
  58. res, err := client.CatIndices().Columns("rti").Do(ctx)
  59. if err != nil {
  60. t.Fatal(err)
  61. }
  62. if res == nil {
  63. t.Fatal("want response, have nil")
  64. }
  65. if len(res) == 0 {
  66. t.Fatalf("want response, have: %v", res)
  67. }
  68. refreshTime := res[0].RefreshTime
  69. refreshExternalTime := res[0].RefreshExternalTime
  70. if refreshTime == "" && refreshExternalTime == "" {
  71. t.Fatalf("Index[0]: want one of [refreshTime or refreshExternalTime] be not empty")
  72. }
  73. }