Ejemplo n.º 1
0
func TestCreatePortBindings(t *testing.T) {
	service1 := "service1"
	ports1 := map[string]string{
		"50100": "50100",
	}
	service2 := "service2"
	ports2 := map[string]string{
		"50200": "50200",
	}
	service3 := "service3"
	resources.InitializeServiceAvailablePorts(service1, ports1)
	resources.InitializeServiceAvailablePorts(service2, ports2)

	bindings1 := createPortBindings(service1)
	assert.Len(t, bindings1, 1)
	assert.NotEmpty(t, bindings1["50100/tcp"])
	assert.Equal(t, "50100", bindings1["50100/tcp"][0].HostPort)

	bindings2 := createPortBindings(service2)
	assert.Len(t, bindings2, 1)
	assert.NotEmpty(t, bindings2["50200/tcp"])
	assert.Equal(t, "50200", bindings2["50200/tcp"][0].HostPort)

	bindings3 := createPortBindings(service3)
	assert.Empty(t, bindings3)
}
Ejemplo n.º 2
0
func TestBuildConfig(t *testing.T) {
	defer cfg.CleanServices()
	services := service.CreateMockServices()
	cfg.SetServices(services)
	resources.CreateMockResources(2, "1G", 0, "0G")
	ports1 := map[string]string{
		"50100": "50100",
	}
	resources.InitializeServiceAvailablePorts("service1", ports1)
	service1, _ := service.GetServiceByName("service1")

	config := buildConfig(service1, enum.START)
	assert.Equal(t, "0", config.HostConfig.CpusetCpus)
}
Ejemplo n.º 3
0
func TestCreateExposedPorts(t *testing.T) {
	service1 := "service1"
	id1 := "pippo"
	availablePorts1 := map[string]string{
		"50100": "50100",
	}
	ports1 := map[string][]string{
		"50100": []string{"50100"},
	}

	resources.InitializeServiceAvailablePorts(service1, availablePorts1)
	resources.AssignSpecifiPortsToService(service1, id1, ports1)

	exposed := createExposedPorts(service1)
	assert.Len(t, exposed, 1)
	assert.Equal(t, exposed["50100/tcp"], struct{}{})
}
Ejemplo n.º 4
0
func TestCreateHostConfig(t *testing.T) {
	defer cfg.CleanServices()
	services := service.CreateMockServices()
	cfg.SetServices(services)
	resources.CreateMockResources(2, "1G", 0, "0G")
	ports1 := map[string]string{
		"50100": "50100",
	}
	resources.InitializeServiceAvailablePorts("service1", ports1)
	service1, _ := service.GetServiceByName("service1")

	hostConfigStop := createHostConfig(service1, enum.STOP)
	assert.Equal(t, hostConfigStop.CpusetCpus, "")

	hostConfigStart := createHostConfig(service1, enum.START)
	assert.Equal(t, hostConfigStart.CpusetCpus, "0")
	assert.Len(t, hostConfigStart.PortBindings, 1)
}
Ejemplo n.º 5
0
func TestCreateContainerConfig(t *testing.T) {
	defer cfg.CleanServices()
	services := service.CreateMockServices()
	cfg.SetServices(services)
	resources.CreateMockResources(2, "1G", 0, "0G")
	service1 := "service1"
	id1 := "pippo"
	availablePorts1 := map[string]string{
		"50100": "50100",
	}
	ports1 := map[string][]string{
		"50100": []string{"50100"},
	}
	resources.InitializeServiceAvailablePorts(service1, availablePorts1)
	resources.AssignSpecifiPortsToService(service1, id1, ports1)
	srv1, _ := service.GetServiceByName(service1)

	containerConfigStop := createContainerConfig(srv1, enum.STOP)
	assert.Empty(t, containerConfigStop.ExposedPorts)
	containerConfigStart := createContainerConfig(srv1, enum.START)
	assert.NotEmpty(t, containerConfigStart.ExposedPorts)
}