Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 36 additions & 24 deletions tests/e2e/specs/api/AnsibleDevFileAPI.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,16 @@ suite('Ansible devfile API test', function (): void {
const output: ShellString = containerTerminal.execInContainerCommand(runCommandInBash, containerName);
expect(output.code).eqls(0);

const recapBlocks: string[] = output.stdout.split(/PLAY RECAP/g).slice(1);
// molecule may write its rich formatted output (box-drawing, ANSI codes) to stderr rather than stdout (CRW-12595)
const combinedOutput: string = (output.stdout + output.stderr).trim();

const recapBlocks: string[] = combinedOutput.split(/PLAY RECAP/g).slice(1);
recapBlocks.forEach((block): void => {
expect(block).match(/failed\s*=\s*0/);
});

const outputText: string = output.stdout.trim();
expect(outputText).to.include('was installed successfully');
expect(outputText).to.not.match(/failed\s*=\s*[1-9]\d*/);
expect(combinedOutput).to.include('was installed successfully');
expect(combinedOutput).to.not.match(/failed\s*=\s*[1-9]\d*/);
});

test('Check "molecule-list" command', function (): void {
Expand All @@ -123,7 +125,8 @@ suite('Ansible devfile API test', function (): void {
const output: ShellString = containerTerminal.execInContainerCommand(runCommandInBash, containerName);
expect(output.code).eqls(0);

const outputText: string = output.stdout.trim();
// molecule may write its rich formatted output (box-drawing, ANSI codes) to stderr rather than stdout
const outputText: string = (output.stdout + output.stderr).trim();
expect(outputText).to.include('molecule');
expect(outputText).to.include('ansible');
expect(outputText).to.include('default');
Expand Down Expand Up @@ -152,14 +155,16 @@ suite('Ansible devfile API test', function (): void {
const output: ShellString = containerTerminal.execInContainerCommand(runCommandInBash, containerName);
expect(output.code).eqls(0);

const recapBlocks: string[] = output.stdout.split(/PLAY RECAP/g).slice(1);
// molecule may write its rich formatted output (box-drawing, ANSI codes) to stderr rather than stdout
const combinedOutput: string = (output.stdout + output.stderr).trim();

const recapBlocks: string[] = combinedOutput.split(/PLAY RECAP/g).slice(1);
recapBlocks.forEach((block): void => {
expect(block).match(/failed\s*=\s*0/);
});

const outputText: string = output.stdout.trim();
expect(outputText).to.include('PLAY [Converge]');
expect(outputText).to.not.match(/failed\s*=\s*[1-9]\d*/);
expect(combinedOutput).to.include('PLAY [Converge]');
expect(combinedOutput).to.not.match(/failed\s*=\s*[1-9]\d*/);
});

test('Check "molecule-verify" command', function (): void {
Expand All @@ -184,14 +189,16 @@ suite('Ansible devfile API test', function (): void {
const output: ShellString = containerTerminal.execInContainerCommand(runCommandInBash, containerName);
expect(output.code).eqls(0);

const recapBlocks: string[] = output.stdout.split(/PLAY RECAP/g).slice(1);
// molecule may write its rich formatted output (box-drawing, ANSI codes) to stderr rather than stdout
const combinedOutput: string = (output.stdout + output.stderr).trim();

const recapBlocks: string[] = combinedOutput.split(/PLAY RECAP/g).slice(1);
recapBlocks.forEach((block): void => {
expect(block).match(/failed\s*=\s*0/);
});

const outputText: string = output.stdout.trim();
expect(outputText).to.include('PLAY [Verify]');
expect(outputText).to.not.match(/failed\s*=\s*[1-9]\d*/);
expect(combinedOutput).to.include('PLAY [Verify]');
expect(combinedOutput).to.not.match(/failed\s*=\s*[1-9]\d*/);
});

test('Check "molecule-destroy" command', function (): void {
Expand All @@ -216,14 +223,16 @@ suite('Ansible devfile API test', function (): void {
const output: ShellString = containerTerminal.execInContainerCommand(runCommandInBash, containerName);
expect(output.code).eqls(0);

const recapBlocks: string[] = output.stdout.split(/PLAY RECAP/g).slice(1);
// molecule may write its rich formatted output (box-drawing, ANSI codes) to stderr rather than stdout
const combinedOutput: string = (output.stdout + output.stderr).trim();

const recapBlocks: string[] = combinedOutput.split(/PLAY RECAP/g).slice(1);
recapBlocks.forEach((block): void => {
expect(block).match(/failed\s*=\s*0/);
});

const outputText: string = output.stdout.trim();
expect(outputText).to.include('PLAY [Destroy]');
expect(outputText).to.not.match(/failed\s*=\s*[1-9]\d*/);
expect(combinedOutput).to.include('PLAY [Destroy]');
expect(combinedOutput).to.not.match(/failed\s*=\s*[1-9]\d*/);
});

test('Check "molecule-test" command', function (): void {
Expand All @@ -248,16 +257,18 @@ suite('Ansible devfile API test', function (): void {
const output: ShellString = containerTerminal.execInContainerCommand(runCommandInBash, containerName);
expect(output.code).eqls(0);

const recapBlocks: string[] = output.stdout.split(/PLAY RECAP/g).slice(1);
// molecule may write its rich formatted output (box-drawing, ANSI codes) to stderr rather than stdout
const combinedOutput: string = (output.stdout + output.stderr).trim();

const recapBlocks: string[] = combinedOutput.split(/PLAY RECAP/g).slice(1);
recapBlocks.forEach((block): void => {
expect(block).match(/failed\s*=\s*0/);
});

const outputText: string = output.stdout.trim();
expect(outputText).to.include('PLAY [Create]');
expect(outputText).to.include('PLAY [Converge]');
expect(outputText).to.include('PLAY [Verify]');
expect(outputText).to.not.match(/failed\s*=\s*[1-9]\d*/);
expect(combinedOutput).to.include('PLAY [Create]');
expect(combinedOutput).to.include('PLAY [Converge]');
expect(combinedOutput).to.include('PLAY [Verify]');
expect(combinedOutput).to.not.match(/failed\s*=\s*[1-9]\d*/);
});

test('Check "ansible-navigator" command', function (): void {
Expand Down Expand Up @@ -298,7 +309,8 @@ suite('Ansible devfile API test', function (): void {
const output: ShellString = containerTerminal.execInContainerCommand(runCommandInBash, containerName);
expect(output.code).eqls(0);

const outputText: string = output.stdout.trim();
// ansible-navigator may write output to stderr depending on terminal detection
const outputText: string = (output.stdout + output.stderr).trim();
expect(outputText).to.include('ansible-navigator');
expect(outputText).to.include('collections');
expect(outputText).to.include('config');
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/utils/KubernetesCommandLineToolsExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@

// if still not found, list all pods for debugging
if (!podName || podName.trim() === '') {
Logger.warn('Listing all pods in namespace for debugging:');

Check warning

Code scanning / CodeQL

Unsafe shell command constructed from library input Medium test

This string concatenation which depends on
library input
is later used in a
shell command
.
This string concatenation which depends on
library input
is later used in a
shell command
.
This string concatenation which depends on
library input
is later used in a
shell command
.
This string concatenation which depends on
library input
is later used in a
shell command
.
This string concatenation which depends on
library input
is later used in a
shell command
.
This string concatenation which depends on
library input
is later used in a
shell command
.
const debugPods: ShellString = this.shellExecutor.executeCommand(
`${this.kubernetesCommandLineTool} get pods -n ${this.namespace} --show-labels`
);
Expand Down Expand Up @@ -176,7 +176,7 @@
Logger.debug(`${this.kubernetesCommandLineTool}`);

return this.shellExecutor.executeCommand(
`${this.kubernetesCommandLineTool} exec -i -t ${KubernetesCommandLineToolsExecutor.pod} -n ${this.namespace} -c ${container} -- sh -c '${commandToExecute}'`
`${this.kubernetesCommandLineTool} exec -i ${KubernetesCommandLineToolsExecutor.pod} -n ${this.namespace} -c ${container} -- sh -c '${commandToExecute}'`
);
}

Expand Down
Loading