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

added cluster related tests #367

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 12 additions & 0 deletions Cypress/cypress/fixtures/graphql/mutation.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,15 @@ export const syncHub = `mutation syncHub($id: ID!){
LastSyncedAt
}
}`;

export const userClusterReg = `mutation userClusterReg($clusterInput: ClusterInput!){
userClusterReg(clusterInput: $clusterInput){
token
cluster_id
cluster_name
}
}`;

export const deleteClusters = `mutation deleteClusters($projectID: String!, $cluster_ids: [String]!){
deleteClusters(projectID: $projectID, cluster_ids: $cluster_ids)
}`;
28 changes: 28 additions & 0 deletions Cypress/cypress/fixtures/graphql/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,31 @@ export const GetPredefinedWorkflowList = `query GetPredefinedWorkflowList($HubNa
export const GetPredefinedExperimentYAML = `query GetPredefinedExperimentYAML($experimentInput: ExperimentInput!){
GetPredefinedExperimentYAML(experimentInput: $experimentInput)
}`;

export const getCluster = `query getCluster($project_id: String!, $cluster_type: String){
getCluster(project_id: $project_id, cluster_type: $cluster_type){
cluster_id
project_id
cluster_name
description
platform_name
access_key
is_registered
is_cluster_confirmed
is_active
updated_at
created_at
cluster_type
no_of_schedules
no_of_workflows
token
agent_namespace
serviceaccount
agent_scope
agent_ns_exists
agent_sa_exists
last_workflow_timestamp
start_time
version
}
}`;
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { unauthorized, invalid_request } from "../../../fixtures/errorCodes";

let adminAccessToken, user1AccessToken, user1Id, adminUserId;

before("Clear Database", () => {
cy.task("clearDB");
});

describe("Testing get request to status api", () => {
it("Testing status api", () => {
cy.request({
Expand Down
156 changes: 156 additions & 0 deletions Cypress/cypress/integration/Api_Tests/graphql/cluster.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/// <reference types="Cypress" />

import * as user from "../../../fixtures/Users.json";
import {
userClusterReg,
deleteClusters,
} from "../../../fixtures/graphql/mutation";
import { getCluster } from "../../../fixtures/graphql/queries";

let project1Id, cluster1Id;
before("Clear Database", () => {
cy.task("clearDB");
cy.securityCheckSetup()
.then((createdSetupVariable) => {
project1Id = createdSetupVariable.project1Id;
})
.then(() => {
cy.requestLogin(user.AdminName, user.AdminPassword);
});
});

describe("Testing cluster api", () => {
it("Registering a new cluster", () => {
cy.request({
method: "POST",
url: Cypress.env("apiURL") + "/query",
body: {
operationName: "userClusterReg",
variables: {
clusterInput: {
cluster_name: "cluster1",
platform_name: "AWS",
project_id: project1Id,
cluster_type: "external",
agent_scope: "Cluster",
tolerations: [],
},
},
query: userClusterReg,
},
}).then((res) => {
expect(res.status).to.eq(200);
expect(res.body).to.have.nested.property("data.userClusterReg.token");
expect(res.body).to.have.nested.property(
"data.userClusterReg.cluster_id"
);
expect(res.body).to.have.nested.property(
"data.userClusterReg.cluster_name"
);
expect(res.body.data.userClusterReg.cluster_name).to.eq("cluster1");
cluster1Id = res.body.data.userClusterReg.cluster_id;
});
});

/*it("Testing input validation in registering a new cluster", () => {
cy.request({
method: "POST",
url: Cypress.env("apiURL") + "/query",
body: {
operationName: "userClusterReg",
variables: {
clusterInput: {
cluster_name: "cluster1",
platform_name: "",
project_id: project1Id,
cluster_type: "",
agent_scope: "",
tolerations: [],
},
},
query: userClusterReg,
},
failOnStatusCode: false,
}).then((res) => {
cy.validateErrorMessage(res, "permission_denied");
});
});*/

/*it("Registering a new cluster with same name", () => {
cy.request({
method: "POST",
url: Cypress.env("apiURL") + "/query",
body: {
operationName: "userClusterReg",
variables: {
clusterInput: {
cluster_name: "cluster1",
platform_name: "AWS",
project_id: project1Id,
cluster_type: "external",
agent_scope: "Cluster",
tolerations: [],
},
},
query: userClusterReg,
},
failOnStatusCode: false,
}).then((res) => {
cy.validateErrorMessage(res, "permission_denied");
});
});*/

it("Listing all cluster", () => {
cy.request({
method: "POST",
url: Cypress.env("apiURL") + "/query",
body: {
operationName: "getCluster",
variables: {
project_id: project1Id,
},
query: getCluster,
},
}).then((res) => {
expect(res.status).to.eq(200);
expect(res.body).to.have.nested.property("data.getCluster");
expect(res.body.data.getCluster).to.be.an("array");
});
});

/*it("Deleting a cluster", () => {
cy.request({
method: "POST",
url: Cypress.env("apiURL") + "/query",
body: {
operationName: "deleteClusters",
variables: {
projectID: project1Id,
cluster_ids: [cluster1Id],
},
query: deleteClusters,
},
})
.then((res) => {
expect(res.status).to.eq(200);
expect(res.body).to.have.nested.property("data.deleteClusterReg");
return cy.request({
method: "POST",
url: Cypress.env("apiURL") + "/query",
body: {
operationName: "getCluster",
variables: {
project_id: project1Id,
},
query: getCluster,
},
});
})
.then((res) => {
expect(res.status).to.eq(200);
expect(res.body).to.have.nested.property("data.getCluster");
expect(res.body.data.getCluster).to.be.an("array");
expect(res.body.data.getCluster.length).to.eq(1);
});
});*/
});
17 changes: 5 additions & 12 deletions Cypress/cypress/integration/Api_Tests/graphql/myhub.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,11 @@ import * as myhubInput from "../../../fixtures/myhubInput.json";
describe("Testing myHub api", () => {
let project1Id, project2Id, hubId;
before("Create 3 test users and 2 projects", () => {
cy.task("getSecuritySetupVariable")
.then((setupVariable) => {
if (!setupVariable) {
cy.securityCheckSetup().then((createdSetupVariable) => {
project1Id = createdSetupVariable.project1Id;
project2Id = createdSetupVariable.project2Id;
cy.task("setSetupVariable", createdSetupVariable);
});
} else {
project1Id = setupVariable.project1Id;
project2Id = setupVariable.project2Id;
}
cy.task("clearDB");
cy.securityCheckSetup()
.then((createdSetupVariable) => {
project1Id = createdSetupVariable.project1Id;
project2Id = createdSetupVariable.project2Id;
})
.then(() => {
cy.requestLogin(user.user2.username, user.user2.password);
Expand Down
51 changes: 42 additions & 9 deletions Cypress/cypress/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,46 @@
*/

const { rmdir } = require("fs");
const MongoClient = require("mongodb").MongoClient;

async function drop(databaseName, mongoClient, collectionName) {
const collection = mongoClient.db(databaseName).collection(collectionName);
await collection.drop().catch((e) => {
if (e.code !== 26) {
throw e;
}
});
}

async function clearDatabase() {
const uri = "mongodb://admin:1234@localhost:27017";
const client = new MongoClient(uri, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
try {
await client.connect();
const collection = client.db("auth").collection("users");
await collection.deleteMany({ username: { $ne: "admin" } }).catch((e) => {
if (e.code !== 26) {
throw e;
}
});
const auth = ["project"];
const litmus = ["cluster-collection", "image-registry-collection", "myhub"];
for (const element of auth) {
await drop("auth", client, element);
}
for (const element of litmus) {
await drop("litmus", client, element);
}
client.close();
return true;
} catch (err) {
console.log(err.stack);
return false;
}
}

module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
Expand All @@ -35,15 +75,8 @@ module.exports = (on, config) => {
});
});
},
getSecuritySetupVariable: () => {
if (global.setupVariable) {
return global.setupVariable;
}
return null;
},
setSetupVariable: (setupVariable) => {
global.setupVariable = setupVariable;
return null;
clearDB: () => {
return clearDatabase();
},
});
};
Loading