From faa30ae313890d1af067616d4adaa5d2b6e50ec7 Mon Sep 17 00:00:00 2001 From: Martin Szuc Date: Tue, 29 Oct 2024 16:26:28 +0100 Subject: [PATCH] refactor: getServerUrl to handle different base URL formats Signed-off-by: Martin Szuc --- .../utils/KubernetesCommandLineToolsExecutor.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/e2e/utils/KubernetesCommandLineToolsExecutor.ts b/tests/e2e/utils/KubernetesCommandLineToolsExecutor.ts index ae55ebddb75..997578648cb 100644 --- a/tests/e2e/utils/KubernetesCommandLineToolsExecutor.ts +++ b/tests/e2e/utils/KubernetesCommandLineToolsExecutor.ts @@ -202,8 +202,20 @@ export class KubernetesCommandLineToolsExecutor implements IKubernetesCommandLin getServerUrl(): string { Logger.debug(`${this.kubernetesCommandLineTool} - get server api url.`); + const baseUrl = new URL(BASE_TEST_CONSTANTS.TS_SELENIUM_BASE_URL); + let apiHostname: string; - return BASE_TEST_CONSTANTS.TS_SELENIUM_BASE_URL.replace('devspaces.apps', 'api') + ':6443'; + if (baseUrl.hostname.includes('devspaces.apps')) { + apiHostname = baseUrl.hostname.replace('devspaces.apps', 'api'); + } else if (baseUrl.hostname.includes('console-openshift-console.apps')) { + apiHostname = baseUrl.hostname.replace('console-openshift-console.apps', 'api'); + } else { + throw new Error(`Unexpected base URL hostname format: ${baseUrl.hostname}`); + } + + const apiUrl = `https://${apiHostname}:6443`; + Logger.debug(`Generated API server URL: ${apiUrl}`); + return apiUrl; } }