forked from eclipse-kanto/container-management
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[eclipse-kanto#51] Imporved unit tests.
Signed-off-by: Daniel Milchev [email protected]
- Loading branch information
1 parent
1e06303
commit e28f185
Showing
5 changed files
with
214 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// Copyright (c) 2021 Contributors to the Eclipse Foundation | ||
// | ||
// See the NOTICE file(s) distributed with this work for additional | ||
// information regarding copyright ownership. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License 2.0 which is available at | ||
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
// which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
|
||
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" | ||
) | ||
|
||
func TestWithRuntimeOpts(t *testing.T) { | ||
tests := map[string]struct { | ||
container *types.Container | ||
runtimeRootPath string | ||
}{ | ||
"test_runtime_type_v1": { | ||
&types.Container{ | ||
ID: testCtrID1, | ||
Name: testContainerName, | ||
HostConfig: &types.HostConfig{ | ||
Runtime: types.RuntimeTypeV1, | ||
}, | ||
}, | ||
"", | ||
}, | ||
"test_runtime_type_v2": { | ||
&types.Container{ | ||
ID: testCtrID1, | ||
Name: testContainerName, | ||
HostConfig: &types.HostConfig{ | ||
Runtime: types.RuntimeTypeV2runcV1, | ||
}, | ||
}, | ||
"", | ||
}, | ||
"testing_default": { | ||
&types.Container{ | ||
ID: testCtrID1, | ||
Name: testContainerName, | ||
HostConfig: &types.HostConfig{ | ||
Runtime: "", | ||
}, | ||
}, | ||
"", | ||
}, | ||
} | ||
for name, test := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
got := WithRuntimeOpts(test.container, test.runtimeRootPath) | ||
testutil.AssertNotNil(t, got) | ||
}) | ||
} | ||
} | ||
|
||
func TestWithSpecOpts(t *testing.T) { | ||
|
||
tests := map[string]struct { | ||
container *types.Container | ||
image containerd.Image | ||
execRoot string | ||
}{ | ||
"test_privileged": { | ||
&types.Container{ | ||
Config: &types.ContainerConfiguration{ | ||
Cmd: []string{"test"}, | ||
Env: []string{"test"}, | ||
}, | ||
HostConfig: &types.HostConfig{ | ||
Privileged: true, | ||
}, | ||
}, | ||
containerd.NewImage(&containerd.Client{}, images.Image{}), | ||
"/tmp/test", | ||
}, | ||
"test_extra_capabilities": { | ||
&types.Container{ | ||
Config: &types.ContainerConfiguration{ | ||
Cmd: []string{"test"}, | ||
Env: []string{"test"}, | ||
}, | ||
HostConfig: &types.HostConfig{ | ||
ExtraCapabilities: []string{"CAP_NET_ADMIN"}, | ||
}, | ||
}, | ||
containerd.NewImage(&containerd.Client{}, images.Image{}), | ||
"/tmp/test", | ||
}, | ||
} | ||
for name, tests := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
got := WithSpecOpts(tests.container, tests.image, tests.execRoot) | ||
testutil.AssertNotNil(t, got) | ||
}) | ||
} | ||
} |