Skip to content

Commit

Permalink
✅ test: test for validate the physical cluster creation was added (#4)
Browse files Browse the repository at this point in the history
* ✅ test: test for validate the physical cluster creation was added

* 🔥 chore: some unnecessary files have been removed

* ✅ chore: the first steps to the cluster creaion were added

* ✅ chore: more configurations have been added

* ✅ chore: ordering files to a better way to test on different providers

* ✅ chore: new steps for civo cluster creatiopn were added

* ✅ chore: test cluster name was added in the env vars and change the entrypoint inside dockerfile

* ✅ chore: remove the skip test for cluster creation

* ✅ chore: test case for validate atlantis with github was added

* ✅ chore: the git validation was added

* ✅ chore: some changes were did it

* ⬆️  chore: cypress was updated

* 🦺 chore: change default value to wait for retry

* 🦺 chore: more time was added when when is looking for the link in the metaphor page
  • Loading branch information
futjesus authored Dec 30, 2024
1 parent 721947b commit e0bb164
Show file tree
Hide file tree
Showing 26 changed files with 893 additions and 325 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
.env*
.git*
.nvmrc
README.md
12 changes: 9 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
USERNAME =
PASSWORD =
DOMAIN =
CLUSTER_DOMAIN=
PASSWORD=
USERNAME=
RETRY_DELAY=20s
CLOUD_PROVIDER= aws| civo
MAX_TIME_TO_WAIT=5m
RETRIES_RUN_MODE=3
RETRIES_OPEN_MODE=0
CLUSTER_NAME=test-cluster
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/node_modules
/.pnp
.pnp.js
gitops

# testing
/coverage
Expand Down Expand Up @@ -43,6 +44,7 @@ storybook-static
.yarnrc.yaml
.yarnrc.yml
yarn.lock
token.txt

cypress/screenshots/
cypress/videos/
Expand Down
17 changes: 5 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
# Use the Cypress image as the base image
FROM cypress/included:latest
FROM cypress/included:13.17.0

# Set the working directory
WORKDIR /tests

RUN apt-get update
RUN apt install gh

# Copy necessary files into the container
COPY ./package.json .
COPY ./cypress.config.ts .
COPY ./cypress ./cypress
COPY ./checkStatus.js .
COPY ./tsconfig.json .
COPY ./git-clone.sh .
COPY ./git-status.js .

# Install dependencies
RUN npm install

# Install additional packages (like github-cli) if needed
# Note: Ensure apk packages are installed in the right context
RUN apt-get update
RUN apt install gh

# Check node and npm versions for debugging
RUN node -v && npm -v
RUN find ./cypress -type f -name "*.sh" -exec chmod +x {} \;

# Define the entrypoint for running Cypress tests
ENTRYPOINT ["npx", "cypress", "run"]
Expand Down
97 changes: 0 additions & 97 deletions checkStatus.js

This file was deleted.

33 changes: 0 additions & 33 deletions checkStatus.ts

This file was deleted.

24 changes: 19 additions & 5 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
import { defineConfig } from "cypress";
import * as dotenv from "dotenv";
import ms from "ms";
import "dotenv/config";

dotenv.config();
import {
createAtlantisPullRequestOnGithub,
applyAtlantisPlan,
} from "./cypress/utils/github";

export default defineConfig({
e2e: {
baseUrl: process.env.CLUSTER_DOMAIN,
env: {
USERNAME: process.env.USERNAME,
PASSWORD: process.env.PASSWORD,
RETRY_DELAY: process.env.RETRY_DELAY || 10000,
RETRY_DELAY: process.env.RETRY_DELAY || "10s",
CLOUD_PROVIDER: process.env.CLOUD_PROVIDER,
MAX_TIME_TO_WAIT: process.env.MAX_TIME_TO_WAIT || "1h",
CLUSTER_NAME: process.env.CLUSTER_NAME || "test-cluster",
},
viewportWidth: 2000,
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,
},
setupNodeEvents(on) {
on("task", {
createAtlantisPullRequestOnGithub,
applyAtlantisPlan,
});
},
pageLoadTimeout: Number(ms("10m")),
},
});
85 changes: 82 additions & 3 deletions cypress/e2e/atlantis.cy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import camelcaseKeys from "camelcase-keys";
import ms from "ms";

const MAX_TIME_TO_WAIT = Cypress.env("MAX_TIME_TO_WAIT");

describe("Test atlantis is working correctly", () => {
before(() => {
beforeEach(() => {
const username = Cypress.env("USERNAME");
const password = Cypress.env("PASSWORD");

Expand All @@ -8,6 +13,7 @@ describe("Test atlantis is working correctly", () => {

beforeEach(() => {
cy.wait(2000);

cy.request({
method: "GET",
url: "/api/proxy?url=%2Fcluster",
Expand All @@ -17,19 +23,22 @@ describe("Test atlantis is working correctly", () => {
},
}).then((response) => {
expect(response.status).to.eq(200);
expect(response.body.length).to.equal(2);
expect(response.body.length).to.greaterThan(0);

const [cluster] = response.body;

cy.log("Cluster data: ", cluster);

expect(cluster).to.have.property("git_auth");
expect(cluster.git_auth).to.have.property("git_token");
expect(cluster.git_auth).to.have.property("git_owner");
expect(cluster.git_auth).to.have.property("git_username");

cy.wrap(cluster).as("clusterData");
});
});

it("should do a login and validate cluster data", async () => {
it("should verify the atlantis is up", async () => {
cy.get("@clusterData").then((cluster: any) => {
const { subdomain_name: subdomain, domain_name: domain } = cluster;

Expand All @@ -40,4 +49,74 @@ describe("Test atlantis is working correctly", () => {
}
});
});

it("should create a PR inside the github page", () => {
cy.get("@clusterData").then(({ git_auth }: any) => {
const { gitToken, gitOwner, gitUsername } = camelcaseKeys(git_auth);

cy.visit("/");
cy.wait(2000);

cy.get(".management-cluster").click();

cy.findAllByRole("link").eq(1).as("github");

cy.get("@github")
.invoke("attr", "href")
.then((href) => {
cy.log(`The repository is: ${href}`);
const [base] = href.replace("https://", "").split("/tree/");
cy.log(`The base repository is: ${base}`);
cy.wrap(base).as("baseRepository");
});

cy.get("@baseRepository").then((baseRepository: unknown) => {
cy.task("createAtlantisPullRequestOnGithub", {
gitOwner,
gitToken,
gitUsername,
baseRepository,
}).then(({ createPullRequest }: any) => {
if (createPullRequest) {
cy.get("@clusterData").then((cluster: any) => {
const {
subdomain_name: subdomain,
domain_name: domain,
git_auth: git,
} = cluster;

cy.wait(20000);

if (subdomain) {
cy.visit(`https://atlantis.${subdomain}.${domain}`);
} else {
cy.visit(`https://atlantis.${domain}`);
}

cy.findAllByText(new RegExp(`${git.git_owner}/gitops`, "i"), {
timeout: Number(ms(MAX_TIME_TO_WAIT)),
}).should("exist");

cy.wait(50000);

cy.task("applyAtlantisPlan", {
gitOwner,
gitToken,
gitUsername,
baseRepository,
}).then(({ apply }: any) => {
if (apply) {
cy.wait(50000);
cy.reload();
cy.findAllByText(
new RegExp(`${git.git_owner}/gitops`, "i")
).should("not.exist");
}
});
});
}
});
});
});
});
});
Loading

0 comments on commit e0bb164

Please sign in to comment.