func TestContainerGetInfo(t *testing.T) {
	var handler *ctest.MockContainerHandler
	spec := itest.GenerateRandomContainerSpec(4)
	subcontainers := []info.ContainerReference{
		{Name: "/container/ee0103"},
		{Name: "/container/abcd"},
		{Name: "/container/something"},
	}
	aliases := []string{"a1", "a2"}
	cd := createContainerDataAndSetHandler(
		nil,
		func(h *ctest.MockContainerHandler) {
			h.On("GetSpec").Return(
				spec,
				nil,
			)
			h.On("ListContainers", container.LIST_SELF).Return(
				subcontainers,
				nil,
			)
			h.Aliases = aliases
			handler = h
		},
		t,
	)

	info, err := cd.GetInfo()
	if err != nil {
		t.Fatal(err)
	}

	handler.AssertExpectations(t)

	if len(info.Subcontainers) != len(subcontainers) {
		t.Errorf("Received %v subcontainers, should be %v", len(info.Subcontainers), len(subcontainers))
	}

	for _, sub := range info.Subcontainers {
		found := false
		for _, sub2 := range subcontainers {
			if sub.Name == sub2.Name {
				found = true
			}
		}
		if !found {
			t.Errorf("Received unknown sub container %v", sub)
		}
	}

	if !reflect.DeepEqual(spec, info.Spec) {
		t.Errorf("received wrong container spec")
	}

	if info.Name != handler.Name {
		t.Errorf("received wrong container name: received %v; should be %v", info.Name, handler.Name)
	}
}
Example #2
0
func TestGetInfo(t *testing.T) {
	spec := itest.GenerateRandomContainerSpec(4)
	subcontainers := []info.ContainerReference{
		{Name: "/container/ee0103"},
		{Name: "/container/abcd"},
		{Name: "/container/something"},
	}
	cd, mockHandler, _ := newTestContainerData(t)
	mockHandler.On("GetSpec").Return(
		spec,
		nil,
	)
	mockHandler.On("ListContainers", container.ListSelf).Return(
		subcontainers,
		nil,
	)
	mockHandler.Aliases = []string{"a1", "a2"}

	info, err := cd.GetInfo()
	if err != nil {
		t.Fatal(err)
	}

	mockHandler.AssertExpectations(t)

	if len(info.Subcontainers) != len(subcontainers) {
		t.Errorf("Received %v subcontainers, should be %v", len(info.Subcontainers), len(subcontainers))
	}

	for _, sub := range info.Subcontainers {
		found := false
		for _, sub2 := range subcontainers {
			if sub.Name == sub2.Name {
				found = true
			}
		}
		if !found {
			t.Errorf("Received unknown sub container %v", sub)
		}
	}

	if !reflect.DeepEqual(spec, info.Spec) {
		t.Errorf("received wrong container spec")
	}

	if info.Name != mockHandler.Name {
		t.Errorf("received wrong container name: received %v; should be %v", info.Name, mockHandler.Name)
	}
}
Example #3
0
func TestUpdateSpec(t *testing.T) {
	spec := itest.GenerateRandomContainerSpec(4)
	cd, mockHandler, _ := newTestContainerData(t)
	mockHandler.On("GetSpec").Return(
		spec,
		nil,
	)

	err := cd.updateSpec()
	if err != nil {
		t.Fatal(err)
	}

	mockHandler.AssertExpectations(t)
}
func TestContainerUpdateSpec(t *testing.T) {
	var handler *ctest.MockContainerHandler
	spec := itest.GenerateRandomContainerSpec(4)
	cd := createContainerDataAndSetHandler(
		nil,
		func(h *ctest.MockContainerHandler) {
			h.On("GetSpec").Return(
				spec,
				nil,
			)
			handler = h
		},
		t,
	)

	err := cd.updateSpec()
	if err != nil {
		t.Fatal(err)
	}

	handler.AssertExpectations(t)
}