| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- import { checkErrors } from '../support';
- const PLUGIN_TEMPLATE_NAME = 'console-plugin-template';
- const PLUGIN_TEMPLATE_PULL_SPEC = Cypress.env('PLUGIN_TEMPLATE_PULL_SPEC');
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- export const isLocalDevEnvironment = Cypress.config('baseUrl')!.includes('localhost');
- const installHelmChart = (path: string) => {
- // Install the plugin in a dedicated namespace using the helm chart from this repo
- cy.exec(
- `cd ../../console-plugin-template && ${path} upgrade -i ${PLUGIN_TEMPLATE_NAME} charts/openshift-console-plugin -n ${PLUGIN_TEMPLATE_NAME} --create-namespace --set plugin.image=${PLUGIN_TEMPLATE_PULL_SPEC}`,
- {
- failOnNonZeroExit: false,
- },
- ).then((result) => {
- result.stderr && cy.log('Error installing helm chart: ', result.stderr);
- result.stdout && cy.log('Successfully installed helm chart: ', result.stdout);
- });
- // Wait for the plugin deployment to be ready
- cy.exec(
- `oc rollout status -n ${PLUGIN_TEMPLATE_NAME} deploy/${PLUGIN_TEMPLATE_NAME} -w --timeout=300s`,
- { timeout: 360000, failOnNonZeroExit: false },
- );
- // Wait for console pods to restart with the new plugin
- cy.exec('oc rollout status -w deploy/console -n openshift-console --timeout=300s', {
- timeout: 360000,
- failOnNonZeroExit: false,
- });
- cy.visit('/k8s/cluster/operator.openshift.io~v1~Console/cluster/console-plugins');
- cy.get(`[data-test="${PLUGIN_TEMPLATE_NAME}-status"]`).should('include.text', 'Loaded');
- };
- const deleteHelmChart = (path: string) => {
- cy.exec(
- `cd ../../console-plugin-template && ${path} uninstall ${PLUGIN_TEMPLATE_NAME} -n ${PLUGIN_TEMPLATE_NAME} && oc delete namespaces ${PLUGIN_TEMPLATE_NAME}`,
- {
- failOnNonZeroExit: false,
- },
- ).then((result) => {
- cy.log('Error uninstalling helm chart: ', result.stderr);
- cy.log('Successfully uninstalled helm chart: ', result.stdout);
- });
- };
- describe('Console plugin template test', () => {
- before(() => {
- cy.login();
- cy.get(`[data-test="tour-step-footer-secondary"]`).contains('Skip tour').click();
- if (!isLocalDevEnvironment) {
- console.log('this is not a local env, installing helm');
- cy.exec('cd ../../console-plugin-template && ./install_helm.sh', {
- failOnNonZeroExit: false,
- }).then((result) => {
- cy.log('Error installing helm binary: ', result.stderr);
- cy.log('Successfully installed helm binary in "/tmp" directory: ', result.stdout);
- installHelmChart('/tmp/helm');
- });
- } else {
- console.log('this is a local env, not installing helm');
- installHelmChart('helm');
- }
- });
- afterEach(() => {
- checkErrors();
- });
- after(() => {
- if (!isLocalDevEnvironment) {
- deleteHelmChart('/tmp/helm');
- } else {
- deleteHelmChart('helm');
- }
- cy.logout();
- });
- it('Verify the example page title', () => {
- cy.get('[data-quickstart-id="qs-nav-home"]').click();
- cy.get('[data-test="nav"]').contains('Plugin example').click();
- cy.url().should('include', '/example');
- cy.get('title').should('contain', 'Hello, plugin!');
- });
- });
|