Skip to content

Commit

Permalink
Move aproxy test to own module
Browse files Browse the repository at this point in the history
This is to avoid interference with other tests in the same module.
  • Loading branch information
cbartz committed Nov 17, 2023
1 parent d324f21 commit c9e6270
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 32 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/integration_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
pre-run-script: scripts/pre-integration-test.sh
provider: lxd
test-tox-env: integration-juju2.9
modules: '["test_charm_fork_repo", "test_charm_no_runner", "test_charm_scheduled_events", "test_charm_one_runner", "test_charm_metrics", "test_self_hosted_runner"]'
modules: '["test_charm_fork_repo", "test_charm_no_runner", "test_charm_scheduled_events", "test_charm_one_runner", "test_charm_metrics", "test_self_hosted_runner", "test_charm_with_proxy"]'
integration-tests-juju3:
name: Integration test with juju 3.1
uses: canonical/operator-workflows/.github/workflows/integration_test.yaml@main
Expand All @@ -23,4 +23,4 @@ jobs:
pre-run-script: scripts/pre-integration-test.sh
provider: lxd
test-tox-env: integration-juju3.1
modules: '["test_charm_fork_repo", "test_charm_no_runner", "test_charm_scheduled_events", "test_charm_one_runner", "test_charm_metrics", "test_self_hosted_runner"]'
modules: '["test_charm_fork_repo", "test_charm_no_runner", "test_charm_scheduled_events", "test_charm_one_runner", "test_charm_metrics", "test_self_hosted_runner", "test_charm_with_proxy"]'
30 changes: 0 additions & 30 deletions tests/integration/test_charm_one_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from charm import GithubRunnerCharm
from tests.integration.helpers import (
assert_resource_lxd_profile,
ensure_charm_has_runner,
get_runner_names,
reconcile,
run_in_lxd_instance,
Expand Down Expand Up @@ -50,35 +49,6 @@ async def test_network_access(app: Application) -> None:
assert stdout is None


@pytest.mark.asyncio
@pytest.mark.abort_on_fail
async def test_usage_of_aproxy(model: Model, app_no_runner: Application, squid_proxy: str) -> None:
"""
arrange: A working application with one runner using aproxy configured for a proxy server.
act: Run curl in the runner.
assert: The aproxy log contains the request.
"""
app = app_no_runner # Rename to make it clear that the app will contain a runner.
unit = app.units[0]

await app.set_config({"aproxy-address": squid_proxy})
await ensure_charm_has_runner(app, model)

names = await get_runner_names(unit)
assert names
runner_name = names[0]

return_code, stdout = await run_in_lxd_instance(unit, runner_name, "curl http://canonical.com")
assert return_code == 0

return_code, stdout = await run_in_lxd_instance(
unit, runner_name, "snap logs aproxy.aproxy -n=all"
)
assert return_code == 0
assert stdout is not None
assert "canonical.com" in stdout


@pytest.mark.asyncio
@pytest.mark.abort_on_fail
async def test_flush_runner_and_resource_config(app: Application) -> None:
Expand Down
42 changes: 42 additions & 0 deletions tests/integration/test_charm_with_proxy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.

"""Test the usage of a proxy server."""
import pytest
from juju.application import Application
from juju.model import Model

from tests.integration.helpers import (
ensure_charm_has_runner,
get_runner_names,
run_in_lxd_instance,
)


@pytest.mark.asyncio
@pytest.mark.abort_on_fail
async def test_usage_of_aproxy(model: Model, app_no_runner: Application, squid_proxy: str) -> None:
"""
arrange: A working application with one runner using aproxy configured for a proxy server.
act: Run curl in the runner.
assert: The aproxy log contains the request.
"""
app = app_no_runner # Rename to make it clear that the app will contain a runner.
unit = app.units[0]

await app.set_config({"aproxy-address": squid_proxy})
await ensure_charm_has_runner(app, model)

names = await get_runner_names(unit)
assert names
runner_name = names[0]

return_code, stdout = await run_in_lxd_instance(unit, runner_name, "curl http://canonical.com")
assert return_code == 0

return_code, stdout = await run_in_lxd_instance(
unit, runner_name, "snap logs aproxy.aproxy -n=all"
)
assert return_code == 0
assert stdout is not None
assert "canonical.com" in stdout

0 comments on commit c9e6270

Please sign in to comment.