Skip to content

Commit

Permalink
use 'oc get' to test for 'deletionTimestamp' instead of non-existance…
Browse files Browse the repository at this point in the history
… of row, which timesout
  • Loading branch information
dtaylor113 committed Jul 27, 2020
1 parent e425967 commit afeadc0
Show file tree
Hide file tree
Showing 5 changed files with 1,447 additions and 44 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -192,6 +192,7 @@ Cypress integration tests are run via [Cypress.io](https://www.cypress.io/).
Launch Cypress test runner:
```
cd frontend
oc login ...
yarn run test-cypress
```

Expand Down
Expand Up @@ -2,6 +2,7 @@ import './login';
import './project';
import './selectors';
import './nav';
import './resources';
import 'cypress-jest-adapter';

Cypress.Cookies.defaults({
Expand Down
58 changes: 58 additions & 0 deletions frontend/packages/integration-tests-cypress/support/resources.ts
@@ -0,0 +1,58 @@
import { plural } from 'pluralize';

import { K8sResourceKindReference } from '@console/internal/module/k8s';

export {};
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace,no-redeclare
namespace Cypress {
interface Chainable<Subject> {
resourceShouldBeDeleted(
namespace: string,
resource: K8sResourceKindReference | string,
name: string,
): Chainable<Element>;
}
}
}

// Convert types in the `user.openshift.io~v1~Group` format to `groups.v1.useropenshift.io`
// to pass to oc.
const toCLIType = (type: K8sResourceKindReference | string): string => {
if (!type.includes('~')) {
return type;
}
const [group, version, kind] = type.split('~');
// Resources aren't required to follow this pattern when converting from kind to plural,
// but this should work for most resources and is good enough for our tests.
return `${plural(kind.toLowerCase())}.${version}.${group}`;
};

// any command added below, must be added to global Cypress interface above

Cypress.Commands.add(
'resourceShouldBeDeleted',
(namespace: string, resource: K8sResourceKindReference | string, name: string) =>
cy
.exec(
`oc get -n ${namespace} ${toCLIType(
resource,
)}/${name} -o template --template '{{.metadata.deletionTimestamp}}'`,
{ failOnNonZeroExit: false },
)
.then((result) => {
if (result.code !== 0) {
if (result.stderr.includes('NotFound')) {
cy.log(
`'oc get -n ${namespace} ${resource}/${name}' returned 'NotFound' indicating resource was successfully deleted`,
);
} else {
// this typically would be a 'You must be logged in to the server (Unauthorized)'
assert.fail('', '', `Error during 'oc get ${resource}/${name}', ${result.stderr} `);
}
} else {
cy.log(`expect ${resource}/${name} to have a deletionTimestamp`);
expect(result.stdout).not.toContain(`<no value>`);
}
}),
);
Expand Up @@ -107,7 +107,7 @@ describe('Kubernetes resource CRUD operations', () => {
modal.shouldBeOpened();
modal.submit();
modal.shouldBeClosed();
listPage.rows.shouldNotExist(name);
cy.resourceShouldBeDeleted(testName, resource, name);
};

before(() => {
Expand Down

0 comments on commit afeadc0

Please sign in to comment.