(t *testing.T)
| 389 | } |
| 390 | |
| 391 | func TestUpdateHosts(t *testing.T) { |
| 392 | flags := newUpdateCommand(nil).Flags() |
| 393 | flags.Set("host-add", "example.net:2.2.2.2") |
| 394 | flags.Set("host-add", "ipv6.net:2001:db8:abc8::1") |
| 395 | // adding the special "host-gateway" target should work |
| 396 | flags.Set("host-add", "host.docker.internal:host-gateway") |
| 397 | // remove with ipv6 should work |
| 398 | flags.Set("host-rm", "example.net:2001:db8:abc8::1") |
| 399 | // just hostname should work as well |
| 400 | flags.Set("host-rm", "example.net") |
| 401 | // removing the special "host-gateway" target should work |
| 402 | flags.Set("host-rm", "gateway.docker.internal:host-gateway") |
| 403 | // bad format error |
| 404 | assert.ErrorContains(t, flags.Set("host-add", "$example.com$"), `bad format for add-host: "$example.com$"`) |
| 405 | |
| 406 | hosts := []string{"1.2.3.4 example.com", "4.3.2.1 example.org", "2001:db8:abc8::1 example.net", "gateway.docker.internal:host-gateway"} |
| 407 | expected := []string{"1.2.3.4 example.com", "4.3.2.1 example.org", "2.2.2.2 example.net", "2001:db8:abc8::1 ipv6.net", "host-gateway host.docker.internal"} |
| 408 | |
| 409 | err := updateHosts(flags, &hosts) |
| 410 | assert.NilError(t, err) |
| 411 | assert.Check(t, is.DeepEqual(expected, hosts)) |
| 412 | } |
| 413 | |
| 414 | func TestUpdateHostsPreservesOrder(t *testing.T) { |
| 415 | flags := newUpdateCommand(nil).Flags() |
nothing calls this directly
no test coverage detected
searching dependent graphs…