Skip to content

Commit

Permalink
Fix subcontainer queries in subcontainers.
Browse files Browse the repository at this point in the history
Queries for root were not being correctly diagnosed.
  • Loading branch information
vmarmol committed Apr 21, 2015
1 parent 44848b9 commit f0ea740
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion events/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
11 changes: 11 additions & 0 deletions events/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit f0ea740

Please sign in to comment.