Skip to content

Commit

Permalink
[#51] Fixed according to the comments.
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Milchev [email protected]
  • Loading branch information
daniel-milchev committed Oct 25, 2023
1 parent 436ae94 commit 390e05c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 32 deletions.
35 changes: 11 additions & 24 deletions containerm/ctr/ctrd_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,7 @@ func TestCtrdClientCreateContainer(t *testing.T) {

for testName, testCase := range tests {
t.Run(testName, func(t *testing.T) {
expectedError := testCase.mockExec()
actualError := testClient.CreateContainer(ctx, testCtr, "")
testutil.AssertError(t, expectedError, actualError)
testutil.AssertError(t, testCase.mockExec(), testClient.CreateContainer(ctx, testCtr, ""))
})
}
}
Expand Down Expand Up @@ -584,8 +582,8 @@ func TestAttachContainer(t *testing.T) {
attachConfig: attachConfig,
mockExec: func() error {
mockIoMgr.EXPECT().GetIO(testCtr.ID).Return(nil)
mockIoMgr.EXPECT().InitIO(testCtr.ID, testCtr.IOConfig.OpenStdin).Return(nil, log.NewErrorf("failed to initialise IO for container ID = test-id"))
return log.NewErrorf("failed to initialise IO for container ID = test-id")
mockIoMgr.EXPECT().InitIO(testCtr.ID, testCtr.IOConfig.OpenStdin).Return(nil, log.NewError("failed to initialise IO for container ID = test-id"))
return log.NewError("failed to initialise IO for container ID = test-id")
},
},
"test_container_stdin_true": {
Expand Down Expand Up @@ -627,9 +625,7 @@ func TestAttachContainer(t *testing.T) {

for testName, testCase := range tests {
t.Run(testName, func(t *testing.T) {
expectedError := testCase.mockExec()
actualError := testClient.AttachContainer(ctx, testCtr, testCase.attachConfig)
testutil.AssertError(t, expectedError, actualError)
testutil.AssertError(t, testCase.mockExec(), testClient.AttachContainer(ctx, testCtr, testCase.attachConfig))
})
}
}
Expand Down Expand Up @@ -689,9 +685,7 @@ func TestPauseContainer(t *testing.T) {

for testName, testCase := range tests {
t.Run(testName, func(t *testing.T) {
expectedError := testCase.mockExec(ctx, mockTask)
actualError := testClient.PauseContainer(ctx, testCase.arg)
testutil.AssertError(t, expectedError, actualError)
testutil.AssertError(t, testCase.mockExec(ctx, mockTask), testClient.PauseContainer(ctx, testCase.arg))
})
}
}
Expand Down Expand Up @@ -751,9 +745,7 @@ func TestUnpauseContainer(t *testing.T) {

for testName, testCase := range tests {
t.Run(testName, func(t *testing.T) {
expectedError := testCase.mockExec(ctx, mockTask)
actualError := testClient.UnpauseContainer(ctx, testCase.arg)
testutil.AssertError(t, expectedError, actualError)
testutil.AssertError(t, testCase.mockExec(ctx, mockTask), testClient.UnpauseContainer(ctx, testCase.arg))
})
}
}
Expand Down Expand Up @@ -942,9 +934,7 @@ func TestRestoreContainer(t *testing.T) {

for testName, testCase := range tests {
t.Run(testName, func(t *testing.T) {
expectedError := testCase.mockExec()
actualError := testClient.RestoreContainer(ctx, testCtr)
testutil.AssertError(t, expectedError, actualError)
testutil.AssertError(t, testCase.mockExec(), testClient.RestoreContainer(ctx, testCtr))
})
}
}
Expand Down Expand Up @@ -979,11 +969,10 @@ func TestSetContainerExitHooks(t *testing.T) {

testClient.SetContainerExitHooks(arg)

got := testClient.ctrdCache.containerExitHooks
testutil.AssertEqual(t, 1, len(got))
testutil.AssertEqual(t, 1, len(testClient.ctrdCache.containerExitHooks))

if reflect.ValueOf(got[0]).Pointer() != reflect.ValueOf(arg).Pointer() {
t.Errorf("SetContainerExitHooks() = %v, want %v", reflect.ValueOf(got[0]), reflect.ValueOf(arg))
if reflect.ValueOf(testClient.ctrdCache.containerExitHooks[0]).Pointer() != reflect.ValueOf(arg).Pointer() {
t.Errorf("SetContainerExitHooks() = %v, want %v", reflect.ValueOf(testClient.ctrdCache.containerExitHooks[0]), reflect.ValueOf(arg))
}
}

Expand Down Expand Up @@ -1174,9 +1163,7 @@ func TestCtrdClientUpdateContainer(t *testing.T) {
task: mockTask,
}

expectedErr := testCase.mockExec()
actualErr := testClient.UpdateContainer(ctx, testCase.ctr, testCase.resources)
testutil.AssertError(t, expectedErr, actualErr)
testutil.AssertError(t, testCase.mockExec(), testClient.UpdateContainer(ctx, testCase.ctr, testCase.resources))
})
}
}
Expand Down
15 changes: 7 additions & 8 deletions containerm/ctr/ctrd_container_create_opts_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021 Contributors to the Eclipse Foundation
// Copyright (c) 2023 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
Expand All @@ -15,15 +15,16 @@ package ctr
import (
"testing"

"github.com/containerd/containerd"
"github.com/containerd/containerd/images"
"github.com/eclipse-kanto/container-management/containerm/containers/types"
"github.com/eclipse-kanto/container-management/containerm/pkg/testutil"

"github.com/containerd/containerd"
"github.com/containerd/containerd/images"
)

func TestWithRuntimeOpts(t *testing.T) {
tests := map[string]struct {
container *types.Container
container *types.Container
}{
"test_runtime_type_v1": {
&types.Container{
Expand Down Expand Up @@ -55,8 +56,7 @@ func TestWithRuntimeOpts(t *testing.T) {
}
for name, test := range tests {
t.Run(name, func(t *testing.T) {
got := WithRuntimeOpts(test.container, "")
testutil.AssertNotNil(t, got)
testutil.AssertNotNil(t, WithRuntimeOpts(test.container, ""))
})
}
}
Expand Down Expand Up @@ -91,8 +91,7 @@ func TestWithSpecOpts(t *testing.T) {
}
for name, test := range tests {
t.Run(name, func(t *testing.T) {
got := WithSpecOpts(test.container, containerd.NewImage(&containerd.Client{}, images.Image{}), "/tmp/test")
testutil.AssertNotNil(t, got)
testutil.AssertNotNil(t, WithSpecOpts(test.container, containerd.NewImage(&containerd.Client{}, images.Image{}), "/tmp/test"))
})
}
}

0 comments on commit 390e05c

Please sign in to comment.