mirror of https://github.com/docker/docs.git
Updating unit tests
Signed-off-by: Nishant Totla <nishanttotla@gmail.com>
This commit is contained in:
parent
f5e578188f
commit
40456d0926
|
@ -69,10 +69,10 @@ func TestAffinities(t *testing.T) {
|
||||||
func TestConsolidateResourceFields(t *testing.T) {
|
func TestConsolidateResourceFields(t *testing.T) {
|
||||||
|
|
||||||
config := BuildContainerConfig(container.Config{}, container.HostConfig{Resources: container.Resources{Memory: 4242, MemorySwap: 4343, CPUShares: 4444, CpusetCpus: "1-2"}}, network.NetworkingConfig{})
|
config := BuildContainerConfig(container.Config{}, container.HostConfig{Resources: container.Resources{Memory: 4242, MemorySwap: 4343, CPUShares: 4444, CpusetCpus: "1-2"}}, network.NetworkingConfig{})
|
||||||
assert.Equal(t, config.Memory, int64(4242))
|
assert.Equal(t, config.HostConfig.Memory, int64(4242))
|
||||||
assert.Equal(t, config.MemorySwap, int64(4343))
|
assert.Equal(t, config.HostConfig.MemorySwap, int64(4343))
|
||||||
assert.Equal(t, config.CPUShares, int64(4444))
|
assert.Equal(t, config.HostConfig.CPUShares, int64(4444))
|
||||||
assert.Equal(t, config.CpusetCpus, "1-2")
|
assert.Equal(t, config.HostConfig.CpusetCpus, "1-2")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddAffinity(t *testing.T) {
|
func TestAddAffinity(t *testing.T) {
|
||||||
|
|
|
@ -314,8 +314,8 @@ func TestCreateContainer(t *testing.T) {
|
||||||
assert.NoError(t, engine.ConnectWithClient(client, apiClient))
|
assert.NoError(t, engine.ConnectWithClient(client, apiClient))
|
||||||
assert.True(t, engine.isConnected())
|
assert.True(t, engine.isConnected())
|
||||||
|
|
||||||
mockConfig := config
|
mockConfig := *config
|
||||||
mockConfig.CPUShares = int64(math.Ceil(float64(config.CPUShares*1024) / float64(mockInfo.NCPU)))
|
mockConfig.HostConfig.CPUShares = int64(math.Ceil(float64(config.HostConfig.CPUShares*1024) / float64(mockInfo.NCPU)))
|
||||||
|
|
||||||
// Everything is ok
|
// Everything is ok
|
||||||
name := "test1"
|
name := "test1"
|
||||||
|
@ -334,7 +334,7 @@ func TestCreateContainer(t *testing.T) {
|
||||||
|
|
||||||
// Image not found, pullImage == false
|
// Image not found, pullImage == false
|
||||||
name = "test2"
|
name = "test2"
|
||||||
mockConfig.CPUShares = int64(math.Ceil(float64(config.CPUShares*1024) / float64(mockInfo.NCPU)))
|
mockConfig.HostConfig.CPUShares = int64(math.Ceil(float64(config.HostConfig.CPUShares*1024) / float64(mockInfo.NCPU)))
|
||||||
// FIXMEENGINEAPI : below should return an engine-api error, or something custom
|
// FIXMEENGINEAPI : below should return an engine-api error, or something custom
|
||||||
apiClient.On("ContainerCreate", mock.Anything, &mockConfig.Config, &mockConfig.HostConfig, &mockConfig.NetworkingConfig, name).Return(types.ContainerCreateResponse{}, dockerclient.ErrImageNotFound).Once()
|
apiClient.On("ContainerCreate", mock.Anything, &mockConfig.Config, &mockConfig.HostConfig, &mockConfig.NetworkingConfig, name).Return(types.ContainerCreateResponse{}, dockerclient.ErrImageNotFound).Once()
|
||||||
container, err = engine.Create(config, name, false, auth)
|
container, err = engine.Create(config, name, false, auth)
|
||||||
|
@ -345,7 +345,7 @@ func TestCreateContainer(t *testing.T) {
|
||||||
name = "test3"
|
name = "test3"
|
||||||
id = "id3"
|
id = "id3"
|
||||||
apiClient.On("ImageList", mock.Anything, mock.AnythingOfType("ImageListOptions")).Return([]types.Image{}, nil).Once()
|
apiClient.On("ImageList", mock.Anything, mock.AnythingOfType("ImageListOptions")).Return([]types.Image{}, nil).Once()
|
||||||
mockConfig.CPUShares = int64(math.Ceil(float64(config.CPUShares*1024) / float64(mockInfo.NCPU)))
|
mockConfig.HostConfig.CPUShares = int64(math.Ceil(float64(config.HostConfig.CPUShares*1024) / float64(mockInfo.NCPU)))
|
||||||
apiClient.On("ImagePull", mock.Anything, types.ImagePullOptions{ImageID: config.Image, Tag: "latest"}, mock.Anything).Return(readCloser, nil).Once()
|
apiClient.On("ImagePull", mock.Anything, types.ImagePullOptions{ImageID: config.Image, Tag: "latest"}, mock.Anything).Return(readCloser, nil).Once()
|
||||||
// FIXMEENGINEAPI : below should return an engine-api error, or something custom
|
// FIXMEENGINEAPI : below should return an engine-api error, or something custom
|
||||||
apiClient.On("ContainerCreate", mock.Anything, &mockConfig.Config, &mockConfig.HostConfig, &mockConfig.NetworkingConfig, name).Return(types.ContainerCreateResponse{}, dockerclient.ErrImageNotFound).Once()
|
apiClient.On("ContainerCreate", mock.Anything, &mockConfig.Config, &mockConfig.HostConfig, &mockConfig.NetworkingConfig, name).Return(types.ContainerCreateResponse{}, dockerclient.ErrImageNotFound).Once()
|
||||||
|
|
|
@ -170,22 +170,22 @@ func TestPlaceContainerOvercommit(t *testing.T) {
|
||||||
config := createConfig(0, 0)
|
config := createConfig(0, 0)
|
||||||
|
|
||||||
// Below limit should still work.
|
// Below limit should still work.
|
||||||
config.Memory = 90 * 1024 * 1024 * 1024
|
config.HostConfig.Memory = 90 * 1024 * 1024 * 1024
|
||||||
node := selectTopNode(t, s, config, nodes)
|
node := selectTopNode(t, s, config, nodes)
|
||||||
assert.Equal(t, node, nodes[0])
|
assert.Equal(t, node, nodes[0])
|
||||||
|
|
||||||
// At memory limit should still work.
|
// At memory limit should still work.
|
||||||
config.Memory = 100 * 1024 * 1024 * 1024
|
config.HostConfig.Memory = 100 * 1024 * 1024 * 1024
|
||||||
node = selectTopNode(t, s, config, nodes)
|
node = selectTopNode(t, s, config, nodes)
|
||||||
assert.Equal(t, node, nodes[0])
|
assert.Equal(t, node, nodes[0])
|
||||||
|
|
||||||
// Up to 105% it should still work.
|
// Up to 105% it should still work.
|
||||||
config.Memory = 105 * 1024 * 1024 * 1024
|
config.HostConfig.Memory = 105 * 1024 * 1024 * 1024
|
||||||
node = selectTopNode(t, s, config, nodes)
|
node = selectTopNode(t, s, config, nodes)
|
||||||
assert.Equal(t, node, nodes[0])
|
assert.Equal(t, node, nodes[0])
|
||||||
|
|
||||||
// Above it should return an error.
|
// Above it should return an error.
|
||||||
config.Memory = 106 * 1024 * 1024 * 1024
|
config.HostConfig.Memory = 106 * 1024 * 1024 * 1024
|
||||||
_, err = s.RankAndSort(config, nodes)
|
_, err = s.RankAndSort(config, nodes)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,22 +164,22 @@ func TestSpreadPlaceContainerOvercommit(t *testing.T) {
|
||||||
config := createConfig(0, 0)
|
config := createConfig(0, 0)
|
||||||
|
|
||||||
// Below limit should still work.
|
// Below limit should still work.
|
||||||
config.Memory = 90 * 1024 * 1024 * 1024
|
config.HostConfig.Memory = 90 * 1024 * 1024 * 1024
|
||||||
node := selectTopNode(t, s, config, nodes)
|
node := selectTopNode(t, s, config, nodes)
|
||||||
assert.Equal(t, node, nodes[0])
|
assert.Equal(t, node, nodes[0])
|
||||||
|
|
||||||
// At memory limit should still work.
|
// At memory limit should still work.
|
||||||
config.Memory = 100 * 1024 * 1024 * 1024
|
config.HostConfig.Memory = 100 * 1024 * 1024 * 1024
|
||||||
node = selectTopNode(t, s, config, nodes)
|
node = selectTopNode(t, s, config, nodes)
|
||||||
assert.Equal(t, node, nodes[0])
|
assert.Equal(t, node, nodes[0])
|
||||||
|
|
||||||
// Up to 105% it should still work.
|
// Up to 105% it should still work.
|
||||||
config.Memory = 105 * 1024 * 1024 * 1024
|
config.HostConfig.Memory = 105 * 1024 * 1024 * 1024
|
||||||
node = selectTopNode(t, s, config, nodes)
|
node = selectTopNode(t, s, config, nodes)
|
||||||
assert.Equal(t, node, nodes[0])
|
assert.Equal(t, node, nodes[0])
|
||||||
|
|
||||||
// Above it should return an error.
|
// Above it should return an error.
|
||||||
config.Memory = 106 * 1024 * 1024 * 1024
|
config.HostConfig.Memory = 106 * 1024 * 1024 * 1024
|
||||||
_, err := s.RankAndSort(config, nodes)
|
_, err := s.RankAndSort(config, nodes)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue