fix(docker): host network_mode port selection

This commit is contained in:
yusing
2025-05-07 23:26:51 +08:00
parent 4daefa19d1
commit 1e80ad2a44
3 changed files with 48 additions and 6 deletions

View File

@@ -41,3 +41,38 @@ func TestContainerExplicit(t *testing.T) {
})
}
}
func TestContainerHostNetworkMode(t *testing.T) {
tests := []struct {
name string
container *container.SummaryTrimmed
isHostNetworkMode bool
}{
{
name: "host network mode",
container: &container.SummaryTrimmed{
Names: []string{"test"},
State: "test",
HostConfig: struct {
NetworkMode string "json:\",omitempty\""
}{
NetworkMode: "host",
},
},
isHostNetworkMode: true,
},
{
name: "not host network mode",
container: &container.SummaryTrimmed{
Names: []string{"test"},
State: "test",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := FromDocker(tt.container, "")
ExpectEqual(t, c.IsHostNetworkMode, tt.isHostNetworkMode)
})
}
}