Skip to content

Commit bfe9db3

Browse files
committed
add test
1 parent c84fe3e commit bfe9db3

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: v1
2+
kind: Config
3+
clusters:
4+
- name: inCluster
5+
cluster:
6+
server: https://0.0.0.0:443
7+
certificate-authority: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
8+
insecure-skip-tls-verify: false
9+
users:
10+
- name: developer
11+
user:
12+
token: token
13+
contexts:
14+
- name: logged-user
15+
context:
16+
user: developer
17+
cluster: inCluster
18+
name: logged-user
19+
preferences: {}
20+
current-context: logged-user

packages/dashboard-backend/src/devworkspaceClient/services/__tests__/kubeConfigApi.spec.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import * as mockClient from '@kubernetes/client-node';
1616
import { CoreV1Api, V1PodList } from '@kubernetes/client-node';
17+
import fs from 'fs';
1718

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

31-
const mockExecCatKubeConfig = jest.fn().mockReturnValue({
32+
let mockExecCatKubeConfig = jest.fn().mockReturnValue({
3233
stdOut: '',
3334
stdError: '',
3435
});
@@ -65,6 +66,9 @@ const config = JSON.stringify({
6566
apiVersion: 'v1',
6667
kind: 'Config',
6768
'current-context': 'logged-user',
69+
contexts: [],
70+
clusters: [],
71+
users: [],
6872
});
6973

7074
describe('Kubernetes Config API Service', () => {
@@ -146,6 +150,23 @@ describe('Kubernetes Config API Service', () => {
146150
expect.anything(),
147151
);
148152
});
153+
test('should merge configs', async () => {
154+
const configContent = fs.readFileSync(__dirname + '/fixtures/kubeconfig.yaml', 'utf-8');
155+
mockExecCatKubeConfig = jest.fn().mockReturnValue({
156+
stdOut: configContent,
157+
stdError: '',
158+
});
159+
await kubeConfigService.injectKubeConfig(namespace, 'wksp-id');
160+
161+
expect(spyExec).toHaveBeenNthCalledWith(
162+
5,
163+
workspaceName,
164+
namespace,
165+
containerName,
166+
['sh', '-c', `echo '${configContent}' > ${kubeConfigDir}/config`],
167+
expect.anything(),
168+
);
169+
});
149170
});
150171

151172
function buildListNamespacedPod(): { body: V1PodList } {

0 commit comments

Comments
 (0)