indices_get_settings_test.go 1.9 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 TestIndexGetSettingsURL(t *testing.T) {
  10. client := setupTestClientAndCreateIndex(t)
  11. tests := []struct {
  12. Indices []string
  13. Names []string
  14. Expected string
  15. }{
  16. {
  17. []string{},
  18. []string{},
  19. "/_all/_settings",
  20. },
  21. {
  22. []string{},
  23. []string{"index.merge.*"},
  24. "/_all/_settings/index.merge.%2A",
  25. },
  26. {
  27. []string{"twitter-*"},
  28. []string{"index.merge.*", "_settings"},
  29. "/twitter-%2A/_settings/index.merge.%2A%2C_settings",
  30. },
  31. {
  32. []string{"store-1", "store-2"},
  33. []string{"index.merge.*", "_settings"},
  34. "/store-1%2Cstore-2/_settings/index.merge.%2A%2C_settings",
  35. },
  36. }
  37. for _, test := range tests {
  38. path, _, err := client.IndexGetSettings().Index(test.Indices...).Name(test.Names...).buildURL()
  39. if err != nil {
  40. t.Fatal(err)
  41. }
  42. if path != test.Expected {
  43. t.Errorf("expected %q; got: %q", test.Expected, path)
  44. }
  45. }
  46. }
  47. func TestIndexGetSettingsService(t *testing.T) {
  48. client := setupTestClientAndCreateIndex(t)
  49. esversion, err := client.ElasticsearchVersion(DefaultURL)
  50. if err != nil {
  51. t.Fatal(err)
  52. }
  53. if esversion < "1.4.0" {
  54. t.Skip("Index Get API is available since 1.4")
  55. return
  56. }
  57. res, err := client.IndexGetSettings().Index(testIndexName).Do(context.TODO())
  58. if err != nil {
  59. t.Fatal(err)
  60. }
  61. if res == nil {
  62. t.Fatalf("expected result; got: %v", res)
  63. }
  64. info, found := res[testIndexName]
  65. if !found {
  66. t.Fatalf("expected index %q to be found; got: %v", testIndexName, found)
  67. }
  68. if info == nil {
  69. t.Fatalf("expected index %q to be != nil; got: %v", testIndexName, info)
  70. }
  71. if info.Settings == nil {
  72. t.Fatalf("expected index settings of %q to be != nil; got: %v", testIndexName, info.Settings)
  73. }
  74. }