Merge pull request #289 from vmarmol/docker

Fix logic for deciding if Docker container was not found.
This commit is contained in:
Rohit Jnagal 2014-10-29 13:41:45 -07:00
commit 84da7270da
2 changed files with 25 additions and 3 deletions

View File

@ -275,12 +275,11 @@ func (self *manager) DockerContainersInfo(containerName string, query *info.Cont
} }
} }
} else { } else {
// Strip "/" // Strip first "/"
containerName = strings.Trim(containerName, "/") containerName = strings.Trim(containerName, "/")
// Get the specified container (check all possible Docker names). // Get the specified container (check all possible Docker names).
possibleNames := docker.FullDockerContainerNames(containerName) possibleNames := docker.FullDockerContainerNames(containerName)
found := false
for _, fullName := range possibleNames { for _, fullName := range possibleNames {
cont, ok := self.containers[fullName] cont, ok := self.containers[fullName]
if ok { if ok {
@ -288,7 +287,7 @@ func (self *manager) DockerContainersInfo(containerName string, query *info.Cont
break break
} }
} }
if !found { if len(containers) == 0 {
return fmt.Errorf("unable to find Docker container %q with full names %v", containerName, possibleNames) return fmt.Errorf("unable to find Docker container %q with full names %v", containerName, possibleNames)
} }
} }

View File

@ -165,6 +165,29 @@ func TestSubcontainersInfo(t *testing.T) {
} }
} }
func TestDockerContainersInfo(t *testing.T) {
containers := []string{
"/docker/c1",
}
query := &info.ContainerInfoRequest{
NumStats: 2,
}
m, _, _ := expectManagerWithContainers(containers, query, t)
result, err := m.DockerContainersInfo("c1", query)
if err != nil {
t.Fatalf("expected to succeed: %s", err)
}
if len(result) != len(containers) {
t.Errorf("expected to received a containers %v, but received: %v", containers, result)
}
if result[0].Name != containers[0] {
t.Errorf("Unexpected container %q in result. Expected container %q", result[0].Name, containers[0])
}
}
func TestNew(t *testing.T) { func TestNew(t *testing.T) {
manager, err := New(&stest.MockStorageDriver{}) manager, err := New(&stest.MockStorageDriver{})
if err != nil { if err != nil {