Add tests cases

Signed-off-by: James Sturtevant <jsturtevant@gmail.com>
This commit is contained in:
James Sturtevant
2023-11-01 15:23:38 -07:00
parent 0ffc3e9873
commit a67efe88db
2 changed files with 128 additions and 14 deletions

View File

@@ -127,7 +127,7 @@ func runHostProcess(t *testing.T, expectErr bool, image string, action hpcAction
action(t, cn, containerConfig)
}
func runAndRemoveContainer(t *testing.T, sb string, sbConfig *runtime.PodSandboxConfig, cnConfig *runtime.ContainerConfig) {
func runExecAndRemoveContainer(t *testing.T, sb string, sbConfig *runtime.PodSandboxConfig, cnConfig *runtime.ContainerConfig) {
t.Log("Create the container")
cn, err := runtimeService.CreateContainer(sb, cnConfig, sbConfig)
require.NoError(t, err)
@@ -136,6 +136,13 @@ func runAndRemoveContainer(t *testing.T, sb string, sbConfig *runtime.PodSandbox
// Wait few seconds for the container to be completely initialized
time.Sleep(5 * time.Second)
cmd := []string{"cmd", "/c", "echo", "hello"}
timeoutDuration := 10 * time.Second
stdout, _, err := runtimeService.ExecSync(cn, cmd, timeoutDuration)
require.NoError(t, err)
t.Logf("Exec response: %v", stdout)
require.Equal(t, "hello\r\n", string(stdout))
t.Log("Stop the container")
require.NoError(t, runtimeService.StopContainer(cn, 0))
t.Log("Remove the container")
@@ -187,6 +194,6 @@ func TestArgsEscapedImagesOnWindows(t *testing.T) {
localSystemUsername,
)
runAndRemoveContainer(t, sb, sbConfig, cnConfigWithCtrCmd)
runAndRemoveContainer(t, sb, sbConfig, cnConfigNoCtrCmd)
runExecAndRemoveContainer(t, sb, sbConfig, cnConfigWithCtrCmd)
runExecAndRemoveContainer(t, sb, sbConfig, cnConfigNoCtrCmd)
}