-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update the reminder plugin and add a test for it (#10)
* Fix metadata.yaml to work with current ops * Fix integration tests * Add github workflows and issue templates * Replace apt dist-upgrade by apt upgrade * Lint metadata.yaml * Shorten summary of the charm * Largely ignore inclusive naming issues for now * Add our standard tox/pyproject structure w/o enabling everything * Don't use the full test suite of operator-workflows * Don't hide files from inclusive names test * Only do unit tests in unit tests ! * Expand summary a bit * Removing duplicate apt-get update/upgrade * Change licence into license * Create environment module * Render fn outputs immutable in environment.py * Fix incorrect comment * Revert config naming back to "licence" * Add some context to a comment with link to ref * Fix tests still using "license" as config name * Simplify `enable_smtp_auth` definition * Add fixtures in conftest.py for integration tests * Change env functions to be generators * Transform missing_config_settings into generator * Use typing.Tuple in environment.py * Add/Fix copyright notices * Add s3_tls config option * Add s3 integration test * Fix typo * Add local_mode buildarg to the Dockerfile * Rework integ tests to make s3 tests work * Adapt integ tests to use the build image job of operator-workflows * Relaunch CI * Test without build-args * Fix input name * Change image-build-args into list * Use build-args as simple string * Relaunch CI * Fix extra arguments * Launch CI * Add trivyignore file * Switch to the main branch of operator-workflows * Add workload scale integ test * Kill the leader unit after scaling up * Address some PR comments * Remove local_mode and s3_tls option in favor of the extra_env option * Fix integration tests * Change ops_test.model into a fixture * Add a test_user fixture * Use secrets for localstack access key * Use requests instead of curl, test content of uploaded file * Small fixes * Use tmp_path from pytest instead of a "real" file * Try to change the model config before launching tests * Use localstack:1.4 * Don't active pro mode for localstack * Use IP for s3_config's domain * Try another fix for s3 * Fixes * Fix extra-args on CI * Address PR comments * Address PR comments * Fixes * Fix integ workflow * Fix the pod matching regex * Pin k8s dep * Update remind plugin and add a integ test for it * Improve code quality * Reduce scale test to 2 units to avoid potential memory issues * Try to debug localstack-installation.sh * Try to mkdir missing dir * Try fix localstack version to 1.4.0 * Remove debug env * Try adding a waiting loop * Address PR comments * Revert to ops_test.juju("run", ...) instead of app.run() * Change exception var name * Address comments * Trying to debug test * Fix test * Try to debug * Try without regex * Address comments
- Loading branch information
1 parent
29d0f36
commit c0e5c5d
Showing
6 changed files
with
229 additions
and
99 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -7,19 +7,23 @@ | |
import json | ||
import logging | ||
import secrets | ||
import time | ||
from pathlib import Path | ||
from urllib.parse import urlparse | ||
|
||
import kubernetes | ||
import ops | ||
import pytest_asyncio | ||
import requests | ||
import yaml | ||
from boto3 import client | ||
from botocore.config import Config | ||
from ops.model import ActiveStatus, Application | ||
from pytest import FixtureRequest, fixture | ||
from pytest_operator.plugin import OpsTest | ||
|
||
import utils | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
|
@@ -44,15 +48,6 @@ def mattermost_image(request): | |
return request.config.getoption("--mattermost-image") | ||
|
||
|
||
@fixture(scope="module") | ||
def test_user(): | ||
"""Create login informations for a test user. | ||
Return a dict with the users informations | ||
""" | ||
return {"login_id": "[email protected]", "password": secrets.token_hex()} | ||
|
||
|
||
@pytest_asyncio.fixture(scope="module", name="model") | ||
async def model_fixture(ops_test: OpsTest) -> ops.model.Model: | ||
"""Provide current test model.""" | ||
|
@@ -79,10 +74,18 @@ async def app( | |
application = await model.deploy(charm, application_name=app_name, series="focal") | ||
await model.wait_for_idle() | ||
|
||
# change the image that will be used for the mattermost container | ||
# Change the image that will be used for the mattermost container | ||
# and use some common test configuration extra env variables | ||
await application.set_config( | ||
{ | ||
"mattermost_image_path": mattermost_image, | ||
"extra_env": json.dumps( | ||
{ | ||
"MM_FILESETTINGS_AMAZONS3SSL": "false", | ||
"MM_SERVICESETTINGS_ENABLELOCALMODE": "true", | ||
"MM_SERVICESETTINGS_LOCALMODESOCKETLOCATION": "/tmp/mattermost.socket", | ||
} | ||
), | ||
} | ||
) | ||
await model.wait_for_idle() | ||
|
@@ -93,22 +96,75 @@ async def app( | |
# mypy doesn't see that ActiveStatus has a name | ||
await model.wait_for_idle(status=ActiveStatus.name) # type: ignore | ||
|
||
# test that the application is online | ||
for _ in range(10): | ||
if await utils.is_mattermost_reachable( | ||
await utils.get_mattermost_ip(ops_test, application) | ||
): | ||
break | ||
time.sleep(10) | ||
|
||
assert await utils.is_mattermost_reachable( | ||
await utils.get_mattermost_ip(ops_test, application) | ||
) | ||
yield application | ||
|
||
|
||
@pytest_asyncio.fixture(scope="module") | ||
async def mattermost_ip( | ||
async def test_entities( | ||
ops_test: OpsTest, | ||
app: Application, | ||
): | ||
"""Get the IP address of the first unit of mattermost. | ||
"""Create some usual test entities to be used in integration tests.""" | ||
mattermost_ip = await utils.get_mattermost_ip(ops_test, app) | ||
|
||
Return the IP address of a mattermost unit. | ||
""" | ||
unit_informations = json.loads( | ||
(await ops_test.juju("show-unit", app.units[0].name, "--format", "json"))[1] | ||
test_user = {"login_id": "[email protected]", "password": secrets.token_hex()} | ||
|
||
# create a user | ||
cmd = ( | ||
f"MMCTL_LOCAL_SOCKET_PATH=/tmp/mattermost.socket /mattermost/bin/mmctl" | ||
f" --local user create --email {test_user['login_id']} --username test" | ||
f" --password {test_user['password']}" | ||
) | ||
await ops_test.juju("run", "--application", app.name, cmd) | ||
|
||
# login to the API | ||
response = requests.post( | ||
f"http://{mattermost_ip}:8065/api/v4/users/login", data=json.dumps(test_user), timeout=10 | ||
) | ||
return unit_informations[app.units[0].name]["address"] | ||
token = response.headers["Token"] | ||
headers = {"authorization": f"Bearer {response.headers['Token']}"} | ||
|
||
# create a team | ||
data = {"name": "test", "display_name": "test", "type": "O"} | ||
response = requests.post( | ||
f"http://{mattermost_ip}:8065/api/v4/teams", | ||
data=json.dumps(data), | ||
headers=headers, | ||
timeout=10, | ||
) | ||
team = response.json() | ||
|
||
# create a channel | ||
data = {"team_id": team["id"], "name": "test", "display_name": "test", "type": "O"} | ||
response = requests.post( | ||
f"http://{mattermost_ip}:8065/api/v4/channels", | ||
data=json.dumps(data), | ||
headers=headers, | ||
timeout=10, | ||
) | ||
channel = response.json() | ||
|
||
yield { | ||
"token": token, | ||
"headers": headers, | ||
"user": { | ||
"email": test_user["login_id"], | ||
"password": test_user["password"], | ||
}, | ||
"team": team, | ||
"channel": channel, | ||
} | ||
|
||
|
||
@fixture(scope="module") | ||
|
@@ -180,7 +236,7 @@ def localstack_s3_client(localstack_s3_config: dict) -> client: | |
|
||
@fixture(scope="module", name="kube_config") | ||
def kube_config_fixture(request: FixtureRequest): | ||
"""The Kubernetes cluster configuration file.""" | ||
"""Return the Kubernetes cluster configuration file.""" | ||
kube_config = request.config.getoption("--kube-config") | ||
assert kube_config, ( | ||
"The Kubernetes config file path should not be empty, " | ||
|
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
Oops, something went wrong.