예제 #1
0
func createManagerAndAddContainers(
	driver *stest.MockStorageDriver,
	containers []string,
	f func(*container.MockContainerHandler),
	t *testing.T,
) *manager {
	if driver == nil {
		driver = &stest.MockStorageDriver{}
	}
	container.ClearContainerHandlerFactories()
	mif, err := New(driver)
	if err != nil {
		t.Fatal(err)
	}
	if ret, ok := mif.(*manager); ok {
		for _, name := range containers {
			mockHandler := container.NewMockContainerHandler(name)
			ret.containers[name], err = newContainerData(name, driver, mockHandler, false)
			if err != nil {
				t.Fatal(err)
			}
			f(mockHandler)
		}
		return ret
	}
	t.Fatal("Wrong type")
	return nil
}
예제 #2
0
// Create a containerData instance for a test. Optionsl storage driver may be specified (one is made otherwise).
func newTestContainerData(t *testing.T) (*containerData, *container.MockContainerHandler, *stest.MockStorageDriver) {
	mockHandler := container.NewMockContainerHandler(containerName)
	mockDriver := &stest.MockStorageDriver{}
	ret, err := newContainerData(containerName, mockDriver, mockHandler, nil, false)
	if err != nil {
		t.Fatal(err)
	}
	return ret, mockHandler, mockDriver
}
예제 #3
0
// Create a containerData instance for a test.
func setupContainerData(t *testing.T, spec info.ContainerSpec) (*containerData, *container.MockContainerHandler, *memory.InMemoryCache) {
	mockHandler := container.NewMockContainerHandler(containerName)
	mockHandler.On("GetSpec").Return(
		spec,
		nil,
	)
	memoryCache := memory.New(60, nil)
	ret, err := newContainerData(containerName, memoryCache, mockHandler, false, &collector.GenericCollectorManager{}, 60*time.Second, true)
	if err != nil {
		t.Fatal(err)
	}
	return ret, mockHandler, memoryCache
}
예제 #4
0
// Create a containerData instance for a test.
func setupContainerData(t *testing.T, spec info.ContainerSpec) (*containerData, *container.MockContainerHandler, *memory.InMemoryStorage) {
	mockHandler := container.NewMockContainerHandler(containerName)
	mockHandler.On("GetSpec").Return(
		spec,
		nil,
	)
	memoryStorage := memory.New(60, nil)
	ret, err := newContainerData(containerName, memoryStorage, mockHandler, nil, false)
	if err != nil {
		t.Fatal(err)
	}
	return ret, mockHandler, memoryStorage
}
예제 #5
0
func createManagerAndAddContainers(
	driver *stest.MockStorageDriver,
	sysfs *fakesysfs.FakeSysFs,
	containers []string,
	f func(*container.MockContainerHandler),
	t *testing.T,
) *manager {
	if driver == nil {
		driver = &stest.MockStorageDriver{}
	}
	container.ClearContainerHandlerFactories()
	mif, err := New(driver, sysfs)
	if err != nil {
		t.Fatal(err)
	}
	if ret, ok := mif.(*manager); ok {
		for _, name := range containers {
			mockHandler := container.NewMockContainerHandler(name)
			cont, err := newContainerData(name, driver, mockHandler, nil, false)
			if err != nil {
				t.Fatal(err)
			}
			ret.containers[namespacedContainerName{
				Name: name,
			}] = cont
			// Add Docker containers under their namespace.
			if strings.HasPrefix(name, "/docker") {
				ret.containers[namespacedContainerName{
					Namespace: docker.DockerNamespace,
					Name:      strings.TrimPrefix(name, "/docker/"),
				}] = cont
			}
			f(mockHandler)
		}
		return ret
	}
	t.Fatal("Wrong type")
	return nil
}
예제 #6
0
func createManagerAndAddContainers(
	memoryStorage *memory.InMemoryStorage,
	sysfs *fakesysfs.FakeSysFs,
	containers []string,
	f func(*container.MockContainerHandler),
	t *testing.T,
) *manager {
	container.ClearContainerHandlerFactories()
	mif := &manager{
		containers:    make(map[namespacedContainerName]*containerData),
		quitChannels:  make([]chan error, 0, 2),
		memoryStorage: memoryStorage,
	}
	for _, name := range containers {
		mockHandler := container.NewMockContainerHandler(name)
		spec := itest.GenerateRandomContainerSpec(4)
		mockHandler.On("GetSpec").Return(
			spec,
			nil,
		).Once()
		cont, err := newContainerData(name, memoryStorage, mockHandler, nil, false)
		if err != nil {
			t.Fatal(err)
		}
		mif.containers[namespacedContainerName{
			Name: name,
		}] = cont
		// Add Docker containers under their namespace.
		if strings.HasPrefix(name, "/docker") {
			mif.containers[namespacedContainerName{
				Namespace: docker.DockerNamespace,
				Name:      strings.TrimPrefix(name, "/docker/"),
			}] = cont
		}
		f(mockHandler)
	}
	return mif
}