From f0ea7403289bcf13ae3ed1876c732b9b4827c214 Mon Sep 17 00:00:00 2001 From: Victor Marmol Date: Mon, 20 Apr 2015 11:46:36 -0700 Subject: [PATCH] Fix subcontainer queries in subcontainers. Queries for root were not being correctly diagnosed. --- events/handler.go | 2 +- events/handler_test.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/events/handler.go b/events/handler.go index 0548bf17..9d026503 100644 --- a/events/handler.go +++ b/events/handler.go @@ -174,7 +174,7 @@ func getMaxEventsReturned(request *Request, eSlice EventSlice) EventSlice { // equivalent func checkIfIsSubcontainer(request *Request, event *info.Event) bool { if request.IncludeSubcontainers == true { - return strings.HasPrefix(event.ContainerName+"/", request.ContainerName+"/") + return request.ContainerName == "/" || strings.HasPrefix(event.ContainerName+"/", request.ContainerName+"/") } return event.ContainerName == request.ContainerName } diff --git a/events/handler_test.go b/events/handler_test.go index e1336e91..f9f074b4 100644 --- a/events/handler_test.go +++ b/events/handler_test.go @@ -67,6 +67,8 @@ func ensureProperEventReturned(t *testing.T, expectedEvent *info.Event, eventObj func TestCheckIfIsSubcontainer(t *testing.T) { myRequest := NewRequest() myRequest.ContainerName = "/root" + rootRequest := NewRequest() + rootRequest.ContainerName = "/" sameContainerEvent := &info.Event{ ContainerName: "/root", @@ -78,6 +80,10 @@ func TestCheckIfIsSubcontainer(t *testing.T) { ContainerName: "/root-completely-different-container", } + if checkIfIsSubcontainer(rootRequest, sameContainerEvent) { + t.Errorf("should not have found %v to be a subcontainer of %v", + sameContainerEvent, rootRequest) + } if !checkIfIsSubcontainer(myRequest, sameContainerEvent) { t.Errorf("should have found %v and %v had the same container name", myRequest, sameContainerEvent) @@ -87,8 +93,13 @@ func TestCheckIfIsSubcontainer(t *testing.T) { myRequest, subContainerEvent) } + rootRequest.IncludeSubcontainers = true myRequest.IncludeSubcontainers = true + if !checkIfIsSubcontainer(rootRequest, sameContainerEvent) { + t.Errorf("should have found %v to be a subcontainer of %v", + sameContainerEvent.ContainerName, rootRequest.ContainerName) + } if !checkIfIsSubcontainer(myRequest, sameContainerEvent) { t.Errorf("should have found %v and %v had the same container", myRequest.ContainerName, sameContainerEvent.ContainerName)