From 827c2b72286b218dcc2a7edbbae87b3ee9674158 Mon Sep 17 00:00:00 2001 From: Brendan Burns <5751682+brendandburns@users.noreply.github.com> Date: Fri, 31 Jan 2025 17:14:17 +0000 Subject: [PATCH] Improve loadFromCluster testing --- src/config_test.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/config_test.ts b/src/config_test.ts index eaecefdc07..969db82a54 100644 --- a/src/config_test.ts +++ b/src/config_test.ts @@ -132,6 +132,29 @@ describe('KubeConfig', () => { }); }); + describe('loadFromCluster', () => { + it('should load from cluster', () => { + process.env.KUBERNETES_SERVICE_HOST = 'example.com'; + process.env.KUBERNETES_SERVICE_PORT = '8080'; + + const kc = new KubeConfig(); + kc.loadFromCluster(); + const expectedCluster = { + caFile: '/var/run/secrets/kubernetes.io/serviceaccount/ca.crt', + name: 'inCluster', + server: 'http://example.com:8080', + skipTLSVerify: false, + }; + + process.env.KUBERNETES_SERVICE_HOST = undefined; + process.env.KUBERNETES_SERVICE_PORT = undefined; + + strictEqual(kc.getCurrentContext(), 'inClusterContext'); + deepEqual(kc.getCurrentCluster(), expectedCluster); + deepEqual(kc.getCluster(kc.getContextObject(kc.getCurrentContext())!.cluster), expectedCluster); + }); + }); + describe('loadFromClusterAndUser', () => { it('should load from cluster and user', () => { const kc = new KubeConfig();