Skip to content

Commit 7d04fbd

Browse files
authored
Merge pull request #2191 from kubernetes-client/inClusterTest
Improve loadFromCluster testing
2 parents d53ff24 + 827c2b7 commit 7d04fbd

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/config_test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,29 @@ describe('KubeConfig', () => {
132132
});
133133
});
134134

135+
describe('loadFromCluster', () => {
136+
it('should load from cluster', () => {
137+
process.env.KUBERNETES_SERVICE_HOST = 'example.com';
138+
process.env.KUBERNETES_SERVICE_PORT = '8080';
139+
140+
const kc = new KubeConfig();
141+
kc.loadFromCluster();
142+
const expectedCluster = {
143+
caFile: '/var/run/secrets/kubernetes.io/serviceaccount/ca.crt',
144+
name: 'inCluster',
145+
server: 'http://example.com:8080',
146+
skipTLSVerify: false,
147+
};
148+
149+
process.env.KUBERNETES_SERVICE_HOST = undefined;
150+
process.env.KUBERNETES_SERVICE_PORT = undefined;
151+
152+
strictEqual(kc.getCurrentContext(), 'inClusterContext');
153+
deepEqual(kc.getCurrentCluster(), expectedCluster);
154+
deepEqual(kc.getCluster(kc.getContextObject(kc.getCurrentContext())!.cluster), expectedCluster);
155+
});
156+
});
157+
135158
describe('loadFromClusterAndUser', () => {
136159
it('should load from cluster and user', () => {
137160
const kc = new KubeConfig();

0 commit comments

Comments
 (0)