@@ -767,6 +767,7 @@ func TestConvertToTaskDefinitionWithVolumes(t *testing.T) {
767
767
}
768
768
volumeDef := * taskDefinition .Volumes [0 ]
769
769
mountPoint := * containerDef .MountPoints [0 ]
770
+
770
771
if hostPath != aws .StringValue (volumeDef .Host .SourcePath ) {
771
772
t .Errorf ("Expected HostSourcePath [%s] But was [%s]" , hostPath , aws .StringValue (volumeDef .Host .SourcePath ))
772
773
}
@@ -788,7 +789,7 @@ func TestConvertToTaskDefinitionWithNamedVolume(t *testing.T) {
788
789
Networks : & yaml.Networks {Networks : []* yaml.Network {defaultNetwork }},
789
790
}
790
791
791
- taskDefinition := convertToTaskDefinitionInTest (t , "name" , & config. VolumeConfig {} , serviceConfig , "" , "" )
792
+ taskDefinition := convertToTaskDefinitionInTest (t , "name" , nil , serviceConfig , "" , "" )
792
793
containerDef := * taskDefinition .ContainerDefinitions [0 ]
793
794
794
795
volumeDef := * taskDefinition .Volumes [0 ]
@@ -918,8 +919,17 @@ func TestConvertToMountPoints(t *testing.T) {
918
919
}
919
920
920
921
// Valid inputs with host and container paths set
921
- mountPointsIn := yaml.Volumes {Volumes : []* yaml.Volume {& onlyContainerPath , & onlyContainerPath2 , & hostAndContainerPath ,
922
- & onlyContainerPathWithRO , & hostAndContainerPathWithRO , & hostAndContainerPathWithRW , & namedVolumeAndContainerPath }}
922
+ mountPointsIn := yaml.Volumes {
923
+ Volumes : []* yaml.Volume {
924
+ & onlyContainerPath ,
925
+ & onlyContainerPath2 ,
926
+ & hostAndContainerPath ,
927
+ & onlyContainerPathWithRO ,
928
+ & hostAndContainerPathWithRO ,
929
+ & hostAndContainerPathWithRW ,
930
+ & namedVolumeAndContainerPath ,
931
+ },
932
+ }
923
933
924
934
mountPointsOut , err := ConvertToMountPoints (& mountPointsIn , volumes )
925
935
if err != nil {
@@ -944,16 +954,37 @@ func TestConvertToMountPoints(t *testing.T) {
944
954
if mountPointsOut [1 ].SourceVolume == mountPointsOut [3 ].SourceVolume {
945
955
t .Errorf ("Expected volume %v (onlyContainerPath2) and %v (onlyContainerPathWithRO) to be different" , mountPointsOut [0 ].SourceVolume , mountPointsOut [1 ].SourceVolume )
946
956
}
957
+ }
958
+
959
+ func TestConvertToMountPointsWithInvalidAccessMode (t * testing.T ) {
960
+ volumes := & volumes {
961
+ volumeWithHost : make (map [string ]string ),
962
+ volumeEmptyHost : []string {namedVolume },
963
+ }
964
+
965
+ hostAndContainerPathWithIncorrectAccess := yaml.Volume {
966
+ Source : hostPath ,
967
+ Destination : containerPath ,
968
+ AccessMode : "readonly" ,
969
+ }
970
+
971
+ mountPointsIn := yaml.Volumes {
972
+ Volumes : []* yaml.Volume {& hostAndContainerPathWithIncorrectAccess },
973
+ }
974
+
975
+ _ , err := ConvertToMountPoints (& mountPointsIn , volumes )
947
976
948
- // Invalid access mode input
949
- hostAndContainerPathWithIncorrectAccess := yaml.Volume {Source : hostPath , Destination : containerPath , AccessMode : "readonly" }
950
- mountPointsIn = yaml.Volumes {Volumes : []* yaml.Volume {& hostAndContainerPathWithIncorrectAccess }}
951
- mountPointsOut , err = ConvertToMountPoints (& mountPointsIn , volumes )
952
977
if err == nil {
953
978
t .Errorf ("Expected to get error for mountPoint[%s] but didn't." , hostAndContainerPathWithIncorrectAccess )
954
979
}
980
+ }
955
981
956
- mountPointsOut , err = ConvertToMountPoints (nil , volumes )
982
+ func TestConvertToMountPointsNullContainerVolumes (t * testing.T ) {
983
+ volumes := & volumes {
984
+ volumeWithHost : make (map [string ]string ),
985
+ volumeEmptyHost : []string {namedVolume },
986
+ }
987
+ mountPointsOut , err := ConvertToMountPoints (nil , volumes )
957
988
if err != nil {
958
989
t .Fatalf ("Expected to convert nil mountPoints without errors. But got [%v]" , err )
959
990
}
@@ -1064,11 +1095,76 @@ func verifyUlimit(t *testing.T, output *ecs.Ulimit, name string, softLimit, hard
1064
1095
}
1065
1096
}
1066
1097
1098
+ func TestConvertToVolumes (t * testing.T ) {
1099
+ libcomposeVolumeConfigs := map [string ]* config.VolumeConfig {
1100
+ namedVolume : nil ,
1101
+ }
1102
+
1103
+ expected := & volumes {
1104
+ volumeWithHost : make (map [string ]string ), // map with key:=hostSourcePath value:=VolumeName
1105
+ volumeEmptyHost : []string {namedVolume }, // Declare one volume with an empty host
1106
+ }
1107
+
1108
+ actual , err := ConvertToVolumes (libcomposeVolumeConfigs )
1109
+
1110
+ assert .NoError (t , err , "Unexpected error converting libcompose volume configs" )
1111
+ assert .Equal (t , expected , actual , "Named volumes should match" )
1112
+ }
1113
+
1114
+ func TestConvertToVolumes_ErrorsWithDriverSubfield (t * testing.T ) {
1115
+ libcomposeVolumeConfigs := map [string ]* config.VolumeConfig {
1116
+ namedVolume : & config.VolumeConfig {
1117
+ Driver : "noodles" ,
1118
+ },
1119
+ }
1120
+
1121
+ _ , err := ConvertToVolumes (libcomposeVolumeConfigs )
1122
+
1123
+ assert .Error (t , err , "Expected error converting libcompose volume configs when driver is specified" )
1124
+ }
1125
+
1126
+ func TestConvertToVolumes_ErrorsWithDriverOptsSubfield (t * testing.T ) {
1127
+ driverOpts := map [string ]string {"foo" : "bar" }
1128
+
1129
+ libcomposeVolumeConfigs := map [string ]* config.VolumeConfig {
1130
+ namedVolume : & config.VolumeConfig {
1131
+ DriverOpts : driverOpts ,
1132
+ },
1133
+ }
1134
+
1135
+ _ , err := ConvertToVolumes (libcomposeVolumeConfigs )
1136
+
1137
+ assert .Error (t , err , "Expected error converting libcompose volume configs when driver options are specified" )
1138
+ }
1139
+
1140
+ func TestConvertToVolumes_ErrorsWithExternalSubfield (t * testing.T ) {
1141
+ external := yaml.External {External : false }
1142
+
1143
+ libcomposeVolumeConfigs := map [string ]* config.VolumeConfig {
1144
+ namedVolume : & config.VolumeConfig {
1145
+ External : external ,
1146
+ },
1147
+ }
1148
+
1149
+ _ , err := ConvertToVolumes (libcomposeVolumeConfigs )
1150
+
1151
+ assert .Error (t , err , "Expected error converting libcompose volume configs when external is specified" )
1152
+
1153
+ external = yaml.External {External : true }
1154
+ libcomposeVolumeConfigs = map [string ]* config.VolumeConfig {
1155
+ namedVolume : & config.VolumeConfig {
1156
+ External : external ,
1157
+ },
1158
+ }
1159
+
1160
+ _ , err = ConvertToVolumes (libcomposeVolumeConfigs )
1161
+
1162
+ assert .Error (t , err , "Expected error converting libcompose volume configs when external is specified" )
1163
+ }
1164
+
1067
1165
func convertToTaskDefinitionInTest (t * testing.T , name string , volumeConfig * config.VolumeConfig , serviceConfig * config.ServiceConfig , taskRoleArn string , launchType string ) * ecs.TaskDefinition {
1068
1166
volumeConfigs := make (map [string ]* config.VolumeConfig )
1069
- if volumeConfig != nil {
1070
- volumeConfigs [namedVolume ] = volumeConfig
1071
- }
1167
+ volumeConfigs [namedVolume ] = volumeConfig
1072
1168
1073
1169
serviceConfigs := config .NewServiceConfigs ()
1074
1170
serviceConfigs .Add (name , serviceConfig )
0 commit comments