14
14
15
15
import * as mockClient from '@kubernetes/client-node' ;
16
16
import { CoreV1Api , V1PodList } from '@kubernetes/client-node' ;
17
+ import fs from 'fs' ;
17
18
18
19
import * as helper from '@/devworkspaceClient/services/helpers/exec' ;
19
20
import { KubeConfigApiService } from '@/devworkspaceClient/services/kubeConfigApi' ;
@@ -28,7 +29,7 @@ const mockExecPrintenvHome = jest.fn().mockReturnValue({
28
29
stdError : '' ,
29
30
} ) ;
30
31
31
- const mockExecCatKubeConfig = jest . fn ( ) . mockReturnValue ( {
32
+ let mockExecCatKubeConfig = jest . fn ( ) . mockReturnValue ( {
32
33
stdOut : '' ,
33
34
stdError : '' ,
34
35
} ) ;
@@ -65,6 +66,9 @@ const config = JSON.stringify({
65
66
apiVersion : 'v1' ,
66
67
kind : 'Config' ,
67
68
'current-context' : 'logged-user' ,
69
+ contexts : [ ] ,
70
+ clusters : [ ] ,
71
+ users : [ ] ,
68
72
} ) ;
69
73
70
74
describe ( 'Kubernetes Config API Service' , ( ) => {
@@ -146,6 +150,23 @@ describe('Kubernetes Config API Service', () => {
146
150
expect . anything ( ) ,
147
151
) ;
148
152
} ) ;
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
+ } ) ;
149
170
} ) ;
150
171
151
172
function buildListNamespacedPod ( ) : { body : V1PodList } {
0 commit comments