Merge pull request #658 from vmarmol/events2

Fix subcontainer queries in subcontainers.
This commit is contained in:
Rohit Jnagal 2015-04-21 13:58:54 -07:00
commit 9a0b9b4f4a
2 changed files with 12 additions and 1 deletions

View File

@ -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
}

View File

@ -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)