Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interface tests #31

Merged
merged 12 commits into from
Jan 3, 2024
2 changes: 2 additions & 0 deletions tests/interface/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.
30 changes: 30 additions & 0 deletions tests/interface/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Fixtures for charm-relation-interfaces tests."""
# pylint: disable=redefined-outer-name
import pytest
from interface_tester.plugin import InterfaceTester
from scenario import PeerRelation, State

from charm import SmtpIntegratorOperatorCharm


# Interface tests are centrally hosted at https://github.com/canonical/charm-relation-interfaces.
# this fixture is used by the test runner of charm-relation-interfaces to test saml's compliance
# with the interface specifications.
# DO NOT MOVE OR RENAME THIS FIXTURE! If you need to, you'll need to open a PR on
# https://github.com/canonical/charm-relation-interfaces and change saml's test configuration
# to include the new identifier/location.
@pytest.fixture
def interface_tester(interface_tester: InterfaceTester):
"""Interface tester fixture."""
interface_tester.configure(
charm_type=SmtpIntegratorOperatorCharm,
state_template=State(
leader=True,
config={"host": "smtp.example"},
relations=[PeerRelation(endpoint="smtp-peers")],
),
)
yield interface_tester
19 changes: 19 additions & 0 deletions tests/interface/test_smtp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""SMTP interface tests."""
from interface_tester import InterfaceTester


def test_smtp_v0_interface(interface_tester: InterfaceTester):
"""Test smtp interface.

Args:
interface_tester: interface tester.
"""
interface_tester.configure(
juju_version="3.4",
interface_name="smtp",
interface_version=0,
)
interface_tester.run()
20 changes: 16 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[tox]
skipsdist=True
skip_missing_interpreters = True
envlist = lint, unit, static, coverage-report
envlist = lint, unit, static, interface, coverage-report

[vars]
src_path = {toxinidir}/src/
Expand Down Expand Up @@ -44,12 +44,14 @@ deps =
flake8-test-docs>=1.0
isort
mypy
ops-scenario>=5.3.1
pep8-naming
pydocstyle>=2.10
pylint
pyproject-flake8<6.0.0
pytest
pytest-asyncio
pytest-interface-tester>=1.0.4
pytest-operator
requests
types-PyYAML
Expand Down Expand Up @@ -77,7 +79,7 @@ deps =
-r{toxinidir}/requirements.txt
commands =
coverage run --source={[vars]src_path},{[vars]lib_path} \
-m pytest --ignore={[vars]tst_path}integration -v --tb native -s {posargs}
-m pytest --ignore={[vars]tst_path}integration --ignore={[vars]tst_path}interface -v --tb native -s {posargs}
coverage report

[testenv:coverage-report]
Expand All @@ -97,6 +99,15 @@ deps =
commands =
bandit -c {toxinidir}/pyproject.toml -r {[vars]src_path} {[vars]tst_path}

[testenv:interface]
description = Run unit tests
deps =
pytest
ops-scenario>=5.7.1
pytest-interface-tester>=1.0.6
commands =
pytest -v --tb native {[vars]tst_path}/interface --log-cli-level=INFO -s {posargs}

[testenv:integration-juju-2]
description = Run Juju 2 integration tests
deps =
Expand All @@ -107,7 +118,8 @@ deps =
pytest-operator
-r{toxinidir}/requirements.txt
commands =
pytest -v --tb native --ignore={[vars]tst_path}unit --log-cli-level=INFO -s {posargs}
pytest -v --tb native --ignore={[vars]tst_path}unit --ignore={[vars]tst_path}interface
--log-cli-level=INFO -s {posargs}

[testenv:integration]
description = Run integration tests
Expand All @@ -118,7 +130,7 @@ deps =
pytest-operator
-r{toxinidir}/requirements.txt
commands =
pytest -v --tb native --ignore={[vars]tst_path}unit --log-cli-level=INFO -s {posargs}
pytest -v --tb native --ignore={[vars]tst_path}unit --ignore={[vars]tst_path}interface --log-cli-level=INFO -s {posargs}

[testenv:src-docs]
allowlist_externals=sh
Expand Down
Loading