Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
vinokurig committed Dec 18, 2024
1 parent c84fe3e commit bfe9db3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: v1
kind: Config
clusters:
- name: inCluster
cluster:
server: https://0.0.0.0:443
certificate-authority: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
insecure-skip-tls-verify: false
users:
- name: developer
user:
token: token
contexts:
- name: logged-user
context:
user: developer
cluster: inCluster
name: logged-user
preferences: {}
current-context: logged-user
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import * as mockClient from '@kubernetes/client-node';
import { CoreV1Api, V1PodList } from '@kubernetes/client-node';
import fs from 'fs';

import * as helper from '@/devworkspaceClient/services/helpers/exec';
import { KubeConfigApiService } from '@/devworkspaceClient/services/kubeConfigApi';
Expand All @@ -28,7 +29,7 @@ const mockExecPrintenvHome = jest.fn().mockReturnValue({
stdError: '',
});

const mockExecCatKubeConfig = jest.fn().mockReturnValue({
let mockExecCatKubeConfig = jest.fn().mockReturnValue({
stdOut: '',
stdError: '',
});
Expand Down Expand Up @@ -65,6 +66,9 @@ const config = JSON.stringify({
apiVersion: 'v1',
kind: 'Config',
'current-context': 'logged-user',
contexts: [],
clusters: [],
users: [],
});

describe('Kubernetes Config API Service', () => {
Expand Down Expand Up @@ -146,6 +150,23 @@ describe('Kubernetes Config API Service', () => {
expect.anything(),
);
});
test('should merge configs', async () => {
const configContent = fs.readFileSync(__dirname + '/fixtures/kubeconfig.yaml', 'utf-8');
mockExecCatKubeConfig = jest.fn().mockReturnValue({
stdOut: configContent,
stdError: '',
});
await kubeConfigService.injectKubeConfig(namespace, 'wksp-id');

expect(spyExec).toHaveBeenNthCalledWith(
5,
workspaceName,
namespace,
containerName,
['sh', '-c', `echo '${configContent}' > ${kubeConfigDir}/config`],
expect.anything(),
);
});
});

function buildListNamespacedPod(): { body: V1PodList } {
Expand Down

0 comments on commit bfe9db3

Please sign in to comment.