Skip to content

Commit 4c48dde

Browse files
authored
🧪 Add automation for configuration precedence (#1210)
Resolves #1098 Adds automation to validate the config precedence. Since the env variables were named `HUB_SOMETHING` I renamed those test-oriented to `TEST_HUB_SOMETHING`. This test will be skipped in VSCode Web because Playwright won't be able to modify the cluster's env vars <!-- ## PR Title Prefix Every **PR Title** should be prefixed with :text: to indicate its type. - Breaking change: ⚠️ (`⚠️`) - Non-breaking feature: ✨ (`✨`) - Patch fix: 🐛 (`🐛`) - Docs: 📖 (`📖`) - Infra/Tests/Other: 🌱 (`🌱`) - No release note: 👻 (`👻`) For example, a pull request containing breaking changes might look like `⚠️ My pull request contains breaking changes`. Since GitHub supports emoji aliases (ie. `👻`), there is no need to include the emoji directly in the PR title -- **please use the alias**. It used to be the case that projects using emojis for PR typing had to include the emoji directly because GitHub didn't render the alias. Given that `⚠️` is easy enough to read as text, easy to parse in release tooling, and rendered in GitHub well, we prefer to standardize on the alias. For more information, please see the Konveyor [Versioning Doc](https://github.com/konveyor/release-tools/blob/main/VERSIONING.md). --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Documentation** * Added environment variable configuration options for Hub testing (TEST_HUB_URL, TEST_HUB_USERNAME, TEST_HUB_PASSWORD, TEST_HUB_AUTH_ENABLED, TEST_HUB_INSECURE) with descriptions and defaults. * **Tests** * Added comprehensive end-to-end test suite for Hub configuration from environment variables, including feature verification and multi-scenario coverage. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: Alejandro Brugarolas <[email protected]>
1 parent 4c70450 commit 4c48dde

File tree

4 files changed

+145
-8
lines changed

4 files changed

+145
-8
lines changed

tests/docs/contrib/e2e-environment.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ Additionally, you can directly pass the env variables.
8585
| SOLUTION_SERVER_USERNAME | Username for Solution Server authentication |
8686
| SOLUTION_SERVER_PASSWORD | Password for Solution Server authentication |
8787
| SOLUTION_SERVER_INSECURE | (Optional, boolean) When set to `true`, disables TLS certificate validation (use only for local or test environments). |
88+
| TEST_HUB_URL | (Optional) URL of the Konveyor Hub instance for hub configuration tests. Default is `http://localhost:8080` |
89+
| TEST_HUB_USERNAME | (Optional) Username for Hub authentication in tests. Default is `admin` |
90+
| TEST_HUB_PASSWORD | (Optional) Password for Hub authentication in tests |
91+
| TEST_HUB_AUTH_ENABLED | (Optional, boolean) When set to `true`, enables authentication for Hub in tests |
92+
| TEST_HUB_INSECURE | (Optional, boolean) When set to `true`, skips SSL certificate verification for Hub connections in tests. Default is `true` |
8893

8994
## Running Tests
9095

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
import { expect, test } from '../../fixtures/test-repo-fixture';
2+
import type { VSCode } from '../../pages/vscode.page';
3+
import { HubConfigurationPage } from '../../pages/hub-configuration.page';
4+
import { KAIViews } from '../../enums/views.enum';
5+
import * as VSCodeFactory from '../../utilities/vscode.factory';
6+
7+
test.describe(
8+
'Hub Configuration from Environment Variables',
9+
{
10+
tag: ['@tier3', '@experimental'],
11+
},
12+
() => {
13+
test.skip(!!process.env.WEB_ENV, `Env variables won't be overwritten in VSCode Web`);
14+
test.setTimeout(600000);
15+
16+
test('Verify all features enabled via environment variables with forced hub', async ({
17+
testRepoData,
18+
}) => {
19+
const repoInfo = testRepoData['coolstore'];
20+
21+
const originalEnv = {
22+
HUB_URL: process.env.HUB_URL,
23+
HUB_USERNAME: process.env.HUB_USERNAME,
24+
HUB_PASSWORD: process.env.HUB_PASSWORD,
25+
FORCE_HUB_ENABLED: process.env.FORCE_HUB_ENABLED,
26+
HUB_INSECURE: process.env.HUB_INSECURE,
27+
HUB_SOLUTION_SERVER_ENABLED: process.env.HUB_SOLUTION_SERVER_ENABLED,
28+
HUB_PROFILE_SYNC_ENABLED: process.env.HUB_PROFILE_SYNC_ENABLED,
29+
};
30+
31+
let vscodeApp: VSCode | undefined;
32+
33+
try {
34+
process.env.HUB_URL = 'http://localhost:8080';
35+
process.env.HUB_USERNAME = 'admin';
36+
process.env.HUB_PASSWORD = 'password';
37+
process.env.FORCE_HUB_ENABLED = 'true';
38+
process.env.HUB_INSECURE = 'true';
39+
process.env.HUB_SOLUTION_SERVER_ENABLED = 'true';
40+
process.env.HUB_PROFILE_SYNC_ENABLED = 'true';
41+
42+
console.log('Launching VS Code with Hub env vars set to enable all features');
43+
44+
vscodeApp = await VSCodeFactory.init(repoInfo.repoUrl, repoInfo.repoName, repoInfo.branch);
45+
46+
await HubConfigurationPage.open(vscodeApp);
47+
const view = await vscodeApp.getView(KAIViews.hubConfiguration);
48+
const hubToggle = view.locator('input#hub-enabled');
49+
await expect(hubToggle).toBeChecked();
50+
await expect(hubToggle).toBeDisabled();
51+
52+
await expect(
53+
view.locator('text=Hub connection is enforced by environment configuration')
54+
).toBeVisible();
55+
await expect(view.locator('#hub-url')).toHaveValue(process.env.HUB_URL);
56+
await expect(view.locator('input#auth-enabled')).toBeChecked();
57+
await expect(view.locator('#auth-username')).toHaveValue(process.env.HUB_USERNAME);
58+
await expect(view.locator('#auth-password')).toHaveValue(process.env.HUB_PASSWORD);
59+
await expect(view.locator('input#auth-insecure')).toBeChecked();
60+
await expect(view.locator('input#feature-solution-server')).toBeChecked();
61+
await expect(view.locator('input#feature-profile-sync')).toBeChecked();
62+
63+
console.log('All features verified as enabled via environment variables');
64+
} finally {
65+
restoreOriginalEnvVariables(originalEnv);
66+
if (vscodeApp) {
67+
await vscodeApp.closeVSCode();
68+
}
69+
}
70+
});
71+
72+
test('Verify all features disabled via environment variables', async ({ testRepoData }) => {
73+
const repoInfo = testRepoData['coolstore'];
74+
75+
const originalEnv = {
76+
HUB_URL: process.env.HUB_URL,
77+
HUB_USERNAME: process.env.HUB_USERNAME,
78+
HUB_PASSWORD: process.env.HUB_PASSWORD,
79+
FORCE_HUB_ENABLED: process.env.FORCE_HUB_ENABLED,
80+
HUB_INSECURE: process.env.HUB_INSECURE,
81+
HUB_SOLUTION_SERVER_ENABLED: process.env.HUB_SOLUTION_SERVER_ENABLED,
82+
HUB_PROFILE_SYNC_ENABLED: process.env.HUB_PROFILE_SYNC_ENABLED,
83+
};
84+
85+
let vscodeApp: VSCode | undefined;
86+
87+
try {
88+
process.env.HUB_URL = 'http://localhost:8080';
89+
process.env.HUB_USERNAME = 'admin';
90+
process.env.HUB_PASSWORD = 'password';
91+
delete process.env.FORCE_HUB_ENABLED;
92+
process.env.HUB_INSECURE = 'false';
93+
process.env.HUB_SOLUTION_SERVER_ENABLED = 'false';
94+
process.env.HUB_PROFILE_SYNC_ENABLED = 'false';
95+
96+
console.log('Launching VS Code with Hub env vars set to disable optional features');
97+
98+
vscodeApp = await VSCodeFactory.init(repoInfo.repoUrl, repoInfo.repoName, repoInfo.branch);
99+
100+
await HubConfigurationPage.open(vscodeApp);
101+
const view = await vscodeApp.getView(KAIViews.hubConfiguration);
102+
const hubToggle = view.locator('input#hub-enabled');
103+
await expect(hubToggle).toBeChecked();
104+
await expect(hubToggle).toBeEnabled();
105+
106+
await expect(view.locator('#hub-url')).toHaveValue(process.env.HUB_URL);
107+
await expect(view.locator('input#auth-enabled')).toBeChecked();
108+
await expect(view.locator('input#auth-insecure')).not.toBeChecked();
109+
await expect(view.locator('input#feature-solution-server')).not.toBeChecked();
110+
await expect(view.locator('input#feature-profile-sync')).not.toBeChecked();
111+
112+
console.log('All features verified as disabled via environment variables');
113+
} finally {
114+
restoreOriginalEnvVariables(originalEnv);
115+
if (vscodeApp) {
116+
await vscodeApp.closeVSCode();
117+
}
118+
}
119+
});
120+
121+
const restoreOriginalEnvVariables = (originalEnv: { [key: string]: string | undefined }) => {
122+
Object.keys(originalEnv).forEach((key) => {
123+
const value = originalEnv[key as keyof typeof originalEnv];
124+
if (value === undefined) {
125+
delete process.env[key];
126+
} else {
127+
process.env[key] = value;
128+
}
129+
});
130+
};
131+
}
132+
);

tests/e2e/tests/ccm/hub-configuration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ test.describe(
6565
test('Disconnect from Hub', async () => {
6666
const disconnectConfig = {
6767
enabled: false,
68-
url: process.env.HUB_URL || 'http://localhost:8080',
68+
url: process.env.TEST_HUB_URL || 'http://localhost:8080',
6969
skipSSL: true,
7070
solutionServerEnabled: false,
7171
profileSyncEnabled: false,

tests/e2e/utilities/utils.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,15 +292,15 @@ export function parseLogEntries(rawContent: string): LogEntry[] {
292292

293293
export function getHubConfig(overrides?: Partial<HubConfiguration>): HubConfiguration {
294294
// Get values from env with defaults
295-
const url = overrides?.url ?? process.env.HUB_URL;
295+
const url = overrides?.url ?? process.env.TEST_HUB_URL;
296296
const skipSSL =
297297
overrides?.skipSSL ??
298-
(process.env.HUB_INSECURE !== undefined ? process.env.HUB_INSECURE === 'true' : true);
298+
(process.env.TEST_HUB_INSECURE !== undefined ? process.env.TEST_HUB_INSECURE === 'true' : true);
299299
const solutionServerEnabled = overrides?.solutionServerEnabled ?? false;
300300
const profileSyncEnabled = overrides?.profileSyncEnabled ?? false;
301301

302302
if (!url) {
303-
throw new Error('Missing required HUB_URL environment variable');
303+
throw new Error('Missing required TEST_HUB_URL environment variable');
304304
}
305305

306306
const config: HubConfiguration = {
@@ -314,15 +314,15 @@ export function getHubConfig(overrides?: Partial<HubConfiguration>): HubConfigur
314314
if (overrides?.auth !== undefined) {
315315
config.auth = overrides.auth;
316316
} else {
317-
const username = process.env.HUB_USERNAME;
318-
const password = process.env.HUB_PASSWORD;
319-
const envAuth = process.env.HUB_AUTH_ENABLED;
317+
const username = process.env.TEST_HUB_USERNAME;
318+
const password = process.env.TEST_HUB_PASSWORD;
319+
const envAuth = process.env.TEST_HUB_AUTH_ENABLED;
320320
const authEnabled = envAuth !== undefined ? envAuth === 'true' : !!(username && password);
321321

322322
if (authEnabled) {
323323
if (!username || !password) {
324324
throw new Error(
325-
'HUB_AUTH_ENABLED is true or credentials provided, but missing HUB_USERNAME or HUB_PASSWORD'
325+
'TEST_HUB_AUTH_ENABLED is true or credentials provided, but missing TEST_HUB_USERNAME or TEST_HUB_PASSWORD'
326326
);
327327
}
328328

0 commit comments

Comments
 (0)