Skip to content

Commit 7cf0ffc

Browse files
Merge pull request #17 from MagaluCloud/refactor-repo-structure
refactor: updating package manager, pipeline and run_cli util
2 parents 8090694 + 3cacb99 commit 7cf0ffc

File tree

17 files changed

+632
-230
lines changed

17 files changed

+632
-230
lines changed

.github/workflows/test-on-pr.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: CI Tests with MGC
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
schedule:
7+
- cron: '0 9 * * *'
8+
workflow_dispatch:
9+
10+
jobs:
11+
test:
12+
name: Run Pytest via Make
13+
runs-on: ubuntu-latest
14+
15+
env:
16+
MGC_API_KEY: ${{ secrets.MGC_API_KEY }}
17+
MGC_PATH: ${{ vars.MGC_PATH }}
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Install uv
24+
uses: astral-sh/setup-uv@v5
25+
with:
26+
enable-cache: true
27+
28+
- name: Set up Python
29+
run: uv python install
30+
31+
- name: Install dependencies
32+
run: uv sync --all-extras --dev
33+
34+
- name: Install Magalu Cloud CLI (via APT)
35+
run: |
36+
sudo mkdir -p /etc/apt/keyrings
37+
sudo gpg --yes --keyserver keyserver.ubuntu.com --recv-keys 0C59E21A5CB00594
38+
sudo gpg --export --armor 0C59E21A5CB00594 | sudo gpg --dearmor -o /etc/apt/keyrings/magalu-archive-keyring.gpg
39+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/magalu-archive-keyring.gpg] https://packages.magalu.cloud/apt stable main" | sudo tee /etc/apt/sources.list.d/magalu.list
40+
sudo apt update
41+
sudo apt install -y mgccli
42+
43+
- name: Verify MGC_API_KEY and MGC_PATH and CLI
44+
run: |
45+
if [ -z "$MGC_API_KEY" ]; then
46+
echo "Error: MGC_API_KEY is not set in GitHub Secrets."
47+
exit 1
48+
fi
49+
if [ -z "$MGC_PATH" ]; then
50+
echo "Error: MGC_PATH is not set in GitHub Variables."
51+
exit 1
52+
fi
53+
mgc --version
54+
55+
- name: Run tests
56+
run: make test
57+
58+
- name: Upload Test Report
59+
if: always()
60+
uses: actions/upload-artifact@v4
61+
with:
62+
name: pytest-html-report
63+
path: report.html
64+
retention-days: 7

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,5 @@ cython_debug/
169169

170170
# PyPI configuration file
171171
.pypirc
172+
report.html
173+
.secrets

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.10

Makefile

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,48 @@
1-
test-all:
2-
@MGC_API_KEY=$(MGC_API_KEY) MGC_PATH=$(MGC_PATH) poetry run pytest --tb=short -v
1+
.PHONY: ensure-deps test test-auth test-block test-dbaas test-lbaas test-network test-object test-profile test-regression test-vm test-workspace
32

