indices_get_field_mapping_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. "testing"
  7. )
  8. func TestIndicesGetFieldMappingURL(t *testing.T) {
  9. client := setupTestClientAndCreateIndex(t)
  10. tests := []struct {
  11. Indices []string
  12. Types []string
  13. Fields []string
  14. Expected string
  15. }{
  16. {
  17. []string{},
  18. []string{},
  19. []string{},
  20. "/_all/_mapping/_all/field/%2A",
  21. },
  22. {
  23. []string{},
  24. []string{"tweet"},
  25. []string{"message"},
  26. "/_all/_mapping/tweet/field/message",
  27. },
  28. {
  29. []string{"twitter"},
  30. []string{"tweet"},
  31. []string{"*.id"},
  32. "/twitter/_mapping/tweet/field/%2A.id",
  33. },
  34. {
  35. []string{"store-1", "store-2"},
  36. []string{"tweet", "user"},
  37. []string{"message", "*.id"},
  38. "/store-1%2Cstore-2/_mapping/tweet%2Cuser/field/message%2C%2A.id",
  39. },
  40. }
  41. for _, test := range tests {
  42. path, _, err := client.GetFieldMapping().Index(test.Indices...).Type(test.Types...).Field(test.Fields...).buildURL()
  43. if err != nil {
  44. t.Fatal(err)
  45. }
  46. if path != test.Expected {
  47. t.Errorf("expected %q; got: %q", test.Expected, path)
  48. }
  49. }
  50. }