func TestConvertToTaskDefinition(t *testing.T) { name := "mysql" cpu := int64(10) command := "cmd" essential := false hostname := "foobarbaz" image := "testimage" links := []string{"container1"} memory := int64(100) // 1 MiB = 1048576B privileged := true readOnly := true restart := "no" securityOpts := []string{"label:type:test_virt"} user := "******" workingDir := "/var" serviceConfig := &libcompose.ServiceConfig{ CpuShares: cpu, Command: libcompose.NewCommand(command), Hostname: hostname, Image: image, Links: libcompose.NewMaporColonSlice(links), MemLimit: int64(1048576) * memory, Privileged: privileged, ReadOnly: readOnly, Restart: restart, SecurityOpt: securityOpts, User: user, WorkingDir: workingDir, } // convert taskDefinition := convertToTaskDefinitionInTest(t, name, serviceConfig) containerDef := *taskDefinition.ContainerDefinitions[0] // verify if name != aws.StringValue(containerDef.Name) { t.Errorf("Expected Name [%s] But was [%s]", name, aws.StringValue(containerDef.Name)) } if cpu != aws.Int64Value(containerDef.Cpu) { t.Errorf("Expected cpu [%s] But was [%s]", cpu, aws.Int64Value(containerDef.Cpu)) } if len(containerDef.Command) != 1 || command != aws.StringValue(containerDef.Command[0]) { t.Errorf("Expected command [%s] But was [%v]", command, containerDef.Command) } if essential != aws.BoolValue(containerDef.Essential) { t.Errorf("Expected essential [%s] But was [%s]", essential, aws.BoolValue(containerDef.Essential)) } if !reflect.DeepEqual(securityOpts, aws.StringValueSlice(containerDef.DockerSecurityOptions)) { t.Errorf("Expected securityOpt [%v] But was [%v]", securityOpts, aws.StringValueSlice(containerDef.DockerSecurityOptions)) } if hostname != aws.StringValue(containerDef.Hostname) { t.Errorf("Expected hostname [%s] But was [%s]", hostname, aws.StringValue(containerDef.Hostname)) } if image != aws.StringValue(containerDef.Image) { t.Errorf("Expected Image [%s] But was [%s]", image, aws.StringValue(containerDef.Image)) } if !reflect.DeepEqual(links, aws.StringValueSlice(containerDef.Links)) { t.Errorf("Expected links [%v] But was [%v]", links, aws.StringValueSlice(containerDef.Links)) } if memory != aws.Int64Value(containerDef.Memory) { t.Errorf("Expected memory [%s] But was [%s]", memory, aws.Int64Value(containerDef.Memory)) } if privileged != aws.BoolValue(containerDef.Privileged) { t.Errorf("Expected privileged [%s] But was [%s]", privileged, aws.BoolValue(containerDef.Privileged)) } if readOnly != aws.BoolValue(containerDef.ReadonlyRootFilesystem) { t.Errorf("Expected ReadonlyRootFilesystem [%s] But was [%s]", readOnly, aws.BoolValue(containerDef.ReadonlyRootFilesystem)) } if user != aws.StringValue(containerDef.User) { t.Errorf("Expected user [%s] But was [%s]", user, aws.StringValue(containerDef.User)) } if workingDir != aws.StringValue(containerDef.WorkingDirectory) { t.Errorf("Expected WorkingDirectory [%s] But was [%s]", workingDir, aws.StringValue(containerDef.WorkingDirectory)) } }
func TestConvertToTaskDefinition(t *testing.T) { name := "mysql" memory := int64(100) // 1 MiB = 1048576B envKey := "username" envValue := "root" env := envKey + "=" + envValue cpu := int64(10) image := "testimage" projectName := "ProjectName" volumes := []string{hostPath + ":" + containerPath} volumesFrom := []string{"container1"} links := []string{"container1"} command := "cmd" serviceConfigs := make(map[string]*libcompose.ServiceConfig) serviceConfigs[name] = &libcompose.ServiceConfig{ MemLimit: int64(1048576) * memory, Environment: libcompose.NewMaporEqualSlice([]string{env}), CpuShares: cpu, Image: image, Command: libcompose.NewCommand(command), Volumes: volumes, VolumesFrom: volumesFrom, Links: libcompose.NewMaporColonSlice(links), } context := libcompose.Context{ ProjectName: projectName, } taskDefinition, err := ConvertToTaskDefinition(context, serviceConfigs) if err != nil { t.Errorf("Expected to convert [%v] serviceConfigs without errors. But got [%v]", serviceConfigs, err) } containerDef := *taskDefinition.ContainerDefinitions[0] if name != *containerDef.Name { t.Errorf("Expected Name [%s] But was [%s]", name, *containerDef.Name) } if memory != *containerDef.Memory { t.Errorf("Expected memory [%s] But was [%s]", memory, *containerDef.Memory) } if cpu != *containerDef.Cpu { t.Errorf("Expected cpu [%s] But was [%s]", cpu, *containerDef.Name) } if image != *containerDef.Image { t.Errorf("Expected Image [%s] But was [%s]", image, *containerDef.Image) } if len(containerDef.Command) != 1 || command != *containerDef.Command[0] { t.Errorf("Expected command [%s] But was [%v]", command, containerDef.Command) } if len(volumesFrom) != len(containerDef.VolumesFrom) || volumesFrom[0] != *containerDef.VolumesFrom[0].SourceContainer { t.Errorf("Expected volumesFrom [%v] But was [%v]", volumesFrom, containerDef.VolumesFrom) } if len(links) != len(containerDef.Links) || links[0] != *containerDef.Links[0] { t.Errorf("Expected links [%v] But was [%v]", links, containerDef.Links) } volumeDef := *taskDefinition.Volumes[0] mountPoint := *containerDef.MountPoints[0] if hostPath != *volumeDef.Host.SourcePath { t.Errorf("Expected HostSourcePath [%s] But was [%s]", hostPath, *volumeDef.Host.SourcePath) } if containerPath != *mountPoint.ContainerPath { t.Errorf("Expected containerPath [%s] But was [%s]", containerPath, *mountPoint.ContainerPath) } if *volumeDef.Name != *mountPoint.SourceVolume { t.Errorf("Expected volume name to match. "+ "Got Volume.Name=[%s] And MountPoint.SourceVolume=[%s]", *volumeDef.Name, *mountPoint.SourceVolume) } }