Skip to content

Commit

Permalink
feat(e2e): added e2e script for testing
Browse files Browse the repository at this point in the history
Signed-off-by: Dipankar Das <[email protected]>
  • Loading branch information
dipankardas011 committed May 29, 2024
1 parent 33f2f69 commit 3690034
Show file tree
Hide file tree
Showing 6 changed files with 326 additions and 0 deletions.
107 changes: 107 additions & 0 deletions .github/workflows/e2e-migration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: E2E migration testing

on:
push:
tags:
- v*
branches:
- main
- develop
- feat-add-e2e-test # TODO(user): remove it
workflow_dispatch:

jobs:
e2e-migration-from-0_9_0-to-latest:
runs-on: ${{ matrix.os }}

strategy:
matrix:
python-ver: ["3.11", "3.12"]
os: [self-hosted-arm64, ubuntu-latest]
exclude:
- os: ubuntu-latest
platform: linux/arm64
- os: self-hosted-arm64
platform: linux/amd64

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-ver }}

- name: header
run: |
echo -e "\e[1;33m┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\e[0m
\e[1;33m┃\e[0m \e[1;36m Migration from v0.9.0 to latest \e[0m \e[1;33m┃\e[0m
\e[1;33m┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\e[0m"
- name: install frappe from v0.9.0
run: |
cd /tmp
python -m pip install -U git+https://github.com/rtCamp/[email protected]
- name: frappe version
run: fm --version

- name: e2e run
timeout-minutes: 20
working-directory: test
run: |
./migration_test.sh oldToNew
- name: cleanup
if: always()
run: |
python -m pip uninstall -y frappe-manager
sudo rm -rf ~/frappe
e2e-migration-from-before_latest-to-latest:
runs-on: ${{ matrix.os }}

strategy:
matrix:
python-ver: ["3.11", "3.12"]
os: [self-hosted-arm64, ubuntu-latest]
exclude:
- os: ubuntu-latest
platform: linux/arm64
- os: self-hosted-arm64
platform: linux/amd64

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-ver }}

- name: install jq
run: |
sudo apt upgrade -y
sudo apt install -y jq curl
- name: header
run: |
echo -e "\e[1;33m┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\e[0m
\e[1;33m┃\e[0m \e[1;36m Migration from latest~1 to latest \e[0m \e[1;33m┃\e[0m
\e[1;33m┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\e[0m"
- name: install frappe previous the latest release
run: |
python -m pip install -U git+https://github.com/rtCamp/Frappe-Manager.git@$(curl --silent https://api.github.com/repos/rtCamp/Frappe-Manager/tags | jq -r '.[1].name')
- name: frappe version
run: fm --version

- name: e2e run
timeout-minutes: 30
working-directory: test
run: |
./migration_test.sh semiNewToNew
- name: cleanup
if: always()
run: |
python -m pip uninstall -y frappe-manager
sudo rm -rf ~/frappe
59 changes: 59 additions & 0 deletions .github/workflows/e2e-site.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: E2E site testing

on:
push:
tags:
- v*
branches:
- main
- develop
- feat-add-e2e-test # TODO(user): remove it
workflow_dispatch:

jobs:
e2e-current:
name: e2e current latest branch
runs-on: ${{ matrix.os }}

strategy:
matrix:
python-ver: ["3.11", "3.12"]
os: [self-hosted-arm64, ubuntu-latest]
exclude:
- os: ubuntu-latest
platform: linux/arm64
- os: self-hosted-arm64
platform: linux/amd64

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-ver }}

- name: header
run: |
echo -e "\e[1;33m┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\e[0m
\e[1;33m┃\e[0m \e[1;36m E2E Test \e[0m \e[1;33m┃\e[0m
\e[1;33m┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\e[0m"
- name: install frappe from current commit
run: |
cd ..
python -m pip install --upgrade ./Frappe-Manager
- name: frappe version
run: fm --version

- name: e2e run
timeout-minutes: 20
working-directory: test
run: |
./e2e_test.sh
- name: cleanup
if: always()
run: |
python -m pip uninstall -y frappe-manager
sudo rm -rf ~/frappe
36 changes: 36 additions & 0 deletions test/e2e_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

PS4='+\[\033[0;33m\](\[\033[0;36m\]${BASH_SOURCE##*/}:${LINENO}\[\033[0;33m\])\[\033[0m\] '

set -xe

source ${PWD}/fm.sh
source ${PWD}/helpers.sh

main() {
Prequisites

CreateSite "test-site.prod.local" prod
CreateSite "test-site.dev.local" dev

ListSites

StopSite "test-site.prod.local"
StopSite "test-site.dev.local"

StartSite "test-site.prod.local"
StartSite "test-site.dev.local"

TestSiteReachability "test-site.prod.local"
TestSiteReachability "test-site.dev.local"

GetInfoSite "test-site.prod.local"
GetInfoSite "test-site.dev.local"

DeleteSite "test-site.prod.local"
DeleteSite "test-site.dev.local"

RemoveDanglingDockerStuff
}

time main
61 changes: 61 additions & 0 deletions test/fm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash

CreateSite() {
local siteName="$1"
local envN="$2"
echo "Create SiteName: $siteName, Env: $envN"
if [ ! "${envN:-}" ]; then
fm create $siteName
else
fm create $siteName --env $2
fi

echo "Get Request to the homepage of Site: $siteName, Env: $envN"
TestSiteReachability "$siteName"
}

TestSiteReachability() {
local siteName="$1"
curl -f \
--retry 18 --retry-max-time 600 \
--head \
-H "Host: $siteName" \
-H "Cache-Control: no-cache,no-store" \
http://localhost:80
}

MigrationToLatest() {
pip install -U frappe-manager
echo "yes" | fm list
fm --version
}

DeleteSite() {
local siteName="$1"
echo "Delete SiteName: $siteName"
echo "yes" | fm delete $siteName
}


GetInfoSite() {
local siteName="$1"
echo "Info SiteName: $siteName"
fm info $siteName
}

ListSites() {
echo "List Sites"
fm list
}

StartSite() {
local siteName="$1"
echo "Start SiteName: $siteName"
fm start $siteName
}

StopSite() {
local siteName="$1"
echo "Stop SiteName: $siteName"
fm stop $siteName
}
22 changes: 22 additions & 0 deletions test/helpers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

Prequisites() {
if [ "$(id -u)" -eq 0 ]; then
info_red "You are running as root."
exit 30
fi

for n in git python docker docker-compose;
do
if ! [ -x "$(command -v $n)" ]; then
echo "Error: $n is not installed." >&2
exit 56
fi
done
}

RemoveDanglingDockerStuff() {
docker volume rm -f $(docker volume ls -q) || echo "Failed to delete dangling docker volume"
docker rm -f $(docker ps -aq) || echo "Failed to delete dangling docker container"
docker network rm -f $(docker network ls -q) || echo "Done deleting the networks"
}
41 changes: 41 additions & 0 deletions test/migration_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

PS4='+\[\033[0;33m\](\[\033[0;36m\]${BASH_SOURCE##*/}:${LINENO}\[\033[0;33m\])\[\033[0m\] '

set -xe


source ${PWD}/fm.sh
source ${PWD}/helpers.sh

oldToNew() {
Prequisites
CreateSite "migration-site.localhost"
ListSites
StopSite "migration-site.localhost"
StartSite "migration-site.localhost"
GetInfoSite "migration-site.localhost"
MigrationToLatest
StartSite "migration-site.localhost"
TestSiteReachability "migration-site.localhost"
DeleteSite "migration-site.localhost"
RemoveDanglingDockerStuff
}

semiNewToNew() {
Prequisites
CreateSite "migration-site.dev.local" dev
ListSites
StopSite "migration-site.dev.local"
StartSite "migration-site.dev.local"
GetInfoSite "migration-site.dev.local"
MigrationToLatest
StartSite "migration-site.dev.local"
TestSiteReachability "migration-site.dev.local"
DeleteSite "migration-site.dev.local"
RemoveDanglingDockerStuff
}

time $1
# time oldToNew
# time semiNewToNew

0 comments on commit 3690034

Please sign in to comment.