Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRD - e2e Tests #4161

Merged
merged 12 commits into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aio/scripts/conf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ARCH=$(uname | awk '{print tolower($0)}')
# Local cluster configuration (check start-cluster.sh script for more details).
HEAPSTER_VERSION="v1.5.4"
HEAPSTER_PORT=8082
KIND_VERSION="0.2.1"
KIND_VERSION="v0.5.1"
KIND_BIN=${CACHE_DIR}/kind-${KIND_VERSION}

# Setup logger.
Expand Down
2 changes: 1 addition & 1 deletion aio/scripts/start-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function start-ci-heapster {
}

function start-kind {
${KIND_BIN} create cluster --name="k8s-cluster-ci"
${KIND_BIN} create cluster --name="k8s-cluster-ci" --image=kindest/node:v1.16.2
ensure-kubeconfig
if [ "${CI}" = true ] ; then
start-ci-heapster
Expand Down
Empty file removed cypress/fixtures/.keep
Empty file.
11 changes: 11 additions & 0 deletions cypress/fixtures/crd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: foos.samplecontroller.k8s.io
spec:
group: samplecontroller.k8s.io
version: v1alpha1
names:
kind: Foo
plural: foos
scope: Namespaced
7 changes: 7 additions & 0 deletions cypress/fixtures/example-foo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: samplecontroller.k8s.io/v1alpha1
kind: Foo
metadata:
name: example-foo
spec:
deploymentName: example-foo
replicas: 1
130 changes: 130 additions & 0 deletions cypress/integration/crd.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
describe('Custom Resource Definitions', () => {
it('crd list is initially empty', () => {
cy.visit('/');

cy.get('#sidebar-crd').click();
cy.url().should('include', '/#/customresourcedefinition');

cy.get('#zero-state').should('be.visible');
});

it('create a crd', () => {
cy.fixture('crd.yaml').then(crd => {
cy.createResource({content: crd});
cy.reload();
});
});

it('crd list should contain the new crd', () => {
cy.get('#zero-state').should('not.be.visible');
cy.get('kd-crd-list').within(() => {
cy.get('mat-row').should('have.length', 1);
});
});

it('go to crd details page', () => {
cy.get('kd-crd-list').within(() => {
cy.get('a')
.first()
.click();
});
cy.url().should(
'include',
'/#/customresourcedefinition/foos.samplecontroller.k8s.io?namespace=default',
);

// loads correctly
cy.get('kd-object-meta').within(() => {
cy.get('kd-property')
.first()
.contains('foos.samplecontroller.k8s.io');
});

// has resource information
cy.get('#resource-information').within(() => {
cy.get('kd-property').should('have.length', 3);

cy.get('#resource-version')
.contains('v1alpha1');
cy.get('#resource-scope')
.contains('Namespaced');
cy.get('#resource-group')
.contains('samplecontroller.k8s.io');
});

// has accepted names
cy.get('#accepted-names').within(() => {
cy.get('kd-property').should('have.length', 4);

cy.get('kd-property')
.eq(0)
.contains('foos');
cy.get('kd-property')
.eq(1)
.contains('foo');
cy.get('kd-property')
.eq(2)
.contains('Foo');
cy.get('kd-property')
.eq(3)
.contains('FooList');
});

// has empty object section
cy.get('kd-crd-object-list').within(() => {
cy.get('#zero-state').should('be.visible');
});

// has one version
cy.get('kd-crd-versions-list').within(() => {
cy.get('mat-row').should('have.length', 1);

cy.get('mat-cell')
.first()
.contains('v1alpha1');
});
});

it('create a crd object', () => {
cy.fixture('example-foo.yaml').then(object => {
cy.createResource({content: object, namespace: 'default'});
cy.reload();
});
});

it('crd objects list should contain the new object', () => {
cy.get('kd-crd-object-list').within(() => {
cy.get('#zero-state').should('not.be.visible');

cy.get('mat-row').should('have.length', 1);
cy.get('mat-cell')
.first()
.contains('example-foo');
});
});

it('go to object detail page', () => {
cy.get('kd-crd-object-list').within(() => {
cy.get('a')
.first()
.click();
});

cy.url().should(
'include',
'/#/customresourcedefinition/foos.samplecontroller.k8s.io/default/example-foo?namespace=default',
);

cy.get('kd-object-meta').within(() => {
// Name
cy.get('kd-property')
.eq(0)
.contains('example-foo');

// Namespace
cy.get('kd-property')
.eq(1)
.contains('default');
});
});
});
34 changes: 31 additions & 3 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
// ***********************************************
// Create various custom commands and overwrite existing commands.
// ***********************************************
Cypress.Commands.add(
eloyekunle marked this conversation as resolved.
Show resolved Hide resolved
'createResource',
({resource = '', name = '', namespace = '', content = ''}) => {
return getCsrfToken('appdeploymentfromfile').then(response => {
const {token} = response.body;

return cy.request({
url: '/api/v1/appdeploymentfromfile',
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
'X-CSRF-TOKEN': token,
},
body: {
name,
namespace,
resource,
content,
},
});
});
},
);

function getCsrfToken(action) {
return cy.request({
url: `api/v1/csrftoken/${action}`,
method: 'GET',
});
}
Loading