Skip to content

Commit

Permalink
CONSOLE-2522: Migrate CRD CRUD tests to Cypress
Browse files Browse the repository at this point in the history
  • Loading branch information
rebeccaalpert committed Jan 13, 2021
1 parent 512bb95 commit 3283e58
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 93 deletions.
93 changes: 0 additions & 93 deletions frontend/integration-tests/tests/crud.scenario.ts
Expand Up @@ -9,10 +9,7 @@ import { appHost, testName, checkLogs, checkErrors } from '../protractor.conf';
import * as crudView from '../views/crud.view';
import * as yamlView from '../views/yaml.view';

const K8S_CREATION_TIMEOUT = 15000;

describe('Kubernetes resource CRUD operations', () => {
const testLabel = 'automatedTestName';
const leakedResources = new Set<string>();

afterEach(() => {
Expand Down Expand Up @@ -40,96 +37,6 @@ describe('Kubernetes resource CRUD operations', () => {
});
});

describe('CustomResourceDefinitions', () => {
const plural = `crd${testName}`;
const group = 'test.example.com';
const name = `${plural}.${group}`;
const crd = {
apiVersion: 'apiextensions.k8s.io/v1',
kind: 'CustomResourceDefinition',
metadata: {
name,
labels: { [testLabel]: testName },
},
spec: {
group,
versions: [
{
name: 'v1',
served: true,
storage: true,
schema: {
openAPIV3Schema: {
type: 'object',
properties: {
spec: {
type: 'object',
properties: {
cronSpec: {
type: 'string',
},
image: {
type: 'string',
},
replicas: {
type: 'integer',
},
},
},
},
},
},
},
],
scope: 'Namespaced',
names: {
plural,
singular: `crd${testName}`,
kind: `CRD${testName}`,
shortNames: [testName],
},
},
};

it('displays `CustomResourceDefinitions` list view', async () => {
await browser.get(`${appHost}/k8s/cluster/customresourcedefinitions`);
await crudView.isLoaded();
expect(crudView.resourceRows.count()).not.toEqual(0);
});

it('displays a YAML editor for creating a new custom resource definition', async () => {
await crudView.createYAMLButton.click();
await yamlView.isLoaded();
await yamlView.setEditorContent(safeDump(crd));
await yamlView.saveButton.click();
await browser.wait(until.urlContains(name), K8S_CREATION_TIMEOUT);
expect(crudView.errorMessage.isPresent()).toBe(false);
});

it('displays YAML editor for creating a new custom resource instance', async () => {
await browser.get(`${appHost}/k8s/cluster/customresourcedefinitions?name=${name}`);
await crudView.isLoaded();
await crudView.clickKebabAction(crd.spec.names.kind, 'View instances');
await crudView.isLoaded();
await crudView.createYAMLButton.click();
await yamlView.isLoaded();
expect(yamlView.getEditorContent()).toContain(`kind: CRD${testName}`);
});

it('creates a new custom resource instance', async () => {
leakedResources.add(JSON.stringify({ name, plural: 'customresourcedefinitions' }));
await yamlView.saveButton.click();
expect(crudView.errorMessage.isPresent()).toBe(false);
});

it('deletes the `CustomResourceDefinition`', async () => {
await browser.get(`${appHost}/k8s/cluster/customresourcedefinitions?name=${name}`);
await crudView.resourceRowsPresent();
await crudView.deleteRow('CustomResourceDefinition', true)(crd.spec.names.kind);
leakedResources.delete(JSON.stringify({ name, plural: 'customresourcedefinitions' }));
});
});

describe('Editing labels', () => {
const name = `${testName}-editlabels`;
const plural = 'configmaps';
Expand Down
@@ -0,0 +1,123 @@
import { safeLoad, safeDump } from 'js-yaml';
import * as _ from 'lodash';

import { checkErrors, testName } from '../../support';
import { nav } from '../../views/nav';
import { listPage } from '../../views/list-page';
import * as yamlEditor from '../../views/yaml-editor';
import { errorMessage } from '../../views/form';
import { CustomResourceDefinitionKind } from '@console/internal/module/k8s';

describe('CustomResourceDefinitions', () => {
const plural = `crd${testName}`;
const group = 'test.example.com';
const name = `${plural}.${group}`;
const testLabel = 'automatedTestName';
const crd: CustomResourceDefinitionKind = {
apiVersion: 'apiextensions.k8s.io/v1',
kind: 'CustomResourceDefinition',
metadata: {
name,
labels: { [testLabel]: testName },
},
spec: {
group,
versions: [
{
name: 'v1',
served: true,
storage: true,
schema: {
openAPIV3Schema: {
type: 'object',
properties: {
spec: {
type: 'object',
properties: {
cronSpec: {
type: 'string',
},
image: {
type: 'string',
},
replicas: {
type: 'integer',
},
},
},
},
},
},
},
],
scope: 'Namespaced',
names: {
plural,
singular: `crd${testName}`,
kind: `CRD${testName}`,
shortNames: [testName],
listKind: 'ClusterResourceDefinition',
},
},
};
const customResource = {
name,
apiVersion: `${group}/v1`,
kind: `CRD${testName}`,
metadata: {
name,
namespace: testName,
},
spec: {},
plural: 'customresourcedefinitions',
};

before(() => {
cy.login();
cy.visit('/');
nav.sidenav.switcher.changePerspectiveTo('Administrator');
nav.sidenav.switcher.shouldHaveText('Administrator');
cy.createProject(testName);
});

afterEach(() => {
checkErrors();
});

after(() => {
cy.deleteProject(testName);
cy.logout();
});

it('creates, displays, and deletes `CustomResourceDefinitions` and creates a new custom resource instance', () => {
it('displays a YAML editor for creating a new custom resource definition', () => {
cy.visit('/k8s/cluster/customresourcedefinitions');
listPage.rows.shouldBeLoaded();
listPage.clickCreateYAMLbutton();
yamlEditor.isLoaded();
yamlEditor.getEditorContent().then((content) => {
const newContent = _.defaultsDeep({}, crd, safeLoad(content));
yamlEditor.setEditorContent(safeDump(newContent, { sortKeys: true })).then(() => {
yamlEditor.clickSaveCreateButton();
cy.get(errorMessage).should('not.exist');
});
});
cy.visit(`/k8s/cluster/customresourcedefinitions?name=${name}`);
listPage.rows.shouldBeLoaded();
listPage.rows.clickKebabAction(`CRD${testName}`, 'View instances');
listPage.clickCreateYAMLbutton();
yamlEditor.isLoaded();
yamlEditor.getEditorContent().then((content) => {
const newContent = _.defaultsDeep({}, customResource, safeLoad(content));
yamlEditor.setEditorContent(safeDump(newContent, { sortKeys: true })).then(() => {
yamlEditor.clickSaveCreateButton();
cy.get(errorMessage).should('not.exist');
});
});
cy.visit(`/k8s/cluster/customresourcedefinitions?name=${name}`);
listPage.rows.shouldBeLoaded();
listPage.rows.clickKebabAction(`CRD${testName}`, 'Delete CustomResourceDefinition');
cy.resourceShouldBeDeleted(testName, 'CustomResourceDefinition', `CRD${testName}`);
});
});
});

0 comments on commit 3283e58

Please sign in to comment.