-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring test codebase accordind to recomendations #22544
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,27 +16,25 @@ import { LoginTests } from '../../tests-library/LoginTests'; | |
import { Dashboard } from '../../pageobjects/dashboard/Dashboard'; | ||
import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil'; | ||
import { BASE_TEST_CONSTANTS } from '../../constants/BASE_TEST_CONSTANTS'; | ||
import { assert, expect } from 'chai'; | ||
import { expect } from 'chai'; | ||
import { API_TEST_CONSTANTS } from '../../constants/API_TEST_CONSTANTS'; | ||
import { ShellString } from 'shelljs'; | ||
import { WorkspaceHandlingTests } from '../../tests-library/WorkspaceHandlingTests'; | ||
import { registerRunningWorkspace } from '../MochaHooks'; | ||
const projectAndFileTests: ProjectAndFileTests = e2eContainer.get(CLASSES.ProjectAndFileTests); | ||
const loginTests: LoginTests = e2eContainer.get(CLASSES.LoginTests); | ||
const browserTabsUtil: BrowserTabsUtil = e2eContainer.get(CLASSES.BrowserTabsUtil); | ||
const dashboard: Dashboard = e2eContainer.get(CLASSES.Dashboard); | ||
const shellExecutor: ShellExecutor = e2eContainer.get(CLASSES.ShellExecutor); | ||
const workspaceHandlingTests: WorkspaceHandlingTests = e2eContainer.get(CLASSES.WorkspaceHandlingTests); | ||
function executeArbitraryShellScript(command: string): string { | ||
const output: ShellString = shellExecutor.executeCommand(command); | ||
if (output.stderr.length > 0) { | ||
assert.fail(output.stderr); | ||
} | ||
return output.stdout; | ||
} | ||
import { KubernetesCommandLineToolsExecutor } from '../../utils/KubernetesCommandLineToolsExecutor'; | ||
|
||
suite('Workspace using a parent test suite', function (): void { | ||
loginTests.loginIntoChe(); | ||
const projectAndFileTests: ProjectAndFileTests = e2eContainer.get(CLASSES.ProjectAndFileTests); | ||
const loginTests: LoginTests = e2eContainer.get(CLASSES.LoginTests); | ||
const browserTabsUtil: BrowserTabsUtil = e2eContainer.get(CLASSES.BrowserTabsUtil); | ||
const dashboard: Dashboard = e2eContainer.get(CLASSES.Dashboard); | ||
const shellExecutor: ShellExecutor = e2eContainer.get(CLASSES.ShellExecutor); | ||
const workspaceHandlingTests: WorkspaceHandlingTests = e2eContainer.get(CLASSES.WorkspaceHandlingTests); | ||
const kubernetesCommandLineToolsExecutor: KubernetesCommandLineToolsExecutor = e2eContainer.get( | ||
CLASSES.KubernetesCommandLineToolsExecutor | ||
); | ||
let podName: string = ''; | ||
loginTests.loginIntoChe(); | ||
kubernetesCommandLineToolsExecutor.loginToOcp(); | ||
|
||
test('Create a workspace using a parent', async function (): Promise<void> { | ||
const factoryUrl: string = `${BASE_TEST_CONSTANTS.TS_SELENIUM_BASE_URL}/dashboard/#https://github.com/testsfactory/parentDevfile`; | ||
|
@@ -45,8 +43,6 @@ suite('Workspace using a parent test suite', function (): void { | |
await workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); | ||
registerRunningWorkspace(WorkspaceHandlingTests.getWorkspaceName()); | ||
await projectAndFileTests.waitWorkspaceReadinessForCheCodeEditor(); | ||
// sometimes the trust dialog does not appear at first time, for avoiding this problem we send click event for activating | ||
await new Workbench().click(); | ||
await projectAndFileTests.performTrustAuthorDialog(); | ||
}); | ||
|
||
|
@@ -69,31 +65,31 @@ suite('Workspace using a parent test suite', function (): void { | |
await devFileTask?.click(); | ||
const firstExpectedQuickPick: QuickPickItem | undefined = await input.findQuickPick('1. This command from the devfile'); | ||
const secondExpectedQuickPick: QuickPickItem | undefined = await input.findQuickPick('2. This command from the parent'); | ||
expect(firstExpectedQuickPick).not.eqls(undefined); | ||
expect(secondExpectedQuickPick).not.eqls(undefined); | ||
expect(firstExpectedQuickPick).not.undefined; | ||
expect(secondExpectedQuickPick).not.undefined; | ||
}); | ||
|
||
test('Check expected containers in the parent POD', function (): void { | ||
const getPodNameCommand: string = `${API_TEST_CONSTANTS.TS_API_TEST_KUBERNETES_COMMAND_LINE_TOOL} get pods --selector=controller.devfile.io/devworkspace_name=sample-using-parent --output jsonpath=\'{.items[0].metadata.name}\'`; | ||
|
||
podName = executeArbitraryShellScript(getPodNameCommand); | ||
const containerNames: string = executeArbitraryShellScript( | ||
podName = shellExecutor.executeArbitraryShellScript(getPodNameCommand); | ||
const containerNames: string = shellExecutor.executeArbitraryShellScript( | ||
`${API_TEST_CONSTANTS.TS_API_TEST_KUBERNETES_COMMAND_LINE_TOOL} get pod ${podName} --output jsonpath=\'{.spec.containers[*].name}\'` | ||
); | ||
expect(containerNames).contain('tools'); | ||
expect(containerNames).contains('che-gateway'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
this can be replaced with .and: |
||
|
||
const initContainerName: string = executeArbitraryShellScript( | ||
const initContainerName: string = shellExecutor.executeArbitraryShellScript( | ||
`${API_TEST_CONSTANTS.TS_API_TEST_KUBERNETES_COMMAND_LINE_TOOL} get pod ${podName} --output jsonpath=\'{.spec.initContainers[].name}\'` | ||
); | ||
expect(initContainerName).contain('che-code-injector'); | ||
}); | ||
|
||
test('Check expected environment variables', function (): void { | ||
const envList: string = executeArbitraryShellScript( | ||
const envList: string = shellExecutor.executeArbitraryShellScript( | ||
`${API_TEST_CONSTANTS.TS_API_TEST_KUBERNETES_COMMAND_LINE_TOOL} exec -i ${podName} -c tools -- sh -c env` | ||
); | ||
expect(envList).contain('DEVFILE_ENV_VAR=true'); | ||
expect(envList).contain('PARENT_ENV_VAR=true'); | ||
expect(envList).contain('DEVFILE_ENV_VAR=true').and.contain('PARENT_ENV_VAR=true'); | ||
}); | ||
loginTests.logoutFromChe(); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
import { exec, ShellString } from 'shelljs'; | ||
import { Logger } from './Logger'; | ||
import { injectable } from 'inversify'; | ||
import { assert } from 'chai'; | ||
|
||
@injectable() | ||
export class ShellExecutor { | ||
|
@@ -25,4 +26,12 @@ export class ShellExecutor { | |
Logger.debug(command); | ||
return exec(command); | ||
} | ||
executeArbitraryShellScript(command: string): string { | ||
Logger.debug(command); | ||
const output: ShellString = this.executeCommand(command); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets add Logger.debug() to show when method was called? |
||
if (output.stderr.length > 0) { | ||
assert.fail(output.stderr); | ||
} | ||
return output.stdout; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could it be in one style?