github.com/rumpl/bof@v23.0.0-rc.2+incompatible/daemon/container_unix_test.go (about) 1 //go:build linux || freebsd 2 // +build linux freebsd 3 4 package daemon 5 6 import ( 7 "testing" 8 9 "github.com/docker/docker/api/types" 10 containertypes "github.com/docker/docker/api/types/container" 11 "github.com/docker/docker/daemon/config" 12 "github.com/docker/go-connections/nat" 13 "gotest.tools/v3/assert" 14 ) 15 16 // TestContainerWarningHostAndPublishPorts that a warning is returned when setting network mode to host and specifying published ports. 17 // This should not be tested on Windows because Windows doesn't support "host" network mode. 18 func TestContainerWarningHostAndPublishPorts(t *testing.T) { 19 testCases := []struct { 20 ports nat.PortMap 21 warnings []string 22 }{ 23 {ports: nat.PortMap{}}, 24 {ports: nat.PortMap{ 25 "8080": []nat.PortBinding{{HostPort: "8989"}}, 26 }, warnings: []string{"Published ports are discarded when using host network mode"}}, 27 } 28 muteLogs() 29 30 for _, tc := range testCases { 31 hostConfig := &containertypes.HostConfig{ 32 Runtime: "runc", 33 NetworkMode: "host", 34 PortBindings: tc.ports, 35 } 36 cs := &config.Config{ 37 Runtimes: map[string]types.Runtime{"runc": {}}, 38 } 39 d := &Daemon{configStore: cs} 40 wrns, err := d.verifyContainerSettings(hostConfig, &containertypes.Config{}, false) 41 assert.NilError(t, err) 42 assert.DeepEqual(t, tc.warnings, wrns) 43 } 44 }