MCPcopy Create free account
hub / github.com/docker/cli / TestUpdateHosts

Function TestUpdateHosts

cli/command/service/update_test.go:391–412  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

389}
390
391func 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
414func TestUpdateHostsPreservesOrder(t *testing.T) {
415 flags := newUpdateCommand(nil).Flags()

Callers

nothing calls this directly

Calls 3

updateHostsFunction · 0.85
newUpdateCommandFunction · 0.70
SetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…