Skip to content

Commit

Permalink
fix oc commands
Browse files Browse the repository at this point in the history
  • Loading branch information
FedeAlonso committed Jul 30, 2024
1 parent c193e51 commit 4d9a76b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,8 @@ describe('An admin user can import and run a pipeline', { testIsolation: false }
yamlContent,
dataConnectionReplacements,
);
const tempFilePath = 'cypress/temp_data_connection.yaml';
applyOpenShiftYaml(modifiedYamlContent, tempFilePath).then((result) => {
expect(result.code).to.eq(
0,
`ERROR applying YAML content
stdout: ${result.stdout}
stderr: ${result.stderr}`,
);
applyOpenShiftYaml(modifiedYamlContent).then((result) => {
expect(result.code).to.eq(0);
});
});

Expand All @@ -69,14 +63,8 @@ describe('An admin user can import and run a pipeline', { testIsolation: false }
};
cy.fixture('resources/yaml/dspa_secret.yml').then((yamlContent) => {
const modifiedYamlContent = replacePlaceholdersInYaml(yamlContent, dspaSecretReplacements);
const tempFilePath = 'cypress/temp_dspa_secret.yaml';
applyOpenShiftYaml(modifiedYamlContent, tempFilePath).then((result) => {
expect(result.code).to.eq(
0,
`ERROR applying YAML content
stdout: ${result.stdout}
stderr: ${result.stderr}`,
);
applyOpenShiftYaml(modifiedYamlContent).then((result) => {
expect(result.code).to.eq(0);
});
});

Expand All @@ -88,14 +76,8 @@ describe('An admin user can import and run a pipeline', { testIsolation: false }
};
cy.fixture('resources/yaml/dspa.yml').then((yamlContent) => {
const modifiedYamlContent = replacePlaceholdersInYaml(yamlContent, dspaReplacements);
const tempFilePath = 'cypress/temp_dspa.yaml';
applyOpenShiftYaml(modifiedYamlContent, tempFilePath).then((result) => {
expect(result.code).to.eq(
0,
`ERROR applying YAML content
stdout: ${result.stdout}
stderr: ${result.stderr}`,
);
applyOpenShiftYaml(modifiedYamlContent).then((result) => {
expect(result.code).to.eq(0);
});
});
});
Expand Down
17 changes: 10 additions & 7 deletions frontend/src/__tests__/cypress/cypress/utils/ocCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
* Applies the given YAML content using the `oc apply` command.
*
* @param yamlContent YAML content to be applied
* @param tempFilePath Path to the temporary file
* @returns Cypress Chainable
*/
export const applyOpenShiftYaml = (yamlContent: string, tempFilePath: string) => {
cy.writeFile(tempFilePath, yamlContent);

const ocCommand = `oc apply -f ${tempFilePath}`;

export const applyOpenShiftYaml = (yamlContent: string) => {

Check failure on line 7 in frontend/src/__tests__/cypress/cypress/utils/ocCommands.ts

View workflow job for this annotation

GitHub Actions / Tests (18.x)

Missing return type on function
const ocCommand = `oc apply -f - <<EOF\n${yamlContent}EOF`;
return cy.exec(ocCommand, { failOnNonZeroExit: false }).then((result) => {
if (result.code !== 0) {
// If there is an error, log the error and fail the test
cy.log(`ERROR applying YAML content
stdout: ${result.stdout}
stderr: ${result.stderr}`);
throw new Error(`Command failed with code ${result.code}`);
}
return result;
});
};
Expand Down Expand Up @@ -43,4 +46,4 @@ export const deleteOpenShiftProject = (projectName: string) => {
return cy.exec(ocCommand, { failOnNonZeroExit: false, timeout: 180000 }).then((result) => {
return result;
});
};
};

0 comments on commit 4d9a76b

Please sign in to comment.