2017-11-15 09:44:49 -05:00
|
|
|
// +build linux freebsd
|
|
|
|
|
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
containertypes "github.com/docker/docker/api/types/container"
|
|
|
|
"github.com/docker/docker/daemon/config"
|
|
|
|
"github.com/docker/go-connections/nat"
|
2018-06-11 09:32:11 -04:00
|
|
|
"gotest.tools/assert"
|
2017-11-15 09:44:49 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// TestContainerWarningHostAndPublishPorts that a warning is returned when setting network mode to host and specifying published ports.
|
|
|
|
// This should not be tested on Windows because Windows doesn't support "host" network mode.
|
|
|
|
func TestContainerWarningHostAndPublishPorts(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
ports nat.PortMap
|
|
|
|
warnings []string
|
|
|
|
}{
|
|
|
|
{ports: nat.PortMap{}},
|
|
|
|
{ports: nat.PortMap{
|
|
|
|
"8080": []nat.PortBinding{{HostPort: "8989"}},
|
|
|
|
}, warnings: []string{"Published ports are discarded when using host network mode"}},
|
|
|
|
}
|
2019-10-16 20:47:37 -04:00
|
|
|
muteLogs()
|
2017-11-15 09:44:49 -05:00
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
hostConfig := &containertypes.HostConfig{
|
|
|
|
Runtime: "runc",
|
|
|
|
NetworkMode: "host",
|
|
|
|
PortBindings: tc.ports,
|
|
|
|
}
|
|
|
|
cs := &config.Config{
|
|
|
|
CommonUnixConfig: config.CommonUnixConfig{
|
|
|
|
Runtimes: map[string]types.Runtime{"runc": {}},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
d := &Daemon{configStore: cs}
|
|
|
|
wrns, err := d.verifyContainerSettings("", hostConfig, &containertypes.Config{}, false)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.DeepEqual(t, tc.warnings, wrns)
|
2017-11-15 09:44:49 -05:00
|
|
|
}
|
|
|
|
}
|