cat_aliases_test.go 1.3 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. "context"
  7. "testing"
  8. )
  9. func TestCatAliases(t *testing.T) {
  10. client := setupTestClientAndCreateIndexAndAddDocs(t, SetDecoder(&strictDecoder{})) //, SetTraceLog(log.New(os.Stdout, "", 0)))
  11. ctx := context.Background()
  12. // Add two aliases
  13. _, err := client.Alias().
  14. Add(testIndexName, testAliasName).
  15. Action(NewAliasAddAction(testAliasName2).Index(testIndexName2)).
  16. Do(context.TODO())
  17. if err != nil {
  18. t.Fatal(err)
  19. }
  20. defer func() {
  21. // Remove aliases
  22. client.Alias().
  23. Remove(testIndexName, testAliasName).
  24. Remove(testIndexName2, testAliasName2).
  25. Do(context.TODO())
  26. }()
  27. // Check all aliases
  28. res, err := client.CatAliases().Pretty(true).Columns("*").Do(ctx)
  29. if err != nil {
  30. t.Fatal(err)
  31. }
  32. if res == nil {
  33. t.Fatal("want response, have nil")
  34. }
  35. if want, have := 2, len(res); want != have {
  36. t.Fatalf("want len=%d, have %d", want, have)
  37. }
  38. // Check a named alias
  39. res, err = client.CatAliases().Alias(testAliasName).Pretty(true).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 want, have := 1, len(res); want != have {
  47. t.Fatalf("want len=%d, have %d", want, have)
  48. }
  49. }