-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from canonical/CSS-3449-cicd-tests
CSS-3449: Add CI/CD, unit and integration tests
- Loading branch information
Showing
17 changed files
with
351 additions
and
60 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Integration tests | ||
|
||
on: | ||
pull_request: | ||
|
||
jobs: | ||
integration-test-microk8s: | ||
name: Integration tests (microk8s) | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Setup operator environment | ||
uses: charmed-kubernetes/actions-operator@main | ||
with: | ||
juju-channel: 3.1/stable | ||
provider: microk8s | ||
channel: 1.25-strict/stable | ||
- name: Run integration tests | ||
# set a predictable model name so it can be consumed by charm-logdump-action | ||
run: tox -e integration -- --model testing | ||
- name: Dump logs | ||
uses: canonical/charm-logdump-action@main | ||
if: failure() | ||
with: | ||
app: temporal-ui-k8s | ||
model: testing |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Promote charm | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
origin-channel: | ||
type: choice | ||
description: 'Origin Channel' | ||
options: | ||
- latest/edge | ||
destination-channel: | ||
type: choice | ||
description: 'Destination Channel' | ||
options: | ||
- latest/stable | ||
secrets: | ||
CHARMHUB_TOKEN: | ||
required: true | ||
|
||
jobs: | ||
promote-charm: | ||
uses: canonical/operator-workflows/.github/workflows/promote_charm.yaml@main | ||
with: | ||
origin-channel: ${{ github.event.inputs.origin-channel }} | ||
destination-channel: ${{ github.event.inputs.destination-channel }} | ||
secrets: inherit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name: Tests | ||
|
||
on: | ||
pull_request: | ||
|
||
jobs: | ||
unit-tests: | ||
uses: canonical/operator-workflows/.github/workflows/test.yaml@main | ||
secrets: inherit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Publish to edge | ||
|
||
# On push to a "special" branch, we: | ||
# * always publish to charmhub at latest/edge/branchname | ||
# * always run tests | ||
# where a "special" branch is one of main/master or track/**, as | ||
# by convention these branches are the source for a corresponding | ||
# charmhub edge channel. | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- track/** | ||
|
||
jobs: | ||
publish-to-edge: | ||
uses: canonical/operator-workflows/.github/workflows/test_and_publish_charm.yaml@main | ||
secrets: inherit | ||
with: | ||
integration-test-provider: microk8s | ||
integration-test-provider-channel: 1.25-strict/stable | ||
integration-test-juju-channel: 3.1/stable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
ignore_files: | ||
# Ignore ingress charm library as it uses non compliant terminology: | ||
# whitelist. | ||
- lib/charms/nginx_ingress_integrator/v0/ingress.py | ||
rules: | ||
# Ignore "master" - the database relation event received from the library. | ||
- name: master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright 2023 Canonical Ltd Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
|
||
"""Temporal UI charm integration tests.""" | ||
|
||
import logging | ||
from pathlib import Path | ||
|
||
import pytest | ||
import pytest_asyncio | ||
import requests | ||
import yaml | ||
from pytest_operator.plugin import OpsTest | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
METADATA = yaml.safe_load(Path("./metadata.yaml").read_text()) | ||
APP_NAME = METADATA["name"] | ||
|
||
APP_NAME_SERVER = "temporal-k8s" | ||
APP_NAME_ADMIN = "temporal-admin-k8s" | ||
|
||
|
||
@pytest_asyncio.fixture(name="deploy", scope="module") | ||
async def deploy(ops_test: OpsTest): | ||
"""The app is up and running.""" | ||
charm = await ops_test.build_charm(".") | ||
resources = {"temporal-ui-image": METADATA["containers"]["temporal-ui"]["upstream-source"]} | ||
|
||
# Deploy temporal server, temporal admin and postgresql charms. | ||
await ops_test.model.deploy(charm, resources=resources, application_name=APP_NAME) | ||
await ops_test.model.deploy(APP_NAME_SERVER, channel="edge") | ||
await ops_test.model.deploy(APP_NAME_ADMIN, channel="edge") | ||
await ops_test.model.deploy("postgresql-k8s", channel="edge", trust=True) | ||
|
||
async with ops_test.fast_forward(): | ||
await ops_test.model.wait_for_idle( | ||
apps=[APP_NAME, APP_NAME_SERVER, APP_NAME_ADMIN], | ||
status="blocked", | ||
raise_on_blocked=False, | ||
timeout=1200, | ||
) | ||
await ops_test.model.wait_for_idle( | ||
apps=["postgresql-k8s"], | ||
status="active", | ||
raise_on_blocked=False, | ||
timeout=1200, | ||
) | ||
|
||
assert ops_test.model.applications[APP_NAME].units[0].workload_status == "blocked" | ||
await ops_test.model.integrate(f"{APP_NAME_SERVER}:db", "postgresql-k8s:db") | ||
await ops_test.model.integrate(f"{APP_NAME_SERVER}:visibility", "postgresql-k8s:db") | ||
await ops_test.model.integrate(f"{APP_NAME_SERVER}:admin", f"{APP_NAME_ADMIN}:admin") | ||
await ops_test.model.wait_for_idle( | ||
apps=[APP_NAME_SERVER, APP_NAME_ADMIN], | ||
status="active", | ||
raise_on_blocked=False, | ||
timeout=300, | ||
) | ||
|
||
await ops_test.model.integrate(f"{APP_NAME}:ui", f"{APP_NAME_SERVER}:ui") | ||
|
||
await ops_test.model.wait_for_idle( | ||
apps=[APP_NAME], | ||
status="active", | ||
raise_on_blocked=False, | ||
timeout=300, | ||
) | ||
|
||
assert ops_test.model.applications[APP_NAME].units[0].workload_status == "active" | ||
|
||
|
||
@pytest.mark.abort_on_fail | ||
@pytest.mark.usefixtures("deploy") | ||
class TestDeployment: | ||
"""Integration tests for Temporal UI charm.""" | ||
|
||
async def test_basic_client(self, ops_test: OpsTest): | ||
"""Perform GET request on the Temporal UI host.""" | ||
status = await ops_test.model.get_status() # noqa: F821 | ||
address = status["applications"][APP_NAME]["units"][f"{APP_NAME}/0"]["address"] | ||
url = f"http://{address}:8080" | ||
logger.info("curling app address: %s", url) | ||
|
||
response = requests.get(url, timeout=300) | ||
assert response.status_code == 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
# Copyright 2023 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
|
||
"""Unit tests config.""" | ||
|
||
import ops.testing | ||
|
||
ops.testing.SIMULATE_CAN_CONNECT = True |
Oops, something went wrong.