Skip to content

Commit

Permalink
unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
sparrc committed Apr 25, 2024
1 parent 27ce67b commit dfdf23c
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions agent/api/container/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/aws/amazon-ecs-agent/agent/utils"
dockercontainer "github.com/docker/docker/api/types/container"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

type configPair struct {
Expand Down Expand Up @@ -1334,6 +1335,42 @@ func TestGetCredentialSpec(t *testing.T) {
}
}

func TestRestartPolicy(t *testing.T) {
testCases := []struct {
name string
container *Container
restartCount int
expectedEnabled bool
}{
{
name: "base case",
container: &Container{
RestartPolicy: RestartPolicy{},
},
restartCount: 0,
expectedEnabled: false,
},
{
name: "do 5 restarts",
container: &Container{
RestartPolicy: RestartPolicy{
Enabled: true,
},
},
restartCount: 5,
expectedEnabled: true,
},
}

for _, tc := range testCases {
require.Equal(t, tc.expectedEnabled, tc.container.RestartPolicyEnabled())
for i := 0; i < tc.restartCount; i++ {
tc.container.RecordRestart()
}
require.Equal(t, tc.restartCount, tc.container.GetRestartCount())
}
}

func getContainer(hostConfig string, credentialSpecs []string) *Container {
c := &Container{
Name: "c",
Expand Down

0 comments on commit dfdf23c

Please sign in to comment.