Skip to content

Commit

Permalink
Feat: Support FaaS on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafa committed Aug 15, 2024
1 parent 7c0c130 commit b1d53ec
Show file tree
Hide file tree
Showing 12 changed files with 218 additions and 211 deletions.
111 changes: 41 additions & 70 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,97 +7,68 @@ on:
branches:
- main

jobs:
Linux_cli:
name: Linux - Ubuntu Run
runs-on: ubuntu-latest
jobs:
test:
name: Test on ${{ matrix.os }} with ${{ matrix.env }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
env: [cli, faas]
nodeVersion: [14] # For environments requiring Node.js
pythonVersion: [3.12] # For environments requiring Python

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install MetaCall
python-version: ${{ matrix.pythonVersion }}

- name: Install MetaCall (CLI only - Ubuntu)
if: matrix.env == 'cli' && matrix.os == 'ubuntu-latest'
run: |
sudo apt update
curl -sL https://raw.githubusercontent.com/metacall/install/master/install.sh | sh
- name: Verify MetaCall installation
run: |
metacall
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run Tests Suits
run: |
find test-suites -type f -name "*.yaml" -exec python ./testing.py -f {} -V -e cli \;
Windows_cli:
name: Windows Run
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install MetaCall
shell: powershell
- name: Install MetaCall (CLI only - Windows)
if: matrix.env == 'cli' && matrix.os == 'windows-latest'
run: |
powershell -NoProfile -ExecutionPolicy unrestricted -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; &([scriptblock]::Create((Invoke-WebRequest -UseBasicParsing 'https://raw.githubusercontent.com/metacall/install/master/install.ps1')))"
- name: Add MetaCall to PATH
run: |
echo C:\Users\runneradmin\AppData\Local\MetaCall >> $env:GITHUB_PATH
shell: powershell

- name: Verify MetaCall installation
shell: powershell
run: |
metacall.bat

- name: Set up Node.js
if: matrix.env == 'faas'
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.nodeVersion }}

- name: Install MetaCall Deploy and FaaS (FaaS only)
if: matrix.env == 'faas'
run: |
npm i -g @metacall/deploy @metacall/faas
metacall-deploy --version
metacall-faas --version
- name: Install Dependencies
shell: bash
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run Test Suits
shell: bash
- name: Start FaaS Service
if: matrix.env == 'faas' && matrix.os == 'ubuntu-latest'
run: |
find test-suites -type f -name "*.yaml" -exec python ./testing.py -f {} -V -e cli \;

# MacOS:
# name: MacOS Run
# runs-on: macos-latest
# steps:
# - name: Checkout code
# uses: actions/checkout@v4

# - name: Set up Python
# uses: actions/setup-python@v5
# with:
# python-version: '3.12'

# - name: Install MetaCall
# run: |
# curl --insecure -sL https://raw.githubusercontent.com/metacall/install/master/install.sh | sh -s -- --no-check-certificate --no-docker-fallback
docker run -d -p 9000:9000 --name faas_container metacall/faas
# - name: Install Dependencies
# run: |
# python -m pip install --upgrade pip
# pip install -r requirements.txt

# - name: Run Tests Suits
# run: |
# find test-suites -type f -name "*.yaml" -exec python ./testing.py -f {} -V -e cli \;
- name: Run Test Suits
run: |
if [ "${{ matrix.env }}" == "faas" && "${{ matrix.os }}" == "windows-latest" ]; then
metacall-faas &
sleep 5 # Wait for the server to start
fi
find test-suites -type f -name "*.yaml" -exec python ./testing.py -f {} -V -e ${{ matrix.env }} \;
shell: bash
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Matacall Test Center

This is a test center for Matacall. It contains a set of test cases for Matacall projects and examples. The test cases are written in a specific yaml format, which is described in the following sections.
The main script used for testing is `testing.py` and it is mainly used in the CI/CD pipeline of this repository. It can also used to test the projects locally.

## Test Suits Format

The test suits are written in a yaml format. The following is an example of a test suit for the [random-password-generator-example](https://github.com/metacall/random-password-generator-example)
```yaml
project: random-password-generator-example
Expand All @@ -16,20 +18,25 @@ code-files:
- name: Check the password is generated in the correct length
function-call: getRandomPassword()
expected-pattern: 'missing 1 required positional argument'
```
```
## Arguments
The following arguments are available for the `testing.py` script:

```bash
> ./testing.py -h
> python3 ./testing.py -h
usage: testing.py [-h] [-V] [-f FILE]
options:
-h, --help show this help message and exit
-V, --verbose increase output verbosity
-f FILE, --file FILE the test suite file name
-e, --envs the environments to run the tests on, e,g: -e faas cli, default is cli
```
Example:

## Example

```bash
python3 ./testing.py -f test-suites/test-time-app-web.yaml -V
```
python3 ./testing.py -f test-suites/test-time-app-web.yaml -V -e cli
```
13 changes: 0 additions & 13 deletions TODO.md

This file was deleted.

76 changes: 0 additions & 76 deletions deploy.sh

This file was deleted.

20 changes: 0 additions & 20 deletions test-suites/test-string-manipulation.yaml

This file was deleted.

16 changes: 11 additions & 5 deletions testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from testing.logger import Logger
from testing.repo_manager import RepoManager
from testing.deploy_manager import DeployManager
from testing.test_runner import TestRunner
from testing.test_suites_extractor import TestSuitesExtractor

Expand All @@ -12,7 +13,7 @@ def main():
parser = argparse.ArgumentParser()
parser.add_argument("-f", "--file", action="store", help="the test suite file name")
parser.add_argument("-V", "--verbose", action="store_true", help="increase output verbosity")
parser.add_argument("-e", "--environments", nargs="+", default=["cli"], help="the environments to run the tests")
parser.add_argument("-e", "--envs", nargs="+", default=["cli"], help="the environments to run the tests")
args = parser.parse_args()

logger = Logger.get_instance()
Expand All @@ -27,14 +28,19 @@ def main():


test_suites_extractor = TestSuitesExtractor(test_suite_file_name)
project_name, repo_url, test_suites = test_suites_extractor.extract_test_suites()
config.project_name = project_name

logger.info(f"Project: {project_name}")
project_path, repo_url, test_suites = test_suites_extractor.extract_test_suites()
project_name = project_path.split('/')[-1]
logger.info(f"Testing Project: {project_name}")

repo_manager = RepoManager(repo_url)
repo_manager.clone_repo_if_not_exist()

if "faas" in args.environments:
deploy_manager = DeployManager(project_path)
if deploy_manager.deploy_local_faas() == False:
logger.error("Error deploying the project, remove faas from the environments")
args.environments.remove("faas")

test_runner = TestRunner(args.environments)
test_runner.run_tests(test_suites)

Expand Down
Loading

0 comments on commit b1d53ec

Please sign in to comment.