4-
test-lbaas:
5-
@MGC_PRINT_COMMAND=True MGC_API_KEY=$(MGC_API_KEY) MGC_PATH=$(MGC_PATH) poetry run pytest tests/test_lbaas.py --tb=short -v
3+
ensure-deps:
4+
@command -v python3 >/dev/null 2>&1 || { echo "python3 not found. Please install python3 and re-run."; exit 1; }
5+
@command -v curl >/dev/null 2>&1 || { echo "curl not found. Install curl to allow automatic installation of 'uv'."; exit 1; }
6+
@command -v uv >/dev/null 2>&1 || ( \
7+
echo "uv not found — installing via curl..."; \
8+
mkdir -p ~/.local/bin; \
9+
UV_URL=$${UV_URL:-https://github.com/uv/uv/releases/latest/download/uv}; \
10+
if curl -fL "$$UV_URL" -o ~/.local/bin/uv; then \
11+
chmod +x ~/.local/bin/uv; \
12+
echo "uv installed at ~/.local/bin/uv"; \
13+
else \
14+
echo "Failed to download 'uv' via curl. Please install 'uv' manually."; exit 1; \
15+
fi )
616

7-
test-dbaas:
8-
@MGC_PRINT_COMMAND=True MGC_API_KEY=$(MGC_API_KEY) MGC_PATH=$(MGC_PATH) poetry run pytest tests/test_dbaas.py --tb=short -v
17+
test: ensure-deps
18+
@MGC_API_KEY=$(MGC_API_KEY) MGC_PATH=$(MGC_PATH) uv run pytest --html=report.html --self-contained-html
919

10-
test-network:
11-
@MGC_PRINT_COMMAND=True MGC_API_KEY=$(MGC_API_KEY) MGC_PATH=$(MGC_PATH) poetry run pytest tests/test_network.py --tb=short -v
20+
test-auth: ensure-deps
21+
@MGC_VERBOSE=True MGC_API_KEY=$(MGC_API_KEY) MGC_PATH=$(MGC_PATH) uv run pytest tests/test_auth.py
1222

13-
test-object:
14-
@MGC_PRINT_COMMAND=True MGC_API_KEY=$(MGC_API_KEY) MGC_PATH=$(MGC_PATH) poetry run pytest tests/test_object.py --tb=short -v
23+
test-block: ensure-deps
24+
@MGC_VERBOSE=True MGC_API_KEY=$(MGC_API_KEY) MGC_PATH=$(MGC_PATH) uv run pytest tests/test_block.py
1525

16-
test-profile:
17-
@MGC_PRINT_COMMAND=True MGC_API_KEY=$(MGC_API_KEY) MGC_PATH=$(MGC_PATH) poetry run pytest tests/test_profile.py --tb=short -v
26+
test-dbaas: ensure-deps
27+
@MGC_VERBOSE=True MGC_API_KEY=$(MGC_API_KEY) MGC_PATH=$(MGC_PATH) uv run pytest tests/test_dbaas.py
1828

19-
test-vm:
20-
@MGC_PRINT_COMMAND=True MGC_API_KEY=$(MGC_API_KEY) MGC_PATH=$(MGC_PATH) poetry run pytest tests/test_vm.py --tb=short -v
29+
test-lbaas: ensure-deps
30+
@MGC_VERBOSE=True MGC_API_KEY=$(MGC_API_KEY) MGC_PATH=$(MGC_PATH) uv run pytest tests/test_lbaas.py
2131

22-
test-workspace:
23-
@MGC_PRINT_COMMAND=True MGC_API_KEY=$(MGC_API_KEY) MGC_PATH=$(MGC_PATH) poetry run pytest tests/test_workspace.py --tb=short -v
32+
test-network: ensure-deps
33+
@MGC_VERBOSE=True MGC_API_KEY=$(MGC_API_KEY) MGC_PATH=$(MGC_PATH) uv run pytest tests/test_network.py
2434

25-
test-regression:
26-
@MGC_PRINT_COMMAND=True MGC_API_KEY=$(MGC_API_KEY) MGC_PATH=$(MGC_PATH) poetry run pytest tests/test_regression.py --tb=short -v
35+
test-object: ensure-deps
36+
@MGC_VERBOSE=True MGC_API_KEY=$(MGC_API_KEY) MGC_PATH=$(MGC_PATH) uv run pytest tests/test_object.py
2737

28-
test-ci:
29-
@MGC_API_KEY=$(MGC_API_KEY) MGC_PATH=$(MGC_PATH) poetry run pytest --ignore=tests/test_auth.py --tb=short -v
38+
test-profile: ensure-deps
39+
@MGC_VERBOSE=True MGC_API_KEY=$(MGC_API_KEY) MGC_PATH=$(MGC_PATH) uv run pytest tests/test_profile.py
40+
41+
test-regression: ensure-deps
42+
@MGC_VERBOSE=True MGC_API_KEY=$(MGC_API_KEY) MGC_PATH=$(MGC_PATH) uv run pytest tests/test_regression.py
43+
44+
test-vm: ensure-deps
45+
@MGC_VERBOSE=True MGC_API_KEY=$(MGC_API_KEY) MGC_PATH=$(MGC_PATH) uv run pytest tests/test_vm.py
46+
47+
test-workspace: ensure-deps
48+
@MGC_VERBOSE=True MGC_API_KEY=$(MGC_API_KEY) MGC_PATH=$(MGC_PATH) uv run pytest tests/test_workspace.py

README.md

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,67 @@
11
# mgc-cli-tests
2-
funcional tests on Magalu Cloud CLI
2+
3+
Functional tests for Magalu Cloud CLI.
34

45
## Requirements
5-
- python 3.12
6-
- poetry
7-
- [MGC CLI](https://github.com/MagaluCloud/mgccli/) on path (or configured via `MGC_PATH` env var)
86

9-
## How to run
7+
- Python 3.10 or higher
8+
- uv (Astral's package manager)
9+
- Make
10+
- [MGC CLI](https://github.com/MagaluCloud/mgccli/) in PATH (or configure via the `MGC_PATH` environment variable)
11+
12+
## Installation and setup
13+
14+
Option A — Manual:
15+
1. Install uv following the official instructions: https://github.com/astral-sh/uv
16+
- Example (Linux/Mac):
17+
```
18+
curl -LsSf https://astral.sh/uv/install.sh | sh
19+
```
20+
- Restart your terminal after installation.
21+
2. In the project directory, run:
22+
```
23+
uv sync
24+
uv run pytest --html=report.html --self-contained-html
25+
```
26+
3. To run individual test targets:
27+
```
28+
uv run pytest tests/test_auth.py
29+
uv run pytest tests/test_block.py
30+
...
31+
```
32+
33+
Option B — Automatic (using the Makefile):
34+
1. Run:
35+
```
36+
make test
37+
```
38+
- The Makefile checks for python3 and curl and attempts to install `uv` via curl into `~/.local/bin/uv` if not present.
39+
- If the Makefile installs `uv` to `~/.local/bin`, ensure `~/.local/bin` is in your PATH, e.g.:
40+
```
41+
export PATH=$HOME/.local/bin:$PATH
42+
```
43+
2. To run individual test targets:
44+
```
45+
make test-auth
46+
make test-block
47+
...
48+
```
49+
50+
## HTML report
51+
52+
- The `make test` target generates a self-contained HTML report named `report.html`.
53+
- Open `report.html` in your browser after the run to review results.
1054
11-
```bash
12-
poetry run pytest
55+
## How to run without the Makefile
56+
57+
To run all tests:
58+
```
59+
uv run pytest
60+
```
61+
62+
To run a specific test file:
63+
```
64+
uv run pytest tests/test_lbaas.py
1365
```
1466
1567
## Modules tested

action.yml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: 'MGCCLI Tests'
2-
description: 'Executa testes para mgccli usando Poetry e Pytest'
2+
description: 'Executa testes para mgccli usando Astral UV e Pytest'
33
author: 'MagaluCloud'
44

55
inputs:
@@ -67,33 +67,34 @@ runs:
6767
with:
6868
python-version: ${{ inputs.python-version }}
6969

70-
- name: Install Poetry
71-
uses: snok/install-poetry@76e04a911780d5b312d89783f7b1cd627778900a
72-
with:
73-
version: 1.8.4
70+
- name: Install Astral UV
71+
shell: bash
72+
run: |
73+
curl -LsSf https://astral.sh/uv/install.sh | sh
7474
7575
- name: Install dependencies
7676
shell: bash
7777
working-directory: ./tmp/mgccli-source
7878
run: |
79-
poetry install --no-interaction
80-
79+
uv sync
80+
8181
- name: Run tests
8282
id: run-tests
8383
shell: bash
8484
working-directory: ./tmp/mgccli-source
8585
env:
8686
MGC_PATH: ${{ env.MGC_PATH_RESOLVED }}
8787
run: |
88-
echo "Executando testes com MGC_PATH: $MGC_PATH"
89-
poetry run pytest ${{ inputs.pytest-args }} --tb=short -v --ignore=tests/test_auth.py 2>&1 | tee pytest_output.txt
88+
echo "Running tests with MGC_PATH: $MGC_PATH"
89+
uv run pytest ${{ inputs.pytest-args }} --tb=short -v --html=report.html --self-contained-html 2>&1 | tee pytest_output.txt
9090
echo "exit_code=${PIPESTATUS[0]}" >> $GITHUB_OUTPUT
91-
91+
9292
- name: Upload test results
9393
if: always()
9494
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
9595
with:
9696
name: pytest-results
97-
path: ./tmp/mgccli-source/pytest_output.txt
97+
path: |
98+
./tmp/mgccli-source/pytest_output.txt
99+
./tmp/mgccli-source/report.html
98100
retention-days: 2
99-

main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def main():
2+
print("Run the tests with: uv run pytest")
3+
4+
5+
if __name__ == "__main__":
6+
main()

poetry.lock

Lines changed: 0 additions & 74 deletions
This file was deleted.

pyproject.toml

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
[tool.poetry]
2-
name = "mgc-cli-tests"
1+
[project]
2+
name = "mgccli-tests"
33
version = "0.1.0"
4-
description = ""
5-
authors = ["Luiz Cavalcanti <luiz.cavalcanti@luizalabs.com>"]
4+
description = "Add your description here"
65
readme = "README.md"
7-
package-mode = false
8-
9-
[tool.poetry.dependencies]
10-
python = "^3.12"
11-
12-
13-
[tool.poetry.group.dev.dependencies]
14-
pytest = "^8.3.4"
15-
16-
[build-system]
17-
requires = ["poetry-core"]
18-
build-backend = "poetry.core.masonry.api"
6+
requires-python = ">=3.10"
7+
dependencies = [
8+
"pytest>=9.0.2",
9+
"pytest-html>=4.1.1",
10+
]
11+
authors = [
12+
{ name = "Luiz Cavalcanti", email = "<luiz.cavalcanti@luizalabs.com>" },
13+
{ name = "Chrystian R. Campos", email = "<chrystian1.camp@luizalabs.com>" }
14+
]

0 commit comments

Comments
 (0)