Skip to content

Commit

Permalink
✅ chore: ordering files to a better way to test on different providers
Browse files Browse the repository at this point in the history
  • Loading branch information
futjesus committed Dec 16, 2024
1 parent c8367e1 commit 1279f1a
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 136 deletions.
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ CLUSTER_DOMAIN=
PASSWORD=
USERNAME=
RETRY_DELAY=10000
CLOUD_PROVIDER=aws
CLOUD_PROVIDER= aws| civo
MAX_TIME_TO_WAIT=5m
RETRIES_RUN_MODE=3
RETRIES_OPEN_MODE=0
4 changes: 2 additions & 2 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export default defineConfig({
viewportHeight: 900,
supportFile: "cypress/support/e2e.ts",
retries: {
runMode: 3,
openMode: 0,
runMode: +process.env.RETRIES_RUN_MODE || 1,
openMode: +process.env.RETRIES_OPEN_MODE || 0,
},
},
});
101 changes: 101 additions & 0 deletions cypress/e2e/physical-cluster.aws.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import ms from "ms";

import { Account } from "../../types/accouts";

import { fillOutForm } from "./utils";

const CLUSTER_NAME = "test-cluster";
const isAWS = Cypress.env("CLOUD_PROVIDER") === "aws";
const MAX_TIME_TO_WAIT = Cypress.env("MAX_TIME_TO_WAIT");

describe("Test to validate physical cluster creation on AWS", () => {
beforeEach(function () {
if (!isAWS) {
cy.log("This test is only for AWS");

this.skip();
}
});

beforeEach(() => {
const username = Cypress.env("USERNAME");
const password = Cypress.env("PASSWORD");

cy.login(username, password);
});

it("should create a physical cluster", () => {
cy.visit("/");
cy.findByRole("button", { name: /add workload cluster/i }).as("button");

cy.request("GET", "/api/proxy?url=%2Fcloud-account").then(
({ status, body }) => {
expect(status).to.eq(200);

const { cloud_accounts: cloudAccounts } = body;
cy.wrap(cloudAccounts as Account[]).as("accounts");
}
);

cy.get("@accounts").then((accounts) => {
const cloudAccounts = accounts as unknown as Account[];
expect(cloudAccounts).to.be.an("array");
expect(cloudAccounts).to.have.length.greaterThan(0);

const defaultAccount = cloudAccounts.find(
(account) => account.name === "default"
);

expect(defaultAccount).to.exist;
});

cy.get("@button").click();

fillOutForm(CLUSTER_NAME);

cy.findByRole("button", {
name: /create cluster/i,
}).click();

cy.wait(2000);

cy.findByRole("heading", { name: new RegExp(CLUSTER_NAME, "i") }).should(
"exist"
);
cy.contains("Provisioning").should("exist");
});

it("should validate the cluster is provisioning", () => {
cy.visit("/");

cy.goClusterManagement();

cy.findAllByRole("button", { name: new RegExp(CLUSTER_NAME, "i") })
.eq(0)
.as("clusterProvisioningButton");

cy.get("@clusterProvisioningButton").should("exist");

cy.get("@clusterProvisioningButton").within(() => {
cy.findByText(/provisioning/i).should("exist");
});
});

it("should validate the cluster is provisioned", { retries: 3 }, () => {
cy.visit("/");

cy.goClusterManagement();

cy.findAllByRole("button", { name: new RegExp(CLUSTER_NAME, "i") })
.eq(0)
.as("clusterProvisionedButton");

cy.get("@clusterProvisionedButton").should("exist");

cy.get("@clusterProvisionedButton").within(() => {
cy.findByText(/provisioned/i, {
timeout: Number(ms(MAX_TIME_TO_WAIT)),
}).should("exist");
});
});
});
64 changes: 64 additions & 0 deletions cypress/e2e/physical-cluster.civo.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { Account } from "../../types/accouts";

import { fillOutForm } from "./utils";

const CLUSTER_NAME = "test-cluster";
const isCivo = Cypress.env("CLOUD_PROVIDER") === "civo";

describe("Test to validate physical cluster creation", () => {
beforeEach(function () {
if (!isCivo) {
cy.log("This test is only for Civo");

this.skip();
}
});

beforeEach(() => {
const username = Cypress.env("USERNAME");
const password = Cypress.env("PASSWORD");

cy.login(username, password);
});

it("should create a physical cluster", () => {
cy.visit("/");
cy.findByRole("button", { name: /add workload cluster/i }).as("button");

cy.request("GET", "/api/proxy?url=%2Fcloud-account").then(
({ status, body }) => {
expect(status).to.eq(200);

const { cloud_accounts: cloudAccounts } = body;
cy.wrap(cloudAccounts as Account[]).as("accounts");
}
);

cy.get("@accounts").then((accounts) => {
const cloudAccounts = accounts as unknown as Account[];
expect(cloudAccounts).to.be.an("array");
expect(cloudAccounts).to.have.length.greaterThan(0);

const defaultAccount = cloudAccounts.find(
(account) => account.name === "default"
);

expect(defaultAccount).to.exist;
});

cy.get("@button").click();

fillOutForm(CLUSTER_NAME);

// cy.findByRole("button", {
// name: /create cluster/i,
// }).click();

// cy.wait(2000);

// cy.findByRole("heading", { name: new RegExp(CLUSTER_NAME, "i") }).should(
// "exist"
// );
// cy.contains("Provisioning").should("exist");
});
});
133 changes: 0 additions & 133 deletions cypress/e2e/physical-cluster.cy.ts

This file was deleted.

1 change: 1 addition & 0 deletions cypress/e2e/utils/create-cluster/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./physical/fill-out-form";
34 changes: 34 additions & 0 deletions cypress/e2e/utils/create-cluster/physical/fill-out-form.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
export const fillOutForm = (clusterName: string) => {
cy.get("form").as("form");
cy.get("@form").should("exist");

cy.findByRole("textbox").type(clusterName, {
delay: 10,
});

cy.findByRole("radio", { name: /physical/i }).click();

cy.findAllByRole("combobox").eq(1).as("clusterHost");

cy.get("@clusterHost").click();

cy.findByRole("listbox").within(() => {
cy.findByRole("option", { name: /default/i }).click();
});

cy.findAllByRole("combobox").eq(2).as("clusterRegion");

cy.get("@clusterRegion").click();

cy.findByRole("listbox").within(() => {
cy.findByRole("option", { name: /us-east-1/i }).click();
});

cy.findAllByRole("combobox").eq(3).as("instanceSize");

cy.get("@instanceSize").click();

cy.findByRole("listbox").within(() => {
cy.findByRole("option", { name: /t2.nano/i }).click();
});
};
1 change: 1 addition & 0 deletions cypress/e2e/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./create-cluster";

0 comments on commit 1279f1a

Please sign in to comment.