From 7d6a75b342ed9053a003114d526ad73ff6d16d79 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 23 Jul 2025 15:34:46 +0200 Subject: [PATCH] runconfig: update fixtures for TestDecodeContainerConfig Signed-off-by: Sebastiaan van Stijn (cherry picked from commit a401c0c04642cb7b2b489ad96a4cdf11ce4820eb) Signed-off-by: Sebastiaan van Stijn --- runconfig/config_test.go | 38 +++++- .../fixtures/unix/container_config_1_19.json | 58 ---------- .../fixtures/unix/container_config_1_24.json | 108 ++++++++++++++++++ .../windows/container_config_1_19.json | 58 ---------- .../windows/container_config_1_24.json | 108 ++++++++++++++++++ 5 files changed, 248 insertions(+), 122 deletions(-) delete mode 100644 runconfig/fixtures/unix/container_config_1_19.json create mode 100644 runconfig/fixtures/unix/container_config_1_24.json delete mode 100644 runconfig/fixtures/windows/container_config_1_19.json create mode 100644 runconfig/fixtures/windows/container_config_1_24.json diff --git a/runconfig/config_test.go b/runconfig/config_test.go index c247e06170..a21fac1ea1 100644 --- a/runconfig/config_test.go +++ b/runconfig/config_test.go @@ -14,6 +14,33 @@ import ( is "gotest.tools/v3/assert/cmp" ) +/* +TestDecodeContainerConfig validates unmarshaling a container config fixture. + +Fixture created using; + + docker run -it \ + --cap-add=NET_ADMIN \ + --cap-drop=MKNOD \ + --cpu-shares=512 \ + --cpuset-cpus=0,1 \ + --dns=8.8.8.8 \ + --entrypoint bash \ + --label com.example.license=GPL \ + --label com.example.vendor=Acme \ + --label com.example.version=1.0 \ + --link=redis3:redis \ + --log-driver=json-file \ + --mac-address="12:34:56:78:9a:bc" \ + --memory=4M \ + --network=bridge \ + --volumes-from=other:ro \ + --volumes-from=parent \ + -p=11022:22/tcp \ + -v /tmp \ + -v /tmp:/tmp \ + ubuntu date +*/ func TestDecodeContainerConfig(t *testing.T) { type testCase struct { doc string @@ -22,18 +49,17 @@ func TestDecodeContainerConfig(t *testing.T) { entrypoint []string } - // FIXME (thaJeztah): update fixtures for more current versions. tests := []testCase{ { - doc: "API 1.19 windows", + doc: "API 1.24 windows", imgName: "windows", - fixture: "fixtures/windows/container_config_1_19.json", + fixture: "fixtures/windows/container_config_1_24.json", entrypoint: []string{"cmd"}, }, { - doc: "API 1.19 unix", + doc: "API 1.24 unix", imgName: "ubuntu", - fixture: "fixtures/unix/container_config_1_19.json", + fixture: "fixtures/unix/container_config_1_24.json", entrypoint: []string{"bash"}, }, } @@ -49,7 +75,7 @@ func TestDecodeContainerConfig(t *testing.T) { assert.Check(t, is.Equal(c.Image, tc.imgName)) assert.Check(t, is.DeepEqual([]string(c.Entrypoint), tc.entrypoint)) - var expected int64 = 1000 + var expected int64 = 4194304 assert.Check(t, is.Equal(h.Memory, expected)) }) } diff --git a/runconfig/fixtures/unix/container_config_1_19.json b/runconfig/fixtures/unix/container_config_1_19.json deleted file mode 100644 index de49cf3242..0000000000 --- a/runconfig/fixtures/unix/container_config_1_19.json +++ /dev/null @@ -1,58 +0,0 @@ -{ - "Hostname": "", - "Domainname": "", - "User": "", - "AttachStdin": false, - "AttachStdout": true, - "AttachStderr": true, - "Tty": false, - "OpenStdin": false, - "StdinOnce": false, - "Env": null, - "Cmd": [ - "date" - ], - "Entrypoint": "bash", - "Image": "ubuntu", - "Labels": { - "com.example.vendor": "Acme", - "com.example.license": "GPL", - "com.example.version": "1.0" - }, - "Volumes": { - "/tmp": {} - }, - "WorkingDir": "", - "NetworkDisabled": false, - "MacAddress": "12:34:56:78:9a:bc", - "ExposedPorts": { - "22/tcp": {} - }, - "HostConfig": { - "Binds": ["/tmp:/tmp"], - "Links": ["redis3:redis"], - "LxcConf": {"lxc.utsname":"docker"}, - "Memory": 1000, - "MemorySwap": 0, - "CpuShares": 512, - "CpusetCpus": "0,1", - "PortBindings": { "22/tcp": [{ "HostPort": "11022" }] }, - "PublishAllPorts": false, - "Privileged": false, - "ReadonlyRootfs": false, - "Dns": ["8.8.8.8"], - "DnsSearch": [""], - "DnsOptions": [""], - "ExtraHosts": null, - "VolumesFrom": ["parent", "other:ro"], - "CapAdd": ["NET_ADMIN"], - "CapDrop": ["MKNOD"], - "RestartPolicy": { "Name": "", "MaximumRetryCount": 0 }, - "NetworkMode": "bridge", - "Devices": [], - "Ulimits": [{}], - "LogConfig": { "Type": "json-file", "Config": {} }, - "SecurityOpt": [""], - "CgroupParent": "" - } -} diff --git a/runconfig/fixtures/unix/container_config_1_24.json b/runconfig/fixtures/unix/container_config_1_24.json new file mode 100644 index 0000000000..f16fb8072d --- /dev/null +++ b/runconfig/fixtures/unix/container_config_1_24.json @@ -0,0 +1,108 @@ +{ + "AttachStderr": true, + "AttachStdin": true, + "AttachStdout": true, + "Cmd": ["date"], + "Domainname": "", + "Entrypoint": ["bash"], + "Env": [], + "ExposedPorts": { + "22/tcp": {} + }, + "HostConfig": { + "AutoRemove": false, + "Binds": ["/tmp:/tmp"], + "BlkioDeviceReadBps": null, + "BlkioDeviceReadIOps": null, + "BlkioDeviceWriteBps": null, + "BlkioDeviceWriteIOps": null, + "BlkioWeight": 0, + "BlkioWeightDevice": null, + "CapAdd": ["NET_ADMIN"], + "CapDrop": ["MKNOD"], + "Cgroup": "", + "CgroupParent": "", + "ConsoleSize": [0,0], + "ContainerIDFile": "", + "CpuCount": 0, + "CpuPercent": 0, + "CpuPeriod": 0, + "CpuQuota": 0, + "CpuShares": 512, + "CpusetCpus": "0,1", + "CpusetMems": "", + "Devices": [], + "DiskQuota": 0, + "Dns": ["8.8.8.8"], + "DnsOptions": [], + "DnsSearch": [], + "ExtraHosts": null, + "GroupAdd": null, + "IOMaximumBandwidth": 0, + "IOMaximumIOps": 0, + "IpcMode": "", + "Isolation": "", + "KernelMemory": 0, + "Links": [ + "redis3:redis" + ], + "LogConfig": { + "Config": {}, + "Type": "json-file" + }, + "Memory": 4194304, + "MemoryReservation": 0, + "MemorySwap": 0, + "MemorySwappiness": -1, + "NetworkMode": "bridge", + "OomKillDisable": false, + "OomScoreAdj": 0, + "PidMode": "", + "PidsLimit": 0, + "PortBindings": { + "22/tcp": [ + { + "HostIp": "", + "HostPort": "11022" + } + ] + }, + "Privileged": false, + "PublishAllPorts": false, + "ReadonlyRootfs": false, + "RestartPolicy": { + "MaximumRetryCount": 0, + "Name": "no" + }, + "SecurityOpt": null, + "ShmSize": 0, + "UTSMode": "", + "Ulimits": null, + "UsernsMode": "", + "VolumeDriver": "", + "VolumesFrom": [ + "parent", + "other:ro" + ] + }, + "Hostname": "", + "Image": "ubuntu", + "Labels": { + "com.example.license": "GPL", + "com.example.vendor": "Acme", + "com.example.version": "1.0" + }, + "MacAddress": "12:34:56:78:9a:bc", + "NetworkingConfig": { + "EndpointsConfig": {} + }, + "OnBuild": null, + "OpenStdin": true, + "StdinOnce": true, + "Tty": true, + "User": "", + "Volumes": { + "/tmp": {} + }, + "WorkingDir": "" +} diff --git a/runconfig/fixtures/windows/container_config_1_19.json b/runconfig/fixtures/windows/container_config_1_19.json deleted file mode 100644 index 724320c760..0000000000 --- a/runconfig/fixtures/windows/container_config_1_19.json +++ /dev/null @@ -1,58 +0,0 @@ -{ - "Hostname": "", - "Domainname": "", - "User": "", - "AttachStdin": false, - "AttachStdout": true, - "AttachStderr": true, - "Tty": false, - "OpenStdin": false, - "StdinOnce": false, - "Env": null, - "Cmd": [ - "date" - ], - "Entrypoint": "cmd", - "Image": "windows", - "Labels": { - "com.example.vendor": "Acme", - "com.example.license": "GPL", - "com.example.version": "1.0" - }, - "Volumes": { - "c:/windows": {} - }, - "WorkingDir": "", - "NetworkDisabled": false, - "MacAddress": "12:34:56:78:9a:bc", - "ExposedPorts": { - "22/tcp": {} - }, - "HostConfig": { - "Binds": ["c:/windows:d:/tmp"], - "Links": ["redis3:redis"], - "LxcConf": {"lxc.utsname":"docker"}, - "Memory": 1000, - "MemorySwap": 0, - "CpuShares": 512, - "CpusetCpus": "0,1", - "PortBindings": { "22/tcp": [{ "HostPort": "11022" }] }, - "PublishAllPorts": false, - "Privileged": false, - "ReadonlyRootfs": false, - "Dns": ["8.8.8.8"], - "DnsSearch": [""], - "DnsOptions": [""], - "ExtraHosts": null, - "VolumesFrom": ["parent", "other:ro"], - "CapAdd": ["NET_ADMIN"], - "CapDrop": ["MKNOD"], - "RestartPolicy": { "Name": "", "MaximumRetryCount": 0 }, - "NetworkMode": "default", - "Devices": [], - "Ulimits": [{}], - "LogConfig": { "Type": "json-file", "Config": {} }, - "SecurityOpt": [""], - "CgroupParent": "" - } -} diff --git a/runconfig/fixtures/windows/container_config_1_24.json b/runconfig/fixtures/windows/container_config_1_24.json new file mode 100644 index 0000000000..8707c82e2c --- /dev/null +++ b/runconfig/fixtures/windows/container_config_1_24.json @@ -0,0 +1,108 @@ +{ + "AttachStderr": true, + "AttachStdin": true, + "AttachStdout": true, + "Cmd": ["date"], + "Domainname": "", + "Entrypoint": ["cmd"], + "Env": [], + "ExposedPorts": { + "22/tcp": {} + }, + "HostConfig": { + "AutoRemove": false, + "Binds": ["c:/windows:/tmp"], + "BlkioDeviceReadBps": null, + "BlkioDeviceReadIOps": null, + "BlkioDeviceWriteBps": null, + "BlkioDeviceWriteIOps": null, + "BlkioWeight": 0, + "BlkioWeightDevice": null, + "CapAdd": ["NET_ADMIN"], + "CapDrop": ["MKNOD"], + "Cgroup": "", + "CgroupParent": "", + "ConsoleSize": [0,0], + "ContainerIDFile": "", + "CpuCount": 0, + "CpuPercent": 0, + "CpuPeriod": 0, + "CpuQuota": 0, + "CpuShares": 512, + "CpusetCpus": "0,1", + "CpusetMems": "", + "Devices": [], + "DiskQuota": 0, + "Dns": ["8.8.8.8"], + "DnsOptions": [], + "DnsSearch": [], + "ExtraHosts": null, + "GroupAdd": null, + "IOMaximumBandwidth": 0, + "IOMaximumIOps": 0, + "IpcMode": "", + "Isolation": "", + "KernelMemory": 0, + "Links": [ + "redis3:redis" + ], + "LogConfig": { + "Config": {}, + "Type": "json-file" + }, + "Memory": 4194304, + "MemoryReservation": 0, + "MemorySwap": 0, + "MemorySwappiness": -1, + "NetworkMode": "bridge", + "OomKillDisable": false, + "OomScoreAdj": 0, + "PidMode": "", + "PidsLimit": 0, + "PortBindings": { + "22/tcp": [ + { + "HostIp": "", + "HostPort": "11022" + } + ] + }, + "Privileged": false, + "PublishAllPorts": false, + "ReadonlyRootfs": false, + "RestartPolicy": { + "MaximumRetryCount": 0, + "Name": "no" + }, + "SecurityOpt": null, + "ShmSize": 0, + "UTSMode": "", + "Ulimits": null, + "UsernsMode": "", + "VolumeDriver": "", + "VolumesFrom": [ + "parent", + "other:ro" + ] + }, + "Hostname": "", + "Image": "windows", + "Labels": { + "com.example.license": "GPL", + "com.example.vendor": "Acme", + "com.example.version": "1.0" + }, + "MacAddress": "12:34:56:78:9a:bc", + "NetworkingConfig": { + "EndpointsConfig": {} + }, + "OnBuild": null, + "OpenStdin": true, + "StdinOnce": true, + "Tty": true, + "User": "", + "Volumes": { + "c:/windows": {} + }, + "WorkingDir": "" +}