Skip to content

Commit baa1a6e

Browse files
committed
add gha to test the app
1 parent eaadad7 commit baa1a6e

4 files changed

Lines changed: 190 additions & 1 deletion

File tree

.github/workflows/test-app.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: hier-config-cli test
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version:
15+
- "3.9"
16+
- "3.10"
17+
- "3.11"
18+
- "3.12"
19+
20+
steps:
21+
- uses: actions/checkout@v2
22+
- name: Set up Python ${{ matrix.python-version }}
23+
uses: actions/setup-python@v2
24+
with:
25+
python-version: ${{ matrix.python-version }}
26+
- name: Install poetry
27+
uses: snok/install-poetry@v1
28+
with:
29+
version: 1.5.1
30+
- name: Run tests
31+
run: |
32+
poetry install --no-interaction --no-root
33+
poetry run black --check .
34+
poetry run pytest

poetry.lock

Lines changed: 63 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pyyaml = "^6.0.2"
1515

1616
[tool.poetry.group.dev.dependencies]
1717
black = "^24.10.0"
18+
pytest = "^8.3.4"
1819

1920
[build-system]
2021
requires = ["poetry-core"]

tests/test_cli.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import pytest
2+
from click.testing import CliRunner
3+
from hier_config_cli import cli
4+
5+
6+
# Define test fixtures for mock configurations
7+
@pytest.fixture
8+
def mock_running_config(tmp_path):
9+
config_path = tmp_path / "running_config.conf"
10+
config_path.write_text("hostname test-router\ninterface Vlan1\n")
11+
return str(config_path)
12+
13+
14+
@pytest.fixture
15+
def mock_generated_config(tmp_path):
16+
config_path = tmp_path / "generated_config.conf"
17+
config_path.write_text(
18+
"hostname test-router-updated\ninterface Vlan1\n ip address 10.0.0.1 255.255.255.0\n"
19+
)
20+
return str(config_path)
21+
22+
23+
# Test `list_platforms` command
24+
def test_list_platforms():
25+
runner = CliRunner()
26+
result = runner.invoke(cli, ["list-platforms"])
27+
assert result.exit_code == 0
28+
assert "Available Platforms" in result.output
29+
assert "ios" in result.output
30+
assert "junos" in result.output
31+
32+
33+
# Test `remediation` command
34+
def test_remediation_command(mock_running_config, mock_generated_config):
35+
runner = CliRunner()
36+
result = runner.invoke(
37+
cli,
38+
[
39+
"remediation",
40+
"--platform",
41+
"ios",
42+
"--running-config",
43+
mock_running_config,
44+
"--generated-config",
45+
mock_generated_config,
46+
],
47+
)
48+
assert result.exit_code == 0
49+
assert "Remediation Configuration" in result.output
50+
assert "no hostname test-router" in result.output
51+
assert "hostname test-router-updated" in result.output
52+
53+
54+
# Test `rollback` command
55+
def test_rollback_command(mock_running_config, mock_generated_config):
56+
runner = CliRunner()
57+
result = runner.invoke(
58+
cli,
59+
[
60+
"rollback",
61+
"--platform",
62+
"ios",
63+
"--running-config",
64+
mock_running_config,
65+
"--generated-config",
66+
mock_generated_config,
67+
],
68+
)
69+
assert result.exit_code == 0
70+
assert "Rollback Configuration" in result.output
71+
assert "hostname test-router" in result.output
72+
assert "no hostname test-router-updated" in result.output
73+
74+
75+
# Test `future` command
76+
def test_future_command(mock_running_config, mock_generated_config):
77+
runner = CliRunner()
78+
result = runner.invoke(
79+
cli,
80+
[
81+
"future",
82+
"--platform",
83+
"ios",
84+
"--running-config",
85+
mock_running_config,
86+
"--generated-config",
87+
mock_generated_config,
88+
],
89+
)
90+
assert result.exit_code == 0
91+
assert "Future Configuration" in result.output
92+
assert "hostname test-router-updated" in result.output

0 commit comments

Comments
 (0)