nolint:gocyclo
(t *testing.T)
| 88 | |
| 89 | //nolint:gocyclo |
| 90 | func TestClientConfiguration(t *testing.T) { |
| 91 | t.Parallel() |
| 92 | |
| 93 | t.Run("With empty", func(t *testing.T) { |
| 94 | c, err := New() |
| 95 | |
| 96 | if err != nil { |
| 97 | t.Errorf("Unexpected error: %s", err) |
| 98 | } |
| 99 | |
| 100 | u := c.Transport.(*elastictransport.Client).URLs()[0].String() |
| 101 | |
| 102 | if u != defaultURL { |
| 103 | t.Errorf("Unexpected URL, want=%s, got=%s", defaultURL, u) |
| 104 | } |
| 105 | }) |
| 106 | |
| 107 | t.Run("With URL from Addresses", func(t *testing.T) { |
| 108 | c, err := New(WithAddresses("http://localhost:8080//")) |
| 109 | if err != nil { |
| 110 | t.Fatalf("Unexpected error: %s", err) |
| 111 | } |
| 112 | |
| 113 | u := c.Transport.(*elastictransport.Client).URLs()[0].String() |
| 114 | |
| 115 | if u != "http://localhost:8080" { |
| 116 | t.Errorf("Unexpected URL, want=http://localhost:8080, got=%s", u) |
| 117 | } |
| 118 | }) |
| 119 | |
| 120 | t.Run("With URL from environment", func(t *testing.T) { |
| 121 | os.Setenv("ELASTICSEARCH_URL", "http://example.com") |
| 122 | defer func() { os.Setenv("ELASTICSEARCH_URL", "") }() |
| 123 | |
| 124 | c, err := New() |
| 125 | if err != nil { |
| 126 | t.Errorf("Unexpected error: %s", err) |
| 127 | } |
| 128 | |
| 129 | u := c.Transport.(*elastictransport.Client).URLs()[0].String() |
| 130 | |
| 131 | if u != "http://example.com" { |
| 132 | t.Errorf("Unexpected URL, want=http://example.com, got=%s", u) |
| 133 | } |
| 134 | }) |
| 135 | |
| 136 | t.Run("With URL from environment and cfg.Addresses", func(t *testing.T) { |
| 137 | os.Setenv("ELASTICSEARCH_URL", "http://example.com") |
| 138 | defer func() { os.Setenv("ELASTICSEARCH_URL", "") }() |
| 139 | |
| 140 | c, err := New(WithAddresses("http://localhost:8080//")) |
| 141 | if err != nil { |
| 142 | t.Fatalf("Unexpected error: %s", err) |
| 143 | } |
| 144 | |
| 145 | u := c.Transport.(*elastictransport.Client).URLs()[0].String() |
| 146 | |
| 147 | if u != "http://localhost:8080" { |
nothing calls this directly
no test coverage detected