Skip to content

Commit

Permalink
Adding a test case on WSL1
Browse files Browse the repository at this point in the history
If this works as expected, one test case should run under WSL1.
Without the current patch that would block forever.
With the launcher patch, cloud-init status --wait won't even run, so no hangs.
  • Loading branch information
CarlosNihelton committed Dec 17, 2024
1 parent bb72652 commit 472a2d8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions e2e/launchertester/basic_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"fmt"
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
Expand Down Expand Up @@ -45,6 +46,7 @@ func TestSetupWithCloudInit(t *testing.T) {
testCases := map[string]struct {
install_root bool
withRegistryUser string
withWSL1 bool
wantUser string
wantFile string
}{
Expand All @@ -56,6 +58,7 @@ func TestSetupWithCloudInit(t *testing.T) {
"With only remote users": {wantUser: "testmail"},
"With broken passwd file": {wantUser: "testmail"},
"Without checking user": {install_root: true, wantUser: "root", wantFile: "/home/testuser/with_default_user.done"},
"Do not block on WSL1": {install_root: true, wantUser: "root"},
}

home, err := os.UserHomeDir()
Expand All @@ -77,6 +80,13 @@ func TestSetupWithCloudInit(t *testing.T) {

for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
if tc.withWSL1 {
require.NoError(t, exec.Command("wsl.exe", "--set-default-version", "1").Run(), "Setup: Cannot set WSL1 as default version")
t.Cleanup(func() {
t.Log("Cleaning up: Setting WSL2 back as default version")
require.NoError(t, exec.Command("wsl.exe", "--set-default-version", "2").Run(), "Setup: Cannot set WSL2 back as default version")
})
}
wslSetup(t)

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#cloud-config
users:
- name: nontestuser
groups: sudo
shell: /bin/bash
sudo: ALL=(ALL) NOPASSWD:ALL
- name: testuser
groups: sudo
shell: /bin/bash
sudo: ALL=(ALL) NOPASSWD:ALL

write_files:
- path: /etc/wsl.conf
append: true
content: |
[user]
default=testuser

runcmd:
- touch /home/testuser/with_default_user.done

0 comments on commit 472a2d8

Please sign in to comment.