Tests to verify the Windows HostProcess
(t *testing.T)
| 46 | |
| 47 | // Tests to verify the Windows HostProcess |
| 48 | func TestWindowsHostProcess(t *testing.T) { |
| 49 | pauseImage := images.Get(images.Pause) |
| 50 | EnsureImageExists(t, pauseImage) |
| 51 | |
| 52 | t.Run("run as Local Service", func(t *testing.T) { |
| 53 | runHostProcess(t, false, pauseImage, defaultAction, hpcContainerOpt, localServiceUsername, defaultCommand) |
| 54 | }) |
| 55 | t.Run("run as Local System", func(t *testing.T) { |
| 56 | runHostProcess(t, false, pauseImage, defaultAction, hpcContainerOpt, localSystemUsername, defaultCommand) |
| 57 | }) |
| 58 | t.Run("run as unacceptable user", func(t *testing.T) { |
| 59 | runHostProcess(t, true, pauseImage, defaultAction, hpcContainerOpt, WithWindowsUsername("Guest"), defaultCommand) |
| 60 | }) |
| 61 | t.Run("run command on host", func(t *testing.T) { |
| 62 | cmd := WithCommand("Powershell", "/c", "Get-Command containerd.exe") |
| 63 | runHostProcess(t, false, pauseImage, defaultAction, hpcContainerOpt, localServiceUsername, cmd) |
| 64 | }) |
| 65 | t.Run("run withHostNetwork", func(t *testing.T) { |
| 66 | hostname, err := os.Hostname() |
| 67 | require.NoError(t, err) |
| 68 | cmd := WithCommand("Powershell", "/c", fmt.Sprintf("if ($env:COMPUTERNAME -ne %s) { exit -1 }", hostname)) |
| 69 | runHostProcess(t, false, pauseImage, defaultAction, hpcContainerOpt, localServiceUsername, cmd) |
| 70 | }) |
| 71 | t.Run("run with a different os.version image", func(t *testing.T) { |
| 72 | image := "docker.io/e2eteam/busybox:1.29-windows-amd64-1909" |
| 73 | EnsureImageExists(t, image) |
| 74 | runHostProcess(t, false, image, defaultAction, hpcContainerOpt, localServiceUsername, defaultCommand) |
| 75 | }) |
| 76 | t.Run("run and check stats", func(t *testing.T) { |
| 77 | var stats = func(t *testing.T, containerID string, containerConfig *v1.ContainerConfig) { |
| 78 | t.Logf("Fetch stats for container") |
| 79 | var ( |
| 80 | s *runtime.ContainerStats |
| 81 | err error |
| 82 | ) |
| 83 | require.NoError(t, Eventually(func() (bool, error) { |
| 84 | s, err = runtimeService.ContainerStats(containerID) |
| 85 | if err != nil { |
| 86 | return false, err |
| 87 | } |
| 88 | if s.GetWritableLayer().GetUsedBytes().GetValue() != 0 { |
| 89 | return true, nil |
| 90 | } |
| 91 | return false, nil |
| 92 | }, time.Second, 30*time.Second)) |
| 93 | |
| 94 | t.Logf("Verify stats received for container %q", containerConfig) |
| 95 | testStats(t, s, containerConfig) |
| 96 | } |
| 97 | runHostProcess(t, false, pauseImage, stats, hpcContainerOpt, localServiceUsername, defaultCommand, WithTestAnnotations(), WithTestLabels()) |
| 98 | }) |
| 99 | } |
| 100 | |
| 101 | func runHostProcess(t *testing.T, expectErr bool, image string, action hpcAction, opts ...ContainerOpts) { |
| 102 | t.Logf("Create a pod config and run sandbox container") |
nothing calls this directly
no test coverage detected
searching dependent graphs…