Skip to content

Commit

Permalink
Fix unit tests for containerID/containerName changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sparrc committed Sep 3, 2020
1 parent ab0e1cb commit e865e9c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion agent/engine/docker_task_engine_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ func TestTaskCPULimitHappyPath(t *testing.T) {
// Expect a bunch of steady state 'poll' describes when we trigger cleanup
client.EXPECT().RemoveContainer(gomock.Any(), gomock.Any(), gomock.Any()).Do(
func(ctx interface{}, removedContainerName string, timeout time.Duration) {
assert.Equal(t, getCreatedContainerName(), removedContainerName,
assert.Equal(t, containerID, removedContainerName,
"Container name mismatch")
}).Return(nil)

Expand Down
27 changes: 14 additions & 13 deletions agent/engine/docker_task_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func TestBatchContainerHappyPath(t *testing.T) {
// Expect a bunch of steady state 'poll' describes when we trigger cleanup
client.EXPECT().RemoveContainer(gomock.Any(), gomock.Any(), gomock.Any()).Do(
func(ctx interface{}, removedContainerName string, timeout time.Duration) {
assert.Equal(t, getCreatedContainerName(), removedContainerName,
assert.Equal(t, containerID, removedContainerName,
"Container name mismatch")
}).Return(nil)

Expand Down Expand Up @@ -494,7 +494,7 @@ func TestRemoveEvents(t *testing.T) {

client.EXPECT().RemoveContainer(gomock.Any(), gomock.Any(), gomock.Any()).Do(
func(ctx interface{}, removedContainerName string, timeout time.Duration) {
assert.Equal(t, getCreatedContainerName(), removedContainerName,
assert.Equal(t, containerID, removedContainerName,
"Container name mismatch")

// Emit a couple of events for the task before cleanup finishes. This forces
Expand Down Expand Up @@ -634,7 +634,7 @@ func TestSteadyStatePoll(t *testing.T) {
cleanup := make(chan time.Time)
defer close(cleanup)
testTime.EXPECT().After(gomock.Any()).Return(cleanup).MinTimes(1)
client.EXPECT().RemoveContainer(gomock.Any(), dockerContainer.DockerName, dockerclient.RemoveContainerTimeout).Return(nil)
client.EXPECT().RemoveContainer(gomock.Any(), dockerContainer.DockerID, dockerclient.RemoveContainerTimeout).Return(nil)
imageManager.EXPECT().RemoveContainerReferenceFromImageState(gomock.Any()).Return(nil)

waitForStopEvents(t, taskEngine.StateChangeEvents(), false)
Expand Down Expand Up @@ -1259,7 +1259,7 @@ func TestProvisionContainerResources(t *testing.T) {
}, testTask)

gomock.InOrder(
dockerClient.EXPECT().InspectContainer(gomock.Any(), dockerContainerName, gomock.Any()).Return(&types.ContainerJSON{
dockerClient.EXPECT().InspectContainer(gomock.Any(), containerID, gomock.Any()).Return(&types.ContainerJSON{
ContainerJSONBase: &types.ContainerJSONBase{
ID: containerID,
State: &types.ContainerState{Pid: containerPid},
Expand Down Expand Up @@ -1298,7 +1298,7 @@ func TestProvisionContainerResourcesInspectError(t *testing.T) {
Container: pauseContainer,
}, testTask)

dockerClient.EXPECT().InspectContainer(gomock.Any(), dockerContainerName, gomock.Any()).Return(nil, errors.New("test error"))
dockerClient.EXPECT().InspectContainer(gomock.Any(), containerID, gomock.Any()).Return(nil, errors.New("test error"))

assert.NotNil(t, taskEngine.(*DockerTaskEngine).provisionContainerResources(testTask, pauseContainer).Error)
}
Expand Down Expand Up @@ -1353,7 +1353,7 @@ func TestStopPauseContainerCleanupCalled(t *testing.T) {
}, testTask)

gomock.InOrder(
dockerClient.EXPECT().InspectContainer(gomock.Any(), dockerContainerName, gomock.Any()).Return(&types.ContainerJSON{
dockerClient.EXPECT().InspectContainer(gomock.Any(), containerID, gomock.Any()).Return(&types.ContainerJSON{
ContainerJSONBase: &types.ContainerJSONBase{
ID: containerID,
State: &types.ContainerState{Pid: containerPid},
Expand Down Expand Up @@ -1416,7 +1416,7 @@ func TestStopPauseContainerCleanupDelay(t *testing.T) {
}, testTask)

gomock.InOrder(
dockerClient.EXPECT().InspectContainer(gomock.Any(), dockerContainerName, gomock.Any()).Return(&types.ContainerJSON{
dockerClient.EXPECT().InspectContainer(gomock.Any(), containerID, gomock.Any()).Return(&types.ContainerJSON{
ContainerJSONBase: &types.ContainerJSONBase{
ID: containerID,
State: &types.ContainerState{Pid: containerPid},
Expand Down Expand Up @@ -1478,7 +1478,7 @@ func TestCreateContainerOnAgentRestart(t *testing.T) {
sleepTask := testdata.LoadTask("sleep5")
sleepContainer, _ := sleepTask.ContainerByName("sleep5")
// Store the generated container name to state
state.AddContainer(&apicontainer.DockerContainer{DockerName: "docker_container_name", Container: sleepContainer}, sleepTask)
state.AddContainer(&apicontainer.DockerContainer{DockerID: "dockerID", DockerName: "docker_container_name", Container: sleepContainer}, sleepTask)

gomock.InOrder(
client.EXPECT().APIVersion().Return(defaultDockerClientAPIVersion, nil),
Expand Down Expand Up @@ -3006,7 +3006,7 @@ func TestGetBridgeIP(t *testing.T) {

func TestStartFirelensContainerRetryForContainerIP(t *testing.T) {
dockerMetaDataWithoutNetworkSettings := dockerapi.DockerContainerMetadata{
DockerID: dockerContainerName,
DockerID: containerID,
Volumes: []types.MountPoint{
{
Name: "volume",
Expand Down Expand Up @@ -3080,17 +3080,18 @@ func TestStartFirelensContainerRetryForContainerIP(t *testing.T) {
taskEngine.(*DockerTaskEngine).state.AddTask(testTask)
taskEngine.(*DockerTaskEngine).state.AddContainer(&apicontainer.DockerContainer{
Container: testTask.Containers[1],
DockerName: "dockerContainerName",
DockerName: dockerContainerName,
DockerID: containerID,
}, testTask)

client.EXPECT().APIVersion().Return(defaultDockerClientAPIVersion, nil).AnyTimes()
client.EXPECT().StartContainer(gomock.Any(), gomock.Any(), gomock.Any()).Return(dockerMetaDataWithoutNetworkSettings).AnyTimes()
gomock.InOrder(
client.EXPECT().InspectContainer(gomock.Any(), dockerContainerName, gomock.Any()).
client.EXPECT().InspectContainer(gomock.Any(), containerID, gomock.Any()).
Return(jsonBaseWithoutNetwork, nil),
client.EXPECT().InspectContainer(gomock.Any(), dockerContainerName, gomock.Any()).
client.EXPECT().InspectContainer(gomock.Any(), containerID, gomock.Any()).
Return(jsonBaseWithoutNetwork, nil),
client.EXPECT().InspectContainer(gomock.Any(), dockerContainerName, gomock.Any()).
client.EXPECT().InspectContainer(gomock.Any(), containerID, gomock.Any()).
Return(jsonBaseWithNetwork, nil),
)
ret := taskEngine.(*DockerTaskEngine).startContainer(testTask, testTask.Containers[1])
Expand Down

0 comments on commit e865e9c

Please sign in to comment.