Skip to content

Commit

Permalink
modularize the oc calls
Browse files Browse the repository at this point in the history
  • Loading branch information
FedeAlonso committed Jul 31, 2024
1 parent 9c7f886 commit 6a949ea
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 59 deletions.
3 changes: 3 additions & 0 deletions frontend/src/__tests__/cypress/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ Cypress.Keyboard.defaults({
keystrokeDelay: 0,
});

//TODO: Delete this once https://issues.redhat.com/browse/RHOAIENG-10719 is fixed
Cypress.on('uncaught:exception', () => false);

before(() => {
// disable Cypress's default behavior of logging all XMLHttpRequests and fetches
cy.intercept({ resourceType: /xhr|fetch/ }, { log: false });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import {
createOpenShiftProject,
deleteOpenShiftProject,
applyOpenShiftYaml,
} from '~/__tests__/cypress/cypress/utils/ocCommands';
import { createOpenShiftProject, deleteOpenShiftProject } from '~/__tests__/cypress/cypress/utils/oc_commands/project';

Check failure on line 1 in frontend/src/__tests__/cypress/cypress/tests/e2e/pipelines/pipelines.cy.ts

View workflow job for this annotation

GitHub Actions / Tests (18.x)

Replace `·createOpenShiftProject,·deleteOpenShiftProject·` with `⏎··createOpenShiftProject,⏎··deleteOpenShiftProject,⏎`
import { createDataConnection } from '~/__tests__/cypress/cypress/utils/oc_commands/dataConnection';
import { createDSPASecret, createDSPA } from '~/__tests__/cypress/cypress/utils/oc_commands/dspa';
import { replacePlaceholdersInYaml } from '~/__tests__/cypress/cypress/utils/yaml_files';

Check failure on line 4 in frontend/src/__tests__/cypress/cypress/tests/e2e/pipelines/pipelines.cy.ts

View workflow job for this annotation

GitHub Actions / Tests (18.x)

'replacePlaceholdersInYaml' is defined but never used
import { ADMIN_USER } from '~/__tests__/cypress/cypress/utils/e2eUsers';
import { AWS_BUCKETS } from '~/__tests__/cypress/cypress/utils/s3Buckets';

import { projectListPage, projectDetails } from '~/__tests__/cypress/cypress/pages/projects';
import { pipelineImportModal } from '~/__tests__/cypress/cypress/pages/pipelines/pipelineImportModal';
import { pipelinesGlobal } from '~/__tests__/cypress/cypress/pages/pipelines/pipelinesGlobal';
import { pipelinesTable } from '~/__tests__/cypress/cypress/pages/pipelines/pipelinesTable';
import { createRunPage } from '~/__tests__/cypress/cypress/pages/pipelines/createRunPage';
import {
pipelineDetails,
Expand All @@ -25,14 +21,7 @@ const testRunName = 'test-pipelines-run';
describe('An admin user can import and run a pipeline', { testIsolation: false }, () => {
before(() => {
// Provision a Project
createOpenShiftProject(projectName).then((result) => {
expect(result.code).to.eq(
0,
`ERROR provisioning ${projectName} Project
stdout: ${result.stdout}
stderr: ${result.stderr}`,
);
});
createOpenShiftProject(projectName);

// Create a pipeline compatible Data Connection
const dataConnectionReplacements = {
Expand All @@ -43,15 +32,7 @@ describe('An admin user can import and run a pipeline', { testIsolation: false }
AWS_S3_ENDPOINT: Buffer.from(AWS_BUCKETS.BUCKET_2.ENDPOINT).toString('base64'),
AWS_SECRET_ACCESS_KEY: Buffer.from(AWS_BUCKETS.AWS_SECRET_ACCESS_KEY).toString('base64'),
};
cy.fixture('resources/yaml/data_connection.yml').then((yamlContent) => {
const modifiedYamlContent = replacePlaceholdersInYaml(
yamlContent,
dataConnectionReplacements,
);
applyOpenShiftYaml(modifiedYamlContent).then((result) => {
expect(result.code).to.eq(0);
});
});
createDataConnection(dataConnectionReplacements);

// Configure Pipeline server: Create DSPA Secret
const dspaSecretReplacements = {
Expand All @@ -60,25 +41,54 @@ describe('An admin user can import and run a pipeline', { testIsolation: false }
AWS_ACCESS_KEY_ID: Buffer.from(AWS_BUCKETS.AWS_ACCESS_KEY_ID).toString('base64'),
AWS_SECRET_ACCESS_KEY: Buffer.from(AWS_BUCKETS.AWS_SECRET_ACCESS_KEY).toString('base64'),
};
cy.fixture('resources/yaml/dspa_secret.yml').then((yamlContent) => {
const modifiedYamlContent = replacePlaceholdersInYaml(yamlContent, dspaSecretReplacements);
applyOpenShiftYaml(modifiedYamlContent).then((result) => {
expect(result.code).to.eq(0);
});
});
createDSPASecret(dspaSecretReplacements);

// Configure Pipeline server: Create DSPA
const dspaReplacements = {
DSPA_SECRET_NAME: dspaSecretName,
NAMESPACE: projectName,
AWS_S3_BUCKET: AWS_BUCKETS.BUCKET_2.NAME,
AWS_S3_BUCKET: AWS_BUCKETS.BUCKET_2.NAME

Check failure on line 50 in frontend/src/__tests__/cypress/cypress/tests/e2e/pipelines/pipelines.cy.ts

View workflow job for this annotation

GitHub Actions / Tests (18.x)

Insert `,`
};
cy.fixture('resources/yaml/dspa.yml').then((yamlContent) => {
const modifiedYamlContent = replacePlaceholdersInYaml(yamlContent, dspaReplacements);
applyOpenShiftYaml(modifiedYamlContent).then((result) => {
expect(result.code).to.eq(0);
});
});
createDSPA(dspaReplacements);

Check failure on line 53 in frontend/src/__tests__/cypress/cypress/tests/e2e/pipelines/pipelines.cy.ts

View workflow job for this annotation

GitHub Actions / Tests (18.x)

Delete `⏎····⏎····`


// cy.fixture('resources/yaml/data_connection.yml').then((yamlContent) => {
// const modifiedYamlContent = replacePlaceholdersInYaml(
// yamlContent,
// dataConnectionReplacements,
// );
// applyOpenShiftYaml(modifiedYamlContent).then((result) => {
// expect(result.code).to.eq(0);
// });
// });

// // Configure Pipeline server: Create DSPA Secret
// const dspaSecretReplacements = {
// DSPA_SECRET_NAME: dspaSecretName,
// NAMESPACE: projectName,
// AWS_ACCESS_KEY_ID: Buffer.from(AWS_BUCKETS.AWS_ACCESS_KEY_ID).toString('base64'),
// AWS_SECRET_ACCESS_KEY: Buffer.from(AWS_BUCKETS.AWS_SECRET_ACCESS_KEY).toString('base64'),
// };
// cy.fixture('resources/yaml/dspa_secret.yml').then((yamlContent) => {
// const modifiedYamlContent = replacePlaceholdersInYaml(yamlContent, dspaSecretReplacements);
// applyOpenShiftYaml(modifiedYamlContent).then((result) => {
// expect(result.code).to.eq(0);
// });
// });

// // Configure Pipeline server: Create DSPA
// const dspaReplacements = {
// DSPA_SECRET_NAME: dspaSecretName,
// NAMESPACE: projectName,
// AWS_S3_BUCKET: AWS_BUCKETS.BUCKET_2.NAME,
// };
// cy.fixture('resources/yaml/dspa.yml').then((yamlContent) => {
// const modifiedYamlContent = replacePlaceholdersInYaml(yamlContent, dspaReplacements);
// applyOpenShiftYaml(modifiedYamlContent).then((result) => {
// expect(result.code).to.eq(0);
// });
// });
});

after(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Applies the given YAML content using the `oc apply` command.
*
* @param yamlContent YAML content to be applied
* @returns Cypress Chainable
*/
export const applyOpenShiftYaml = (yamlContent: string) => {

Check failure on line 7 in frontend/src/__tests__/cypress/cypress/utils/oc_commands/baseCommands.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;
});
};

Check failure on line 19 in frontend/src/__tests__/cypress/cypress/utils/oc_commands/baseCommands.ts

View workflow job for this annotation

GitHub Actions / Tests (18.x)

Insert `⏎`
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { replacePlaceholdersInYaml } from "../yaml_files";

Check warning on line 1 in frontend/src/__tests__/cypress/cypress/utils/oc_commands/dataConnection.ts

View workflow job for this annotation

GitHub Actions / Tests (18.x)

import statements should have an absolute path

Check failure on line 1 in frontend/src/__tests__/cypress/cypress/utils/oc_commands/dataConnection.ts

View workflow job for this annotation

GitHub Actions / Tests (18.x)

Replace `"../yaml_files"` with `'../yaml_files'`
import { applyOpenShiftYaml } from "./baseCommands";

Check failure on line 2 in frontend/src/__tests__/cypress/cypress/utils/oc_commands/dataConnection.ts

View workflow job for this annotation

GitHub Actions / Tests (18.x)

`./baseCommands` import should occur before import of `../yaml_files`

/**
* Try to create a data connection based on the dataConnectionReplacements config
* @param dataConnectionReplacements Dictionary with the config values
* Dict Structure:
* dataConnectionReplacements = {
* NAMESPACE: <PROJECT NAME>,
* AWS_ACCESS_KEY_ID: <AWS ACCESS KEY ID>,
* AWS_DEFAULT_REGION: <AWS REGION>,
* AWS_S3_BUCKET: <AWS BUCKET NAME>,
* AWS_S3_ENDPOINT: <AWS ENDPOINT>,
* AWS_SECRET_ACCESS_KEY: <AWS SECRET>,
* }
* @param yamlFilePath
*/
export const createDataConnection = (
dataConnectionReplacements: { [key: string]: string },
yamlFilePath: string = 'resources/yaml/data_connection.yml'
) => {
cy.fixture(yamlFilePath).then((yamlContent) => {
const modifiedYamlContent = replacePlaceholdersInYaml(yamlContent, dataConnectionReplacements);
applyOpenShiftYaml(modifiedYamlContent).then((result) => {
return result;
});
});
};
49 changes: 49 additions & 0 deletions frontend/src/__tests__/cypress/cypress/utils/oc_commands/dspa.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { replacePlaceholdersInYaml } from "../yaml_files";

Check warning on line 1 in frontend/src/__tests__/cypress/cypress/utils/oc_commands/dspa.ts

View workflow job for this annotation

GitHub Actions / Tests (18.x)

import statements should have an absolute path
import { applyOpenShiftYaml } from "./baseCommands";

/**
* Try to create a DSPA Secret based on the dspaSecretReplacements config
* @param dspaSecretReplacements Dictionary with the config values
* Dict Structure:
* dspaSecretReplacements = {
* DSPA_SECRET_NAME: <DSPA SECRET NAME>,
* NAMESPACE: <PROJECT NAME>,
* AWS_ACCESS_KEY_ID: <AWS ACCESS KEY ID>,
* AWS_SECRET_ACCESS_KEY: <AWS SECRET>,
* }
* @param yamlFilePath
*/
export const createDSPASecret = (
dspaSecretReplacements: { [key: string]: string },
yamlFilePath: string = 'resources/yaml/dspa_secret.yml'
) => {
cy.fixture(yamlFilePath).then((yamlContent) => {
const modifiedYamlContent = replacePlaceholdersInYaml(yamlContent, dspaSecretReplacements);
applyOpenShiftYaml(modifiedYamlContent).then((result) => {
return result;
});
});
};

/**
* Try to create a DSPA based on the dspaReplacements config
* @param dspaReplacements Dictionary with the config values
* Dict Structure:
* dspaSecretReplacements = {
* DSPA_SECRET_NAME: <DSPA SECRET NAME>,
* NAMESPACE: <PROJECT NAME>,
* AWS_S3_BUCKET: <AWS BUCKET NAME>
* }
* @param yamlFilePath
*/
export const createDSPA = (
dspaReplacements: { [key: string]: string },
yamlFilePath: string = 'resources/yaml/dspa.yml'
) => {
cy.fixture(yamlFilePath).then((yamlContent) => {
const modifiedYamlContent = replacePlaceholdersInYaml(yamlContent, dspaReplacements);
applyOpenShiftYaml(modifiedYamlContent).then((result) => {
return result;
});
});
};
Original file line number Diff line number Diff line change
@@ -1,23 +1,3 @@
/**
* Applies the given YAML content using the `oc apply` command.
*
* @param yamlContent YAML content to be applied
* @returns Cypress Chainable
*/
export const applyOpenShiftYaml = (yamlContent: string) => {
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;
});
};

/**
* Create an Openshift Project
*
Expand All @@ -28,12 +8,17 @@ export const applyOpenShiftYaml = (yamlContent: string) => {
export const createOpenShiftProject = (projectName: string, displayName?: string) => {
const finalDisplayName = displayName || projectName;
const ocCommand = `oc new-project ${projectName} --display-name='${finalDisplayName}'`;

return cy.exec(ocCommand, { failOnNonZeroExit: false }).then((result) => {
if (result.code !== 0) {
cy.log(`ERROR provisioning ${projectName} Project
stdout: ${result.stdout}
stderr: ${result.stderr}`);
throw new Error(`Command failed with code ${result.code}`);
}
return result;
});
};

/**
* Delete an Openshift Project given its name
*
Expand All @@ -44,3 +29,4 @@ export const deleteOpenShiftProject = (projectName: string) => {
const ocCommand = `oc delete project ${projectName}`;
return cy.exec(ocCommand, { failOnNonZeroExit: false }).then(() => {});
};

0 comments on commit 6a949ea

Please sign in to comment.