TestAddressList_SeekTo verifies the behaviour of addressList.seekTo.
(t *testing.T)
| 200 | |
| 201 | // TestAddressList_SeekTo verifies the behaviour of addressList.seekTo. |
| 202 | func (s) TestAddressList_SeekTo(t *testing.T) { |
| 203 | addrs := []resolver.Address{ |
| 204 | { |
| 205 | Addr: "192.168.1.1", |
| 206 | ServerName: "test-host-1", |
| 207 | Attributes: attributes.New("key-1", "val-1"), |
| 208 | BalancerAttributes: attributes.New("bal-key-1", "bal-val-1"), |
| 209 | }, |
| 210 | { |
| 211 | Addr: "192.168.1.2", |
| 212 | ServerName: "test-host-2", |
| 213 | Attributes: attributes.New("key-2", "val-2"), |
| 214 | BalancerAttributes: attributes.New("bal-key-2", "bal-val-2"), |
| 215 | }, |
| 216 | { |
| 217 | Addr: "192.168.1.3", |
| 218 | ServerName: "test-host-3", |
| 219 | Attributes: attributes.New("key-3", "val-3"), |
| 220 | BalancerAttributes: attributes.New("bal-key-3", "bal-val-3"), |
| 221 | }, |
| 222 | } |
| 223 | |
| 224 | addressList := addressList{} |
| 225 | addressList.updateAddrs(addrs) |
| 226 | |
| 227 | // Try finding an address in the list. |
| 228 | key := resolver.Address{ |
| 229 | Addr: "192.168.1.2", |
| 230 | ServerName: "test-host-2", |
| 231 | Attributes: attributes.New("key-2", "val-2"), |
| 232 | BalancerAttributes: attributes.New("ignored", "bal-val-2"), |
| 233 | } |
| 234 | |
| 235 | if got, want := addressList.seekTo(key), true; got != want { |
| 236 | t.Errorf("addressList.seekTo(%v) = %t, want %t", key, got, want) |
| 237 | } |
| 238 | |
| 239 | // It should be possible to increment once more now that the pointer has advanced. |
| 240 | if got, want := addressList.increment(), true; got != want { |
| 241 | t.Errorf("addressList.increment() = %t, want %t", got, want) |
| 242 | } |
| 243 | |
| 244 | if got, want := addressList.increment(), false; got != want { |
| 245 | t.Errorf("addressList.increment() = %t, want %t", got, want) |
| 246 | } |
| 247 | |
| 248 | // Seek to the key again, it is behind the pointer now. |
| 249 | if got, want := addressList.seekTo(key), true; got != want { |
| 250 | t.Errorf("addressList.seekTo(%v) = %t, want %t", key, got, want) |
| 251 | } |
| 252 | |
| 253 | // Seek to a key not in the list. |
| 254 | key = resolver.Address{ |
| 255 | Addr: "192.168.1.5", |
| 256 | ServerName: "test-host-5", |
| 257 | Attributes: attributes.New("key-5", "val-5"), |
| 258 | BalancerAttributes: attributes.New("ignored", "bal-val-5"), |
| 259 | } |
nothing calls this directly
no test coverage detected