nodes_info_test.go 914 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 TestNodesInfo(t *testing.T) {
  10. client, err := NewClient()
  11. if err != nil {
  12. t.Fatal(err)
  13. }
  14. info, err := client.NodesInfo().Do(context.TODO())
  15. if err != nil {
  16. t.Fatal(err)
  17. }
  18. if info == nil {
  19. t.Fatal("expected nodes info")
  20. }
  21. if info.ClusterName == "" {
  22. t.Errorf("expected cluster name; got: %q", info.ClusterName)
  23. }
  24. if len(info.Nodes) == 0 {
  25. t.Errorf("expected some nodes; got: %d", len(info.Nodes))
  26. }
  27. for id, node := range info.Nodes {
  28. if id == "" {
  29. t.Errorf("expected node id; got: %q", id)
  30. }
  31. if node == nil {
  32. t.Fatalf("expected node info; got: %v", node)
  33. }
  34. if node.IP == "" {
  35. t.Errorf("expected node IP; got: %q", node.IP)
  36. }
  37. }
  38. }