mirror of
https://github.com/docker/compose.git
synced 2025-07-23 13:45:00 +02:00
Add test for convert failure
Signed-off-by: aiordache <anca.iordache@docker.com> Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
2ef1e28f1d
commit
ce3ab38e61
@ -154,6 +154,21 @@ services:
|
|||||||
assert.Equal(t, def.Cpu, "4096")
|
assert.Equal(t, def.Cpu, "4096")
|
||||||
assert.Equal(t, def.Memory, "8192")
|
assert.Equal(t, def.Memory, "8192")
|
||||||
}
|
}
|
||||||
|
func TestTaskSizeConvertFailure(t *testing.T) {
|
||||||
|
model := loadConfig(t, "test", `
|
||||||
|
version: "3"
|
||||||
|
services:
|
||||||
|
test:
|
||||||
|
image: nginx
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpus: '0.5'
|
||||||
|
memory: 2043248M
|
||||||
|
`)
|
||||||
|
_, err := Backend{}.Convert(model)
|
||||||
|
assert.ErrorContains(t, err, "unable to find cpu/mem for the required resources")
|
||||||
|
}
|
||||||
|
|
||||||
func TestLoadBalancerTypeNetwork(t *testing.T) {
|
func TestLoadBalancerTypeNetwork(t *testing.T) {
|
||||||
template := convertYaml(t, "test", `
|
template := convertYaml(t, "test", `
|
||||||
@ -256,6 +271,13 @@ func load(t *testing.T, paths ...string) *types.Project {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func convertYaml(t *testing.T, name string, yaml string) *cloudformation.Template {
|
func convertYaml(t *testing.T, name string, yaml string) *cloudformation.Template {
|
||||||
|
model := loadConfig(t, name, yaml)
|
||||||
|
template, err := Backend{}.Convert(model)
|
||||||
|
assert.NilError(t, err)
|
||||||
|
return template
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadConfig(t *testing.T, name string, yaml string) *types.Project {
|
||||||
dict, err := loader.ParseYAML([]byte(yaml))
|
dict, err := loader.ParseYAML([]byte(yaml))
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
model, err := loader.Load(types.ConfigDetails{
|
model, err := loader.Load(types.ConfigDetails{
|
||||||
@ -266,7 +288,5 @@ func convertYaml(t *testing.T, name string, yaml string) *cloudformation.Templat
|
|||||||
options.Name = "Test"
|
options.Name = "Test"
|
||||||
})
|
})
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
template, err := Backend{}.Convert(model)
|
return model
|
||||||
assert.NilError(t, err)
|
|
||||||
return template
|
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ func toSystemControls(sysctls types.Mapping) []ecs.TaskDefinition_SystemControl
|
|||||||
return sys
|
return sys
|
||||||
}
|
}
|
||||||
|
|
||||||
const Mb = 1024 * 1024
|
const MiB = 1024 * 1024
|
||||||
|
|
||||||
func toLimits(service types.ServiceConfig) (string, string, error) {
|
func toLimits(service types.ServiceConfig) (string, string, error) {
|
||||||
// All possible cpu/mem values for Fargate
|
// All possible cpu/mem values for Fargate
|
||||||
@ -149,9 +149,9 @@ func toLimits(service types.ServiceConfig) (string, string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for cpu, mem := range cpuToMem {
|
for cpu, mem := range cpuToMem {
|
||||||
if v <= cpu*Mb {
|
if v <= cpu*MiB {
|
||||||
for _, m := range mem {
|
for _, m := range mem {
|
||||||
if limits.MemoryBytes <= m*Mb {
|
if limits.MemoryBytes <= m*MiB {
|
||||||
cpuLimit = strconv.FormatInt(cpu, 10)
|
cpuLimit = strconv.FormatInt(cpu, 10)
|
||||||
memLimit = strconv.FormatInt(int64(m), 10)
|
memLimit = strconv.FormatInt(int64(m), 10)
|
||||||
return cpuLimit, memLimit, nil
|
return cpuLimit, memLimit, nil
|
||||||
@ -174,7 +174,7 @@ func toContainerReservation(service types.ServiceConfig) (string, int, error) {
|
|||||||
if reservations == nil {
|
if reservations == nil {
|
||||||
return cpuReservation, memReservation, nil
|
return cpuReservation, memReservation, nil
|
||||||
}
|
}
|
||||||
return reservations.NanoCPUs, int(reservations.MemoryBytes / Mb), nil
|
return reservations.NanoCPUs, int(reservations.MemoryBytes / MiB), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func toRequiresCompatibilities(isolation string) []*string {
|
func toRequiresCompatibilities(isolation string) []*string {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user