Skip to content

Commit

Permalink
Move rdctl --output reg tests to bats.
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Promislow <epromislow@suse.com>
  • Loading branch information
ericpromislow committed Jun 21, 2023
1 parent d79b516 commit 94ca018
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 80 deletions.
150 changes: 150 additions & 0 deletions bats/tests/preferences/list-settings-output.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
load '../helpers/load'

RD_USE_IMAGE_ALLOW_LIST=true

@test 'factory reset' {
factory_reset
# bypass the defaults deployment file
mkdir -p "$(dirname "${PATH_CONFIG_FILE})")"
touch "$PATH_CONFIG_FILE"
}

@test 'start app' {
start_container_engine
wait_for_container_engine
}

@test 'report parameters for json' {
run rdctl list-settings '--output=json,fish'
assert_failure
assert_output --partial 'the json output format takes no sub-formats, got "json,fish"'
}

@test 'report unrecognized output-options' {
run rdctl list-settings '--output=bickley,ruff'
assert_failure
assert_output --partial $'expecting an output format of \'json\' or \'reg\', got "bickley,ruff"'
}

@test 'report unrecognized reg sub-options' {
run rdctl list-settings '--output=reg,hklm,ruff'
assert_failure
assert_output --partial 'expecting a reg output-format parameter, got "ruff" in "reg,hklm,ruff"'
}

@test 'report duplicate reg hives' {
for x in hklm hkcu; do
for y in hklm hkcu; do
option="reg,${x},locked,${y}"
run rdctl list-settings "--output=${option}"
assert_failure
assert_output --partial $"already specified registry hive \"${x}\" in \"${option}\", can't respecify"
done
done
}

@test 'report duplicate registry sections' {
for x in defaults locked; do
for y in defaults locked; do
option="reg,${x},hkcu,${y}"
run rdctl list-settings "--output=${option}"
assert_failure
assert_output --partial $"already specified registry section \"${x}\" in \"${option}\", can't respecify"
done
done
}

@test 'generates registry output' {
run rdctl list-settings --output reg
assert_success
assert_output <<'EOF'
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Profiles]
[HKEY_LOCAL_MACHINE\SOFTWARE\Profiles\Rancher Desktop]
[HKEY_LOCAL_MACHINE\SOFTWARE\Profiles\Rancher Desktop\defaults]
"version"=dword:8
[HKEY_LOCAL_MACHINE\SOFTWARE\Profiles\Rancher Desktop\defaults\application]
"adminAccess"=dword:0
"debug"=dword:0
"pathManagementStrategy"="rcfiles"
"autoStart"=dword:0
"startInBackground"=dword:0
"hideNotificationIcon"=dword:0
[HKEY_LOCAL_MACHINE\SOFTWARE\Profiles\Rancher Desktop\defaults\application\extensions]
[HKEY_LOCAL_MACHINE\SOFTWARE\Profiles\Rancher Desktop\defaults\application\extensions\allowed]
"enabled"=dword:0
[HKEY_LOCAL_MACHINE\SOFTWARE\Profiles\Rancher Desktop\defaults\application\telemetry]
"enabled"=dword:1
[HKEY_LOCAL_MACHINE\SOFTWARE\Profiles\Rancher Desktop\defaults\application\updater]
"enabled"=dword:0
[HKEY_LOCAL_MACHINE\SOFTWARE\Profiles\Rancher Desktop\defaults\application\window]
"quitOnClose"=dword:0
[HKEY_LOCAL_MACHINE\SOFTWARE\Profiles\Rancher Desktop\defaults\containerEngine]
"name"="moby"
[HKEY_LOCAL_MACHINE\SOFTWARE\Profiles\Rancher Desktop\defaults\containerEngine\allowedImages]
"enabled"=dword:1
"patterns"=hex(7):66,00,69,00,73,00,68,00,00,00,73,00,68,00,65,00,65,00,70,00,00,00,63,00,6f,00,77,00,73,00,00,00,00,00
[HKEY_LOCAL_MACHINE\SOFTWARE\Profiles\Rancher Desktop\defaults\virtualMachine]
"memoryInGB"=dword:4
"numberCPUs"=dword:2
"hostResolver"=dword:1
[HKEY_LOCAL_MACHINE\SOFTWARE\Profiles\Rancher Desktop\defaults\kubernetes]
"version"="1.25.9"
"port"=dword:192b
"enabled"=dword:1
[HKEY_LOCAL_MACHINE\SOFTWARE\Profiles\Rancher Desktop\defaults\kubernetes\options]
"traefik"=dword:1
"flannel"=dword:1
[HKEY_LOCAL_MACHINE\SOFTWARE\Profiles\Rancher Desktop\defaults\kubernetes\ingress]
"localhostOnly"=dword:0
[HKEY_LOCAL_MACHINE\SOFTWARE\Profiles\Rancher Desktop\defaults\experimental]
[HKEY_LOCAL_MACHINE\SOFTWARE\Profiles\Rancher Desktop\defaults\experimental\virtualMachine]
"socketVMNet"=dword:0
"networkingTunnel"=dword:0
"type"="qemu"
"useRosetta"=dword:0
[HKEY_LOCAL_MACHINE\SOFTWARE\Profiles\Rancher Desktop\defaults\experimental\virtualMachine\mount]
"type"="reverse-sshfs"
[HKEY_LOCAL_MACHINE\SOFTWARE\Profiles\Rancher Desktop\defaults\experimental\virtualMachine\mount\9p]
"securityModel"="none"
"protocolVersion"="9p2000.L"
"msizeInKib"=dword:80
"cacheMode"="mmap"
[HKEY_LOCAL_MACHINE\SOFTWARE\Profiles\Rancher Desktop\defaults\experimental\virtualMachine\proxy]
"enabled"=dword:0
"address"=""
"password"=""
"port"=dword:c38
"username"=""
[HKEY_LOCAL_MACHINE\SOFTWARE\Profiles\Rancher Desktop\defaults\portForwarding]
"includeKubernetesServices"=dword:0
[HKEY_LOCAL_MACHINE\SOFTWARE\Profiles\Rancher Desktop\defaults\images]
"showAll"=dword:1
"namespace"="k8s.io"
[HKEY_LOCAL_MACHINE\SOFTWARE\Profiles\Rancher Desktop\defaults\diagnostics]
"showMuted"=dword:0
EOF
}
80 changes: 0 additions & 80 deletions e2e/rdctl.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,86 +143,6 @@ test.describe('Command server', () => {

test.afterAll(() => teardown(electronApp, __filename));

test.describe('rdctl -pre', () => {
test.describe('list-settings output formats', () => {
function regToJSON(regFormatOutput: string): RecursivePartial<Settings> {
return {};
}
test.describe('detects option errors', () => {
test("it doesn't allow json sub-options", async() => {
const { stdout, stderr } = await rdctl(['list-settings', '--output=json,fish']);

expect({ stdout, stderr }).toEqual({
stderr: expect.stringContaining(`the json output format takes no sub-formats, got "json,fish"`),
stdout: '',
});
});
test("it doesn't allow unrecognized output-options", async() => {
const { stdout, stderr } = await rdctl(['list-settings', '--output=bickley,ruff']);

expect({ stdout, stderr }).toEqual({
stderr: expect.stringContaining(`expecting an output format of 'json' or 'reg', got "bickley,ruff"`),
stdout: '',
});
});
test("it doesn't allow unrecognized reg sub-options", async() => {
const { stdout, stderr } = await rdctl(['list-settings', '--output=reg,hklm,ruff']);

expect({ stdout, stderr }).toEqual({
stderr: expect.stringContaining(`expecting a reg output-format parameter, got "ruff" in "reg,hklm,ruff"`),
stdout: '',
});
});
test("it doesn't allow duplicate reg hives", async() => {
let { stdout, stderr } = await rdctl(['list-settings', '--output=reg,hklm,locked,hkcu']);

expect({ stdout, stderr }).toEqual({
stderr: expect.stringContaining(`already specified registry hive "hklm" in "reg,hklm,locked,hkcu", can't respecify`),
stdout: '',
});

({ stdout, stderr } = await rdctl(['list-settings', '--output=reg,hklm,locked,hklm']));
expect({ stdout, stderr }).toEqual({
stderr: expect.stringContaining(`already specified registry hive "hklm" in "reg,hklm,locked,hklm", can't respecify`),
stdout: '',
});

({ stdout, stderr } = await rdctl(['list-settings', '--output=reg,hkcu,locked,hkcu']));
expect({ stdout, stderr }).toEqual({
stderr: expect.stringContaining(`already specified registry hive "hkcu" in "reg,hkcu,locked,hkcu", can't respecify`),
stdout: '',
});

({ stdout, stderr } = await rdctl(['list-settings', '--output=reg,hkcu,locked,hklm']));
expect({ stdout, stderr }).toEqual({
stderr: expect.stringContaining(`already specified registry hive "hkcu" in "reg,hkcu,locked,hklm", can't respecify`),
stdout: '',
});
});
test("it doesn't allow duplicate reg sections", async() => {
const { stdout, stderr } = await rdctl(['list-settings', '--output=reg,hklm,locked,defaults']);

expect({ stdout, stderr }).toEqual({
stderr: expect.stringContaining(`already specified registry section "locked" in "reg,hklm,locked,defaults", can't respecify`),
stdout: '',
});
});
});
test('it converts settings to reg files', async() => {
await rdctl(['settings', '--method', 'PUT', '--body', JSON.stringify(defaultSettings)]);
const { stdout, stderr, error } = await rdctl(['list-settings', '--output=reg']);

expect({
stdout, stderr, error,
}).toEqual({
error: undefined,
stderr: '',
stdout: expect.stringContaining('[HKEY_LOCAL_MACHINE\\SOFTWARE\\Rancher Desktop\\Profile\\defaults]'),
});
expect(regToJSON(stdout)).toMatchObject(defaultSettings);
});
});
});
test('should load Kubernetes API', async() => {
const navPage = new NavPage(page);

Expand Down

0 comments on commit 94ca018

Please sign in to comment.