Skip to content

Commit

Permalink
chore: adding uuid property to forward config (podman-desktop#9783)
Browse files Browse the repository at this point in the history
* chore: adding uuid to forward config

Signed-off-by: axel7083 <[email protected]>

* chore: renaming uuid to id as suggested by @benoitf

Signed-off-by: axel7083 <[email protected]>

---------

Signed-off-by: axel7083 <[email protected]>
  • Loading branch information
axel7083 authored Nov 6, 2024
1 parent dc9d8c5 commit b63c506
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/api/src/kubernetes-port-forward-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ export interface ForwardOptions {
* @see PortMapping
*/
export interface ForwardConfig {
/**
* Identifier of the forward config
*/
id: string;
/**
* The name of the resource.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,7 @@ describe('PortForwardConnectionService', () => {

test('should start port forwarding successfully', async () => {
const forwardConfig: ForwardConfig = {
id: 'fake-id',
kind: WorkloadKind.POD,
name: 'test-pod',
namespace: 'default',
Expand Down Expand Up @@ -728,6 +729,7 @@ describe('PortForwardConnectionService', () => {
test('should start port forwarding on specified mapping', async () => {
const mapping: PortMapping = { localPort: 3001, remotePort: 8080 };
const forwardConfig: ForwardConfig = {
id: 'fake-id',
kind: WorkloadKind.POD,
name: 'test-pod',
namespace: 'default',
Expand All @@ -754,6 +756,7 @@ describe('PortForwardConnectionService', () => {

test('should throw an error if port forwarding fails', async () => {
const forwardConfig: ForwardConfig = {
id: 'fake-id',
kind: WorkloadKind.POD,
name: 'test-pod',
namespace: 'default',
Expand All @@ -777,6 +780,7 @@ describe('PortForwardConnectionService', () => {

test('should dispose all successful forwards if any fail', async () => {
const forwardConfig: ForwardConfig = {
id: 'fake-id',
kind: WorkloadKind.POD,
name: 'test-pod',
namespace: 'default',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/

import type { UUID } from 'node:crypto';
import { randomUUID } from 'node:crypto';

import type { KubeConfig } from '@kubernetes/client-node';
import { beforeEach, describe, expect, test, vi } from 'vitest';

Expand All @@ -35,6 +38,7 @@ vi.mock('/@/plugin/kubernetes/kubernetes-port-forward-storage.js');
vi.mock('/@/plugin/kubernetes/kubernetes-port-forward-validation.js');
vi.mock('/@/plugin/util/port.js');
vi.mock('/@/plugin/directories.js');
vi.mock('node:crypto');

class TestKubernetesPortForwardServiceProvider extends KubernetesPortForwardServiceProvider {
public override getKubeConfigKey(kubeConfig: KubeConfig): string {
Expand Down Expand Up @@ -68,6 +72,7 @@ describe('KubernetesPortForwardService', () => {
};

const sampleForwardConfig: ForwardConfig = {
id: 'fake-id',
name: 'test-name',
namespace: 'test-namespace',
kind: WorkloadKind.POD,
Expand All @@ -80,6 +85,7 @@ describe('KubernetesPortForwardService', () => {
};

const complexForwardConfig: ForwardConfig = {
id: 'fake-id',
name: 'test-name',
namespace: 'test-namespace',
kind: WorkloadKind.POD,
Expand Down Expand Up @@ -112,6 +118,7 @@ describe('KubernetesPortForwardService', () => {
mockForwardingConnectionService,
apiSenderMock,
);
vi.mocked(randomUUID).mockReturnValue('fake-id' as UUID);
});

test('should create a forward configuration', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/
import { randomUUID } from 'node:crypto';

import type { KubeConfig } from '@kubernetes/client-node';

import type { ApiSenderType } from '/@/plugin/api.js';
Expand Down Expand Up @@ -117,6 +119,7 @@ export class KubernetesPortForwardService implements IDisposable {
let result: UserForwardConfig;
if (userForwardConfig) {
result = await this.configManagementService.updateForward(userForwardConfig, {
id: userForwardConfig.id,
name: options.name,
forwards: [...userForwardConfig.forwards, options.forward],
namespace: options.namespace,
Expand All @@ -125,6 +128,7 @@ export class KubernetesPortForwardService implements IDisposable {
});
} else {
result = await this.configManagementService.createForward({
id: randomUUID(),
name: options.name,
forwards: [options.forward],
namespace: options.namespace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ describe('FileBasedConfigStorage', () => {
};

const sampleConfig: UserForwardConfig = {
id: 'fake-id',
name: 'test-name',
namespace: 'test-namespace',
kind: WorkloadKind.POD,
Expand Down Expand Up @@ -257,6 +258,7 @@ describe('FileBasedConfigStorage', () => {

describe('MemoryBasedConfigStorage', () => {
const sampleConfig: UserForwardConfig = {
id: 'fake-id',
name: 'test-name',
namespace: 'test-namespace',
kind: WorkloadKind.POD,
Expand Down Expand Up @@ -336,6 +338,7 @@ describe('ConfigManagementService', () => {
} as unknown as ForwardConfigStorage;

const sampleConfig: UserForwardConfig = {
id: 'fake-id',
name: 'test-name',
namespace: 'test-namespace',
kind: WorkloadKind.POD,
Expand Down Expand Up @@ -381,6 +384,7 @@ describe('ConfigManagementService', () => {
namespace: 'default',
kind: WorkloadKind.POD,
name: 'hihi',
id: 'fake-id',
};

const newConfig = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { type ForwardConfig, WorkloadKind } from '/@api/kubernetes-port-forward-

describe('ForwardConfigRequirements', () => {
const validConfig: ForwardConfig = {
id: 'fake-id',
name: 'validName',
namespace: 'validNamespace',
kind: WorkloadKind.POD,
Expand Down
2 changes: 2 additions & 0 deletions packages/preload/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ test('createKubernetesPortForward', async () => {
);

const userPortForward: UserForwardConfig = {
id: 'fake-id',
displayName: 'My port forward',
namespace: 'kubernetes',
name: 'service',
Expand Down Expand Up @@ -259,6 +260,7 @@ test('deleteKubernetesPortForward', async () => {
);

const userPortForward: UserForwardConfig = {
id: 'fake-id',
displayName: 'My port forward',
namespace: 'kubernetes',
name: 'service',
Expand Down
1 change: 1 addition & 0 deletions packages/renderer/src/lib/kube/details/KubePort.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ beforeEach(() => {
});

const DUMMY_FORWARD_CONFIG: UserForwardConfig = {
id: 'fake-id',
name: 'dummy-pod-name',
namespace: 'dummy-ns',
kind: WorkloadKind.POD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { type UserForwardConfig, WorkloadKind } from '/@api/kubernetes-port-forw
vi.mock('/@/stores/kubernetes-contexts-state', async () => ({}));

const MOCKED_USER_FORWARD_CONFIG: UserForwardConfig = {
id: 'fake-id',
name: 'dummy-pod-name',
namespace: 'dummy-ns',
kind: WorkloadKind.POD,
Expand Down

0 comments on commit b63c506

Please sign in to comment.