@@ -2848,3 +2848,100 @@ func TestTaskGPUDisabled(t *testing.T) {
2848
2848
2849
2849
assert .False (t , testTask .isGPUEnabled ())
2850
2850
}
2851
+
2852
+ func TestInitializeContainerOrderingWithLinksAndVolumesFrom (t * testing.T ) {
2853
+ containerWithOnlyVolume := & apicontainer.Container {
2854
+ Name : "myName" ,
2855
+ Image : "image:tag" ,
2856
+ VolumesFrom : []apicontainer.VolumeFrom {{SourceContainer : "myName1" }},
2857
+ }
2858
+
2859
+ containerWithOnlyLink := & apicontainer.Container {
2860
+ Name : "myName1" ,
2861
+ Image : "image:tag" ,
2862
+ Links : []string {"myName" },
2863
+ }
2864
+
2865
+ containerWithBothVolumeAndLink := & apicontainer.Container {
2866
+ Name : "myName2" ,
2867
+ Image : "image:tag" ,
2868
+ VolumesFrom : []apicontainer.VolumeFrom {{SourceContainer : "myName" }},
2869
+ Links : []string {"myName1" },
2870
+ }
2871
+
2872
+ containerWithNoVolumeOrLink := & apicontainer.Container {
2873
+ Name : "myName3" ,
2874
+ Image : "image:tag" ,
2875
+ }
2876
+
2877
+ task := & Task {
2878
+ Arn : "test" ,
2879
+ ResourcesMapUnsafe : make (map [string ][]taskresource.TaskResource ),
2880
+ Containers : []* apicontainer.Container {containerWithOnlyVolume , containerWithOnlyLink ,
2881
+ containerWithBothVolumeAndLink , containerWithNoVolumeOrLink },
2882
+ }
2883
+
2884
+ err := task .initializeContainerOrderingForVolumes ()
2885
+ assert .NoError (t , err )
2886
+ err = task .initializeContainerOrderingForLinks ()
2887
+ assert .NoError (t , err )
2888
+
2889
+ containerResultWithVolume := task .Containers [0 ]
2890
+ assert .Equal (t , "myName1" , containerResultWithVolume .DependsOn [0 ].Container )
2891
+ assert .Equal (t , ContainerOrderingStartCondition , containerResultWithVolume .DependsOn [0 ].Condition )
2892
+
2893
+ containerResultWithLink := task .Containers [1 ]
2894
+ assert .Equal (t , "myName" , containerResultWithLink .DependsOn [0 ].Container )
2895
+ assert .Equal (t , ContainerOrderingRunningCondition , containerResultWithLink .DependsOn [0 ].Condition )
2896
+
2897
+ containerResultWithBothVolumeAndLink := task .Containers [2 ]
2898
+ assert .Equal (t , "myName" , containerResultWithBothVolumeAndLink .DependsOn [0 ].Container )
2899
+ assert .Equal (t , ContainerOrderingStartCondition , containerResultWithBothVolumeAndLink .DependsOn [0 ].Condition )
2900
+ assert .Equal (t , "myName1" , containerResultWithBothVolumeAndLink .DependsOn [1 ].Container )
2901
+ assert .Equal (t , ContainerOrderingRunningCondition , containerResultWithBothVolumeAndLink .DependsOn [1 ].Condition )
2902
+
2903
+ containerResultWithNoVolumeOrLink := task .Containers [3 ]
2904
+ assert .Equal (t , 0 , len (containerResultWithNoVolumeOrLink .DependsOn ))
2905
+ }
2906
+
2907
+ func TestInitializeContainerOrderingWithError (t * testing.T ) {
2908
+ containerWithVolumeError := & apicontainer.Container {
2909
+ Name : "myName" ,
2910
+ Image : "image:tag" ,
2911
+ VolumesFrom : []apicontainer.VolumeFrom {{SourceContainer : "dummyContainer" }},
2912
+ }
2913
+
2914
+ containerWithLinkError1 := & apicontainer.Container {
2915
+ Name : "myName1" ,
2916
+ Image : "image:tag" ,
2917
+ Links : []string {"dummyContainer" },
2918
+ }
2919
+
2920
+ containerWithLinkError2 := & apicontainer.Container {
2921
+ Name : "myName2" ,
2922
+ Image : "image:tag" ,
2923
+ Links : []string {"myName:link1:link2" },
2924
+ }
2925
+
2926
+ task1 := & Task {
2927
+ Arn : "test" ,
2928
+ ResourcesMapUnsafe : make (map [string ][]taskresource.TaskResource ),
2929
+ Containers : []* apicontainer.Container {containerWithVolumeError , containerWithLinkError1 },
2930
+ }
2931
+
2932
+ task2 := & Task {
2933
+ Arn : "test" ,
2934
+ ResourcesMapUnsafe : make (map [string ][]taskresource.TaskResource ),
2935
+ Containers : []* apicontainer.Container {containerWithVolumeError , containerWithLinkError2 },
2936
+ }
2937
+
2938
+ errVolume1 := task1 .initializeContainerOrderingForVolumes ()
2939
+ assert .Error (t , errVolume1 )
2940
+ errLink1 := task1 .initializeContainerOrderingForLinks ()
2941
+ assert .Error (t , errLink1 )
2942
+
2943
+ errVolume2 := task2 .initializeContainerOrderingForVolumes ()
2944
+ assert .Error (t , errVolume2 )
2945
+ errLink2 := task2 .initializeContainerOrderingForLinks ()
2946
+ assert .Error (t , errLink2 )
2947
+ }
0 commit comments