Skip to content

Commit

Permalink
Enable ingress integration test (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
arturo-seijas authored Feb 7, 2024
1 parent 12083c8 commit 14ef8c0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integration_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
channel: 1.28-strict/stable
extra-arguments: |
--kube-config ${GITHUB_WORKSPACE}/kube-config
modules: '["test_jenkins.py", "test_k8s_agent.py", "test_machine_agent.py", "test_plugins.py", "test_proxy.py", "test_cos.py"]'
modules: '["test_ingress.py", "test_jenkins.py", "test_k8s_agent.py", "test_machine_agent.py", "test_plugins.py", "test_proxy.py", "test_cos.py"]'
pre-run-script: |
-c "sudo microk8s config > ${GITHUB_WORKSPACE}/kube-config
chmod +x tests/integration/pre_run_script.sh
Expand Down
3 changes: 1 addition & 2 deletions src/ingress.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ def __init__(self, charm: ops.CharmBase):
"""
super().__init__(charm, "ingress-observer")
self.charm = charm

self.ingress = IngressPerAppRequirer(self.charm, port=jenkins.WEB_PORT)
self.ingress = IngressPerAppRequirer(self.charm, port=jenkins.WEB_PORT, strip_prefix=True)
3 changes: 2 additions & 1 deletion src/jenkins.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@

WEB_PORT = 8080
WEB_URL = f"http://localhost:{WEB_PORT}"
LOGIN_URL = f"{WEB_URL}/login?from=%2F"
LOGIN_PATH = "/login?from=%2F"
LOGIN_URL = f"{WEB_URL}{LOGIN_PATH}"
EXECUTABLES_PATH = Path("/srv/jenkins/")
# Path to initial Jenkins password file
PASSWORD_FILE_PATH = JENKINS_HOME_PATH / "secrets/initialAdminPassword"
Expand Down
5 changes: 4 additions & 1 deletion tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,10 @@ async def ingress_application_related_fixture(application: Application, external
"traefik-k8s",
channel="1.0/stable",
trust=True,
config={"external_hostname": external_hostname},
config={
"external_hostname": external_hostname,
"routing_mode": "subdomain",
},
)
await application.model.wait_for_idle(
status="active", apps=[traefik.name], raise_on_error=False, timeout=30 * 60
Expand Down
18 changes: 12 additions & 6 deletions tests/integration/test_ingress.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,32 @@

"""Integration tests for jenkins-k8s-operator with ingress."""


# pylint: disable=unused-argument

import pytest
import requests
from juju.application import Application
from juju.model import Model

import jenkins


@pytest.mark.abort_on_fail
async def test_ingress_integration(
model: Model, ingress_related: Application, external_hostname: str
model: Model, application: Application, ingress_related: Application, external_hostname: str
):
"""
arrange: deploy the Jenkins charm and establish relations via ingress.
act: send a request to the ingress in /.
assert: the response succeeds.
"""
status = await model.get_status(filters=[ingress_related.name])
unit = next(iter(status.applications[ingress_related.name].units))
status = await model.get_status(filters=[application.name])
unit = next(iter(status.applications[application.name].units))
address = status["applications"][application.name]["units"][unit]["address"]
response = requests.get(
f"http://{unit.address}",
headers={"Host": f"{model.name}-{ingress_related.name}.{external_hostname}"},
f"http://{address}:{jenkins.WEB_PORT}{jenkins.LOGIN_PATH}",
headers={"Host": f"{model.name}-{application.name}.{external_hostname}"},
timeout=5,
).json()
)
assert response.status_code == 200

0 comments on commit 14ef8c0

Please sign in to comment.