Skip to content

Commit

Permalink
Merge pull request rancher-sandbox#5811 from s0nea/5753
Browse files Browse the repository at this point in the history
Show entries on Port Forwarding screenshot
  • Loading branch information
ericpromislow authored Nov 2, 2023
2 parents 01a2f6e + 5792886 commit 59e1810
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 9 deletions.
13 changes: 11 additions & 2 deletions pkg/rancher-desktop/backend/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import LimaBackend from './lima';
import MockBackend from './mock';
import WSLBackend from './wsl';

import { LimaKubernetesBackendMock, WSLKubernetesBackendMock } from '@pkg/backend/mock_screenshots';
import DockerDirManager from '@pkg/utils/dockerDirManager';

export default function factory(arch: Architecture, dockerDirManager: DockerDirManager): VMBackend {
Expand All @@ -20,11 +21,19 @@ export default function factory(arch: Architecture, dockerDirManager: DockerDirM
case 'linux':
case 'darwin':
return new LimaBackend(arch, dockerDirManager, (backend: LimaBackend) => {
return new LimaKubernetesBackend(arch, backend);
if (process.env.RD_MOCK_FOR_SCREENSHOTS) {
return new LimaKubernetesBackendMock(arch, backend);
} else {
return new LimaKubernetesBackend(arch, backend);
}
});
case 'win32':
return new WSLBackend((backend: WSLBackend) => {
return new WSLKubernetesBackend(backend);
if (process.env.RD_MOCK_FOR_SCREENSHOTS) {
return new WSLKubernetesBackendMock(backend);
} else {
return new WSLKubernetesBackend(backend);
}
});
default:
throw new Error(`OS "${ platform }" is not supported.`);
Expand Down
4 changes: 2 additions & 2 deletions pkg/rancher-desktop/backend/kube/lima.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export default class LimaKubernetesBackend extends events.EventEmitter implement
* Start Kubernetes.
* @returns The Kubernetes endpoint
*/
async start(config_: BackendSettings, kubernetesVersion: semver.SemVer): Promise<string> {
async start(config_: BackendSettings, kubernetesVersion: semver.SemVer, kubeClient?: KubeClient): Promise<string> {
const config = this.cfg = clone(config_);
let k3sEndpoint = '';

Expand Down Expand Up @@ -186,7 +186,7 @@ export default class LimaKubernetesBackend extends events.EventEmitter implement
return k3sConfigString;
}));

this.client = new KubeClient();
this.client = kubeClient || new KubeClient();

await this.progressTracker.action(
'Waiting for services',
Expand Down
4 changes: 2 additions & 2 deletions pkg/rancher-desktop/backend/kube/wsl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export default class WSLKubernetesBackend extends events.EventEmitter implements
'install-k3s', version.raw, await this.vm.wslify(path.join(paths.cache, 'k3s')));
}

async start(config: BackendSettings, activeVersion: semver.SemVer): Promise<string> {
async start(config: BackendSettings, activeVersion: semver.SemVer, kubeClient?: KubeClient): Promise<string> {
if (!config) {
throw new Error('no config!');
}
Expand Down Expand Up @@ -218,7 +218,7 @@ export default class WSLKubernetesBackend extends events.EventEmitter implements
async() => await this.vm.execCommand({ capture: true }, await this.vm.getWSLHelperPath(), 'k3s', 'kubeconfig', rdNetworking));
});

const client = this.client = new KubeClient();
const client = this.client = kubeClient || new KubeClient();

await this.progressTracker.action(
'Waiting for services',
Expand Down
14 changes: 11 additions & 3 deletions pkg/rancher-desktop/backend/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@ import util from 'util';
import semver from 'semver';

import {
BackendSettings, execOptions, State, RestartReasons, VMExecutor, BackendEvents,
BackendEvents, BackendSettings, execOptions, RestartReasons, State, VMExecutor,
} from './backend';
import {
ContainerBasicOptions, ContainerComposeExecOptions, ContainerComposeOptions, ContainerComposePortOptions, ContainerEngineClient, ContainerRunClientOptions, ContainerRunOptions, ContainerStopOptions, ReadableProcess,
ContainerBasicOptions,
ContainerComposeExecOptions,
ContainerComposeOptions,
ContainerComposePortOptions,
ContainerEngineClient,
ContainerRunClientOptions,
ContainerRunOptions,
ContainerStopOptions,
ReadableProcess,
} from './containerClient';
import { KubernetesBackend, KubernetesError, KubernetesBackendEvents } from './k8s';
import { KubernetesBackend, KubernetesBackendEvents, KubernetesError } from './k8s';
import ProgressTracker from './progressTracker';

import K3sHelper from '@pkg/backend/k3sHelper';
Expand Down
40 changes: 40 additions & 0 deletions pkg/rancher-desktop/backend/mock_screenshots.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import semver from 'semver';

import { BackendSettings } from '@pkg/backend/backend';
import { KubeClient, ServiceEntry } from '@pkg/backend/kube/client';
import LimaKubernetesBackend from '@pkg/backend/kube/lima';
import WSLKubernetesBackend from '@pkg/backend/kube/wsl';

export class LimaKubernetesBackendMock extends LimaKubernetesBackend {
start(config_: BackendSettings, kubernetesVersion: semver.SemVer): Promise<string> {
return super.start(config_, kubernetesVersion, new KubeClientMock());
}
}

export class WSLKubernetesBackendMock extends WSLKubernetesBackend {
start(config_: BackendSettings, kubernetesVersion: semver.SemVer): Promise<string> {
return super.start(config_, kubernetesVersion, new KubeClientMock());
}
}

class KubeClientMock extends KubeClient {
listServices(namespace: string | undefined = undefined): ServiceEntry[] {
return [{
namespace: 'default',
name: 'nginx',
portName: 'http',
port: 8080,
listenPort: 30001,
}, {
namespace: 'default',
name: 'wordpress',
portName: 'http',
port: 8080,
}, {
namespace: 'default',
name: 'wordpress',
portName: 'https',
port: 443,
}];
}
}
3 changes: 3 additions & 0 deletions screenshots/screenshots.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ test.describe.serial('Main App Test', () => {
});

test('PortForwarding Page', async({ colorScheme }) => {
const portForwardingPage = await navPage.navigateTo('PortForwarding');

await expect(portForwardingPage.page.getByRole('row')).toHaveCount(4);
await screenshot.take('PortForwarding', navPage);
});

Expand Down

0 comments on commit 59e1810

Please sign in to comment.