Esempio n. 1
0
func TestGetSubcontainersInfo(t *testing.T) {
	query := &info.ContainerInfoRequest{
		NumStats: 3,
	}
	containerName := "/some/container"
	cinfo := itest.GenerateRandomContainerInfo(containerName, 4, query, 1*time.Second)
	cinfo1 := itest.GenerateRandomContainerInfo(path.Join(containerName, "sub1"), 4, query, 1*time.Second)
	cinfo2 := itest.GenerateRandomContainerInfo(path.Join(containerName, "sub2"), 4, query, 1*time.Second)
	response := []info.ContainerInfo{
		*cinfo,
		*cinfo1,
		*cinfo2,
	}
	client, server, err := cadvisorTestClient(fmt.Sprintf("/api/v1.3/subcontainers%v", containerName), query, response, t)
	if err != nil {
		t.Fatalf("unable to get a client %v", err)
	}
	defer server.Close()
	returned, err := client.SubcontainersInfo(containerName, query)
	if err != nil {
		t.Fatal(err)
	}

	if len(returned) != 3 {
		t.Errorf("unexpected number of results: got %d, expected 3", len(returned))
	}
	if !returned[0].Eq(cinfo) {
		t.Error("received unexpected ContainerInfo")
	}
	if !returned[1].Eq(cinfo1) {
		t.Error("received unexpected ContainerInfo")
	}
	if !returned[2].Eq(cinfo2) {
		t.Error("received unexpected ContainerInfo")
	}
}
Esempio n. 2
0
// TestGetContainerInfo generates a random container information object
// and then checks that ContainerInfo returns the expected result.
func TestGetContainerInfo(t *testing.T) {
	query := &info.ContainerInfoRequest{
		NumStats: 3,
	}
	containerName := "/some/container"
	cinfo := itest.GenerateRandomContainerInfo(containerName, 4, query, 1*time.Second)
	client, server, err := cadvisorTestClient(fmt.Sprintf("/api/v1.3/containers%v", containerName), query, cinfo, t)
	if err != nil {
		t.Fatalf("unable to get a client %v", err)
	}
	defer server.Close()
	returned, err := client.ContainerInfo(containerName, query)
	if err != nil {
		t.Fatal(err)
	}

	if !returned.Eq(cinfo) {
		t.Error("received unexpected ContainerInfo")
	}
}