-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Test] Fix Dev Spaces "User secrets in workspace" test to avoid using…
… an absolute devfile registry (#23203) * add new CheckUserEnvsTest e2e test
- Loading branch information
1 parent
3bef038
commit 3074f2b
Showing
1 changed file
with
97 additions
and
0 deletions.
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
tests/e2e/specs/miscellaneous/UserSecretsInWorkspace.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/** ******************************************************************* | ||
* copyright (c) 2020-2024 Red Hat, Inc. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
**********************************************************************/ | ||
import { e2eContainer } from '../../configs/inversify.config'; | ||
import { CLASSES, TYPES } from '../../configs/inversify.types'; | ||
import { WorkspaceHandlingTests } from '../../tests-library/WorkspaceHandlingTests'; | ||
import { ProjectAndFileTests } from '../../tests-library/ProjectAndFileTests'; | ||
import { LoginTests } from '../../tests-library/LoginTests'; | ||
import { registerRunningWorkspace } from '../MochaHooks'; | ||
import { KubernetesCommandLineToolsExecutor } from '../../utils/KubernetesCommandLineToolsExecutor'; | ||
import { ShellExecutor } from '../../utils/ShellExecutor'; | ||
import { ITestWorkspaceUtil } from '../../utils/workspace/ITestWorkspaceUtil'; | ||
import { ShellString } from 'shelljs'; | ||
import { expect } from 'chai'; | ||
import { Dashboard } from '../../pageobjects/dashboard/Dashboard'; | ||
import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil'; | ||
import { OAUTH_CONSTANTS } from '../../constants/OAUTH_CONSTANTS'; | ||
|
||
suite('"User secrets in workspace" test', function (): void { | ||
const workspaceHandlingTests: WorkspaceHandlingTests = e2eContainer.get(CLASSES.WorkspaceHandlingTests); | ||
const projectAndFileTests: ProjectAndFileTests = e2eContainer.get(CLASSES.ProjectAndFileTests); | ||
const loginTests: LoginTests = e2eContainer.get(CLASSES.LoginTests); | ||
const dashboard: Dashboard = e2eContainer.get(CLASSES.Dashboard); | ||
const browserTabsUtil: BrowserTabsUtil = e2eContainer.get(CLASSES.BrowserTabsUtil); | ||
|
||
let kubernetesCommandLineToolsExecutor: KubernetesCommandLineToolsExecutor = e2eContainer.get( | ||
CLASSES.KubernetesCommandLineToolsExecutor | ||
); | ||
const shellExecutor: ShellExecutor = e2eContainer.get(CLASSES.ShellExecutor); | ||
const testWorkspaceUtil: ITestWorkspaceUtil = e2eContainer.get(TYPES.WorkspaceUtil); | ||
const userProject: string = OAUTH_CONSTANTS.TS_SELENIUM_OCP_USERNAME + `-devspaces`; | ||
const stackName: string = 'Empty Workspace'; | ||
|
||
const mountEnvCommand: string = `echo ' | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: mount | ||
labels: | ||
controller.devfile.io/mount-to-devworkspace: "true" | ||
controller.devfile.io/watch-secret: "true" | ||
annotations: | ||
controller.devfile.io/mount-as: env | ||
data: | ||
mykey: bXl2YWx1ZQ== | ||
type: Opaque | ||
' | oc apply -f -`; | ||
|
||
suiteSetup('Mount kubernetes secret to the DevWorkspace containers', function (): void { | ||
kubernetesCommandLineToolsExecutor.loginToOcp(); | ||
shellExecutor.executeCommand('oc project ' + userProject); | ||
shellExecutor.executeCommand('oc delete secret mount || true'); | ||
|
||
ShellString(shellExecutor.executeCommand(mountEnvCommand)); | ||
}); | ||
|
||
suiteSetup('Login', async function (): Promise<void> { | ||
await loginTests.loginIntoChe(); | ||
}); | ||
|
||
test(`Create and open new workspace, stack:${stackName} and wait workspace readiness`, async function (): Promise<void> { | ||
await workspaceHandlingTests.createAndOpenWorkspace(stackName); | ||
await workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); | ||
|
||
registerRunningWorkspace(WorkspaceHandlingTests.getWorkspaceName()); | ||
await projectAndFileTests.waitWorkspaceReadinessForCheCodeEditor(); | ||
}); | ||
|
||
test('Check that mounted secret exists in envs list', async function (): Promise<void> { | ||
kubernetesCommandLineToolsExecutor = e2eContainer.get(CLASSES.KubernetesCommandLineToolsExecutor); | ||
kubernetesCommandLineToolsExecutor.workspaceName = WorkspaceHandlingTests.getWorkspaceName(); | ||
kubernetesCommandLineToolsExecutor.loginToOcp(); | ||
kubernetesCommandLineToolsExecutor.getPodAndContainerNames(); | ||
|
||
const output: ShellString = kubernetesCommandLineToolsExecutor.execInContainerCommand('env | grep mykey'); | ||
expect(output, 'Environment variable "mykey" from the user secret is not found').contains('mykey=myvalue'); | ||
}); | ||
|
||
suiteTeardown('Open dashboard and close all other tabs', async function (): Promise<void> { | ||
await dashboard.openDashboard(); | ||
await browserTabsUtil.closeAllTabsExceptCurrent(); | ||
}); | ||
|
||
suiteTeardown('Stop and delete the workspace by API', async function (): Promise<void> { | ||
await testWorkspaceUtil.deleteWorkspaceByName(WorkspaceHandlingTests.getWorkspaceName()); | ||
}); | ||
|
||
suiteTeardown('Unregister running workspace', function (): void { | ||
registerRunningWorkspace(''); | ||
}); | ||
}); |