-
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.
add tests to OIDC authservice rock (#14)
* add oidc-authservice rock tests * edit dummy rock tests to implement sanity checks edits the original copy/pasted tox.ini and test_rock.py files to suit this repo. tox.ini was refactored because it either did not work before, or I didn't fully understand what it should be doing. tox.ini's integration environment has been replaced with a passing stub so it does not cause CI failure. * update per review suggestion Co-authored-by: Orfeas Kourkakis <orfeas.kourkakis@canonical.com> * update per review suggestion Co-authored-by: Orfeas Kourkakis <orfeas.kourkakis@canonical.com> * Apply suggestions from code review * fix: rename var to be less verbose * fix: pin chisme to main * feat: add gitignore * fix: gitignore * fix: microk8s and juju channel compatible with ckf 1.7 * fix: remove pycache file * ci: modify on pull request and add on push workflow * fix: update build and publish workflow --------- Co-authored-by: Orfeas Kourkakis <orfeas.kourkakis@canonical.com> Co-authored-by: NohaIhab <noha.ihab@canonical.com>
- Loading branch information
1 parent
21476c9
commit fc0b0b8
Showing
6 changed files
with
131 additions
and
8 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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: On Push | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- track/** | ||
|
||
jobs: | ||
|
||
on-push: | ||
name: Get ROCKs modified and build-scan-test-publish them | ||
uses: canonical/charmed-kubeflow-workflows/.github/workflows/get-rocks-modified-and-build-scan-test-publish.yaml@main | ||
permissions: | ||
pull-requests: read | ||
secrets: inherit | ||
with: | ||
microk8s-channel: 1.24/stable | ||
juju-channel: 2.9/stable | ||
python-version: "3.8" |
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,3 @@ | ||
__pycache__ | ||
.tox | ||
*.rock |
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,40 @@ | ||
# Copyright 2022 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
# | ||
# | ||
|
||
from pathlib import Path | ||
|
||
import os | ||
import logging | ||
import random | ||
import pytest | ||
import string | ||
import subprocess | ||
import yaml | ||
|
||
from charmed_kubeflow_chisme.rock import CheckRock | ||
|
||
@pytest.fixture() | ||
def rock_test_env(tmpdir): | ||
"""Yields a temporary directory and random docker container name, then cleans them up after.""" | ||
container_name = "".join([str(i) for i in random.choices(string.ascii_lowercase, k=8)]) | ||
yield tmpdir, container_name | ||
|
||
try: | ||
subprocess.run(["docker", "rm", container_name]) | ||
except Exception: | ||
pass | ||
# tmpdir fixture we use here should clean up the other files for us | ||
|
||
@pytest.mark.abort_on_fail | ||
def test_rock(rock_test_env): | ||
"""Test rock.""" | ||
temp_dir, container_name = rock_test_env | ||
check_rock = CheckRock("rockcraft.yaml") | ||
rock_image = check_rock.get_name() | ||
rock_version = check_rock.get_version() | ||
LOCAL_ROCK_IMAGE = f"{rock_image}:{rock_version}" | ||
|
||
# create ROCK filesystem | ||
subprocess.run(["docker", "run", LOCAL_ROCK_IMAGE, "exec", "ls", "-la", "/bin/oidc-authservice"], check=True) |
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,57 @@ | ||
# Copyright 2022 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
[tox] | ||
skipsdist = True | ||
skip_missing_interpreters = True | ||
envlist = unit, sanity, integration | ||
|
||
[testenv] | ||
setenv = | ||
PYTHONPATH={toxinidir} | ||
PYTHONBREAKPOINT=ipdb.set_trace | ||
CHARM_REPO=https://github.com/canonical/oidc-gatekeeper-operator.git | ||
CHARM_BRANCH=main | ||
LOCAL_CHARM_DIR=charm_repo | ||
|
||
[testenv:pack] | ||
passenv = * | ||
allowlist_externals = | ||
rockcraft | ||
commands = | ||
rockcraft pack | ||
|
||
[testenv:export-to-docker] | ||
passenv = * | ||
allowlist_externals = | ||
bash | ||
skopeo | ||
yq | ||
commands = | ||
# pack rock and export to docker | ||
bash -c 'NAME=$(yq eval .name rockcraft.yaml) && \ | ||
VERSION=$(yq eval .version rockcraft.yaml) && \ | ||
ARCH=$(yq eval ".platforms | keys | .[0]" rockcraft.yaml) && \ | ||
ROCK="$\{NAME\}_$\{VERSION\}_$\{ARCH\}.rock" && \ | ||
DOCKER_IMAGE=$NAME:$VERSION && \\ | ||
echo "Exporting $ROCK to docker as $DOCKER_IMAGE" && \\ | ||
skopeo --insecure-policy copy oci-archive:$ROCK docker-daemon:$DOCKER_IMAGE' | ||
|
||
[testenv:sanity] | ||
passenv = * | ||
deps = | ||
pytest | ||
# TODO: unpin this after this chisme PR is released: | ||
# https://github.com/canonical/charmed-kubeflow-chisme/pull/81 | ||
# charmed-kubeflow-chisme | ||
git+https://github.com/canonical/charmed-kubeflow-chisme.git@main | ||
commands = | ||
# run rock tests | ||
pytest -v --tb native --show-capture=all --log-cli-level=INFO {posargs} {toxinidir}/tests | ||
|
||
[testenv:integration] | ||
passenv = * | ||
allowlist_externals = | ||
echo | ||
commands = | ||
# TODO: Implement integration tests here | ||
echo "WARNING: This is a placeholder test - no test is implemented here." |