mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fix filter on expose and publish
- Add tests to ensure it's working - Rename variables for better clarification - Fix validation test - Remove wrong filter assertion based on publish filter - Change port on test Signed-off-by: Jaime Cepeda <jcepedavillamayor@gmail.com>
This commit is contained in:
parent
c85b2e5c30
commit
f48b7d66f3
2 changed files with 27 additions and 16 deletions
|
@ -551,23 +551,19 @@ func includeContainerInList(container *container.Snapshot, ctx *listContext) ite
|
|||
}
|
||||
}
|
||||
|
||||
if len(ctx.publish) > 0 {
|
||||
shouldSkip := true
|
||||
for port := range ctx.publish {
|
||||
if _, ok := container.PortBindings[port]; ok {
|
||||
if len(ctx.expose) > 0 || len(ctx.publish) > 0 {
|
||||
var (
|
||||
shouldSkip bool = true
|
||||
publishedPort nat.Port
|
||||
exposedPort nat.Port
|
||||
)
|
||||
for _, port := range container.Ports {
|
||||
publishedPort = nat.Port(fmt.Sprintf("%d/%s", port.PublicPort, port.Type))
|
||||
exposedPort = nat.Port(fmt.Sprintf("%d/%s", port.PrivatePort, port.Type))
|
||||
if ok := ctx.publish[publishedPort]; ok {
|
||||
shouldSkip = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if shouldSkip {
|
||||
return excludeContainer
|
||||
}
|
||||
}
|
||||
|
||||
if len(ctx.expose) > 0 {
|
||||
shouldSkip := true
|
||||
for port := range ctx.expose {
|
||||
if _, ok := container.ExposedPorts[port]; ok {
|
||||
} else if ok := ctx.expose[exposedPort]; ok {
|
||||
shouldSkip = false
|
||||
break
|
||||
}
|
||||
|
|
|
@ -816,29 +816,44 @@ func (s *DockerSuite) TestPsListContainersFilterPorts(c *testing.T) {
|
|||
out, _ = dockerCmd(c, "run", "-d", "--expose=8080", "busybox", "top")
|
||||
id2 := strings.TrimSpace(out)
|
||||
|
||||
out, _ = dockerCmd(c, "run", "-d", "-p", "1090:90", "busybox", "top")
|
||||
id3 := strings.TrimSpace(out)
|
||||
|
||||
out, _ = dockerCmd(c, "ps", "--no-trunc", "-q")
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), id1))
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), id2))
|
||||
assert.Assert(c, strings.Contains(strings.TrimSpace(out), id3))
|
||||
|
||||
out, _ = dockerCmd(c, "ps", "--no-trunc", "-q", "--filter", "publish=80-8080/udp")
|
||||
assert.Assert(c, strings.TrimSpace(out) != id1)
|
||||
assert.Assert(c, strings.TrimSpace(out) != id2)
|
||||
assert.Assert(c, strings.TrimSpace(out) != id3)
|
||||
|
||||
out, _ = dockerCmd(c, "ps", "--no-trunc", "-q", "--filter", "expose=8081")
|
||||
assert.Assert(c, strings.TrimSpace(out) != id1)
|
||||
assert.Assert(c, strings.TrimSpace(out) != id2)
|
||||
assert.Assert(c, strings.TrimSpace(out) != id3)
|
||||
|
||||
out, _ = dockerCmd(c, "ps", "--no-trunc", "-q", "--filter", "publish=80-81")
|
||||
assert.Equal(c, strings.TrimSpace(out), id1)
|
||||
assert.Assert(c, strings.TrimSpace(out) != id1)
|
||||
assert.Assert(c, strings.TrimSpace(out) != id2)
|
||||
assert.Assert(c, strings.TrimSpace(out) != id3)
|
||||
|
||||
out, _ = dockerCmd(c, "ps", "--no-trunc", "-q", "--filter", "expose=80/tcp")
|
||||
assert.Equal(c, strings.TrimSpace(out), id1)
|
||||
assert.Assert(c, strings.TrimSpace(out) != id2)
|
||||
assert.Assert(c, strings.TrimSpace(out) != id3)
|
||||
|
||||
out, _ = dockerCmd(c, "ps", "--no-trunc", "-q", "--filter", "publish=1090")
|
||||
assert.Assert(c, strings.TrimSpace(out) != id1)
|
||||
assert.Assert(c, strings.TrimSpace(out) != id2)
|
||||
assert.Equal(c, strings.TrimSpace(out), id3)
|
||||
|
||||
out, _ = dockerCmd(c, "ps", "--no-trunc", "-q", "--filter", "expose=8080/tcp")
|
||||
out = RemoveOutputForExistingElements(out, existingContainers)
|
||||
assert.Assert(c, strings.TrimSpace(out) != id1)
|
||||
assert.Equal(c, strings.TrimSpace(out), id2)
|
||||
assert.Assert(c, strings.TrimSpace(out) != id3)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPsNotShowLinknamesOfDeletedContainer(c *testing.T) {
|
||||
|
|
Loading…
Add table
Reference in a new issue