engine: Add back old test, code is still there
@@ -246,7 +246,7 @@ func TestContainerNextState(t *testing.T) {
}
}
-func TestContainerNextStateWithDependencies(t *testing.T) {
+func TestContainerNextStateWithTransitionDependencies(t *testing.T) {
testCases := []struct {
name string
containerCurrentStatus api.ContainerStatus
@@ -360,6 +360,59 @@ func TestContainerNextStateWithDependencies(t *testing.T) {
}
}
+func TestContainerNextStateWithDependencies(t *testing.T) {
+ testCases := []struct {
+ containerCurrentStatus api.ContainerStatus
+ containerDesiredStatus api.ContainerStatus
+ dependencyCurrentStatus api.ContainerStatus
+ expectedContainerStatus api.ContainerStatus
+ expectedTransitionActionable bool
+ expectedTransitionPossible bool
+ }{
+ // NONE -> RUNNING transition is not allowed and not actionable, when desired is Running and dependency is None
+ {api.ContainerStatusNone, api.ContainerRunning, api.ContainerStatusNone, api.ContainerStatusNone, false, false},
+ // NONE -> RUNNING transition is not allowed and not actionable, when desired is Running and dependency is Created
+ {api.ContainerStatusNone, api.ContainerRunning, api.ContainerCreated, api.ContainerStatusNone, false, false},
+ // NONE -> RUNNING transition is allowed and actionable, when desired is Running and dependency is Running
+ // The expected next status is Pulled
+ {api.ContainerStatusNone, api.ContainerRunning, api.ContainerRunning, api.ContainerPulled, true, true},
+ // NONE -> RUNNING transition is allowed and actionable, when desired is Running and dependency is Stopped
+ // The expected next status is Pulled
+ {api.ContainerStatusNone, api.ContainerRunning, api.ContainerStopped, api.ContainerPulled, true, true},
+ }
+
+ for _, tc := range testCases {
+ t.Run(fmt.Sprintf("%s to %s Transition",
+ tc.containerCurrentStatus.String(), tc.containerDesiredStatus.String()), func(t *testing.T) {
+ dependencyName := "dependency"
+ container := &api.Container{
+ DesiredStatusUnsafe: tc.containerDesiredStatus,
+ KnownStatusUnsafe: tc.containerCurrentStatus,
+ SteadyStateDependencies: []string{dependencyName},
+ }
+ dependency := &api.Container{
+ Name: dependencyName,
+ KnownStatusUnsafe: tc.dependencyCurrentStatus,
+ }
+ task := &managedTask{
+ Task: &api.Task{
+ Containers: []*api.Container{
+ container,
+ dependency,
+ },
+ DesiredStatusUnsafe: api.TaskRunning,
+ },
+ }
+ nextStatus, actionRequired, possible := task.containerNextState(container)
+ assert.Equal(t, tc.expectedContainerStatus, nextStatus,
+ "Expected next state [%s] != Retrieved next state [%s]",
+ tc.expectedContainerStatus.String(), nextStatus.String())
+ assert.Equal(t, tc.expectedTransitionActionable, actionRequired, "transition actionable")
+ assert.Equal(t, tc.expectedTransitionPossible, possible, "transition possible")
+ })
+ }
+}
+
func TestStartContainerTransitionsWhenForwardTransitionPossible(t *testing.T) {
steadyStates := []api.ContainerStatus{api.ContainerRunning, api.ContainerResourcesProvisioned}
for _, steadyState := range steadyStates {
