Skip to content

Commit

Permalink
Add Login e2e test (#61)
Browse files Browse the repository at this point in the history
* Add Login e2e test

Signed-off-by: Luigi Pellecchia <[email protected]>
  • Loading branch information
pellecchialuigi authored Jan 10, 2025
1 parent 3c56ef7 commit 721faf6
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 27 deletions.
68 changes: 45 additions & 23 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,60 +8,75 @@ on:
uuid:
description: 'Unique ID'
required: false

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Print current branch
run: echo "${BRANCH_NAME}"
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
- name: Define global variables
id: global_variables
run: |
echo "BRANCH_NAME=${{ github.head_ref || github.ref_name }}" >> "$GITHUB_OUTPUT"
echo "CONTAINER_ID=${{ github.run_id }}" >> "$GITHUB_OUTPUT"
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Api
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
CONTAINER_ID: ${{ steps.global_variables.outputs.CONTAINER_ID }}
uses: docker/build-push-action@v6
with:
build-args: |
ADMIN_PASSWORD=admin
API_PORT=5000
ADMIN_PASSWORD=dummy_password
API_PORT=5005
context: .
file: Dockerfile-api
push: false
tags: basil-api_${{ env.BRANCH_NAME }}
outputs: type=docker,dest=/tmp/basil-api.tar
no-cache: true
tags: basil-api_${{ env.CONTAINER_ID }}
outputs: type=docker,dest=/tmp/basil-api_${{ env.CONTAINER_ID }}.tar
- name: Build App
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
CONTAINER_ID: ${{ steps.global_variables.outputs.CONTAINER_ID }}
uses: docker/build-push-action@v6
with:
build-args: |
API_ENDPOINT=http://localhost:5000
API_ENDPOINT=http://localhost:5005
APP_PORT=9056
context: .
file: Dockerfile-app
push: false
tags: basil-app_${{ env.BRANCH_NAME }}
outputs: type=docker,dest=/tmp/basil-app.tar
no-cache: true
tags: basil-app_${{ env.CONTAINER_ID }}
outputs: type=docker,dest=/tmp/basil-app_${{ env.CONTAINER_ID }}.tar
- name: Upload basil-api artifact
env:
CONTAINER_ID: ${{ steps.global_variables.outputs.CONTAINER_ID }}
uses: actions/upload-artifact@v4
with:
name: basil-api
path: /tmp/basil-api.tar
path: /tmp/basil-api_${{ env.CONTAINER_ID }}.tar
- name: Upload basil-app artifact
env:
CONTAINER_ID: ${{ steps.global_variables.outputs.CONTAINER_ID }}
uses: actions/upload-artifact@v4
with:
name: basil-app
path: /tmp/basil-app.tar
path: /tmp/basil-app_${{ env.CONTAINER_ID }}.tar
test:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Define global variables
id: global_variables
run: |
echo "BRANCH_NAME=${{ github.head_ref || github.ref_name }}" >> "$GITHUB_OUTPUT"
echo "CONTAINER_ID=${{ github.run_id }}" >> "$GITHUB_OUTPUT"
- name: Download basil-api artifacts
uses: actions/download-artifact@v4
with:
Expand All @@ -74,16 +89,23 @@ jobs:
path: /tmp
- name: Load images
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
CONTAINER_ID: ${{ steps.global_variables.outputs.CONTAINER_ID }}
run: |
docker load --input /tmp/basil-api.tar
docker load --input /tmp/basil-app.tar
docker load --input /tmp/basil-api_${{ env.CONTAINER_ID }}.tar
docker load --input /tmp/basil-app_${{ env.CONTAINER_ID }}.tar
docker image ls -a
docker run -d --privileged --network=host basil-api_${{ env.BRANCH_NAME }}
docker run -d --network=host basil-app_${{ env.BRANCH_NAME }}
docker run -d --network=host basil-api_${{ env.CONTAINER_ID }}
docker run -d --network=host basil-app_${{ env.CONTAINER_ID }}
sleep 60
docker ps
echo "Test Api is running"
curl -vf http://localhost:5000/version
curl -vf http://localhost:5005/version
echo "Test App is running"
curl -vf http://localhost:9000
curl -vf http://localhost:9056
- name: Cypress E2E Testing
uses: cypress-io/github-action@v6
with:
browser: chrome
spec: cypress/e2e/login.cy.js
env:
LIBGL_ALWAYS_SOFTWARE: 1
30 changes: 30 additions & 0 deletions cypress/e2e/login.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/// <reference types="cypress" />

import "../support/e2e.js";
import api_data from "../fixtures/api.json";
import const_data from "../fixtures/consts.json";

describe("Login", () => {
it("Check login", () => {
cy.visit(const_data.app_base_url + "/login");
cy.wait(const_data.long_wait);
cy.url().should("eq", const_data.app_base_url + "/login");

//Fill form
cy.get(const_data.login.input_username)
.type(const_data.users.admin.username)
.should("have.value", const_data.users.admin.username);
cy.get(const_data.login.input_password)
.type(const_data.users.admin.password)
.should("have.value", const_data.users.admin.password)
.type("{enter}");
cy.wait(const_data.long_wait);

// Redirected and logged in
cy.url().should("eq", const_data.app_base_url + "/");
cy.contains(
'span[class^="pf-v5-c-menu-toggle__text"]',
const_data.users.admin.username,
);
});
});
19 changes: 15 additions & 4 deletions cypress/fixtures/consts.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"app_base_url": "http://localhost:9000",
"api_base_url": "http://localhost:5000",
"app_base_url": "http://localhost:9056",
"api_base_url": "http://localhost:5005",
"login": {
"input_username": "#pf-login-username-id",
"input_password": "#pf-login-password-id"
},
"api": {
"modal_button_confirm_id": "#btn-modal-api-confirm",
"table_listing_id": "#table-api-listing"
Expand All @@ -10,6 +14,13 @@
"table_matching_id": "#table-matching-sections",
"table_unmatching_id": "#table-unmatching-sections"
},
"long_wait": 1500,
"fast_wait": 500
"users": {
"admin": {
"username": "admin",
"password": "dummy_password",
"role": "ADMIN"
}
},
"long_wait": 5000,
"fast_wait": 1000
}

0 comments on commit 721faf6

Please sign in to comment.