diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 670d308..463682a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,14 +35,16 @@ jobs: runs-on: ubuntu-latest needs: - changed-dirs - if: contains(needs.changed-dirs.outputs.changeDirs, 'operator') || contains(needs.changed-dirs.outputs.changeDirs, 'server') + if: contains(needs.changed-dirs.outputs.changeDirs, 'opr') || contains(needs.changed-dirs.outputs.changeDirs, 'srv') strategy: matrix: include: - image: ghcr.io/tu-wien-datalab/config-server-operator - directory: operator + directory: opr + version-pattern: operator-v(\d.+) - image: ghcr.io/tu-wien-datalab/config-server - directory: server + directory: srv + version-pattern: server-v(\d.+) steps: - name: Docker metadata id: meta @@ -53,8 +55,7 @@ jobs: # generate Docker tags based on the following events/attributes tags: | type=ref,event=branch - type=match,pattern=\w+-v(\d.+),group=1 - type=ref,event=tag + type=match,pattern=${{ matrix.pattern }},group=1 type=sha - name: Checkout repository diff --git a/README.md b/README.md index f7ff097..123875d 100644 --- a/README.md +++ b/README.md @@ -37,12 +37,12 @@ Install dependencies Add the CRDs to the cluster ```bash - kubectl apply -f operator/crd.yaml + kubectl apply -f opr/crd.yaml ``` Run the operator ```bash - kopf run operator/operator.py --verbose + kopf run opr/operator.py --verbose ``` diff --git a/operator/Dockerfile b/opr/Dockerfile similarity index 100% rename from operator/Dockerfile rename to opr/Dockerfile diff --git a/opr/__init__.py b/opr/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/operator/crd.yaml b/opr/crd.yaml similarity index 100% rename from operator/crd.yaml rename to opr/crd.yaml diff --git a/operator/operator.py b/opr/operator.py similarity index 100% rename from operator/operator.py rename to opr/operator.py diff --git a/operator/requirements.txt b/opr/requirements.txt similarity index 100% rename from operator/requirements.txt rename to opr/requirements.txt diff --git a/operator/tbump.toml b/opr/tbump.toml similarity index 100% rename from operator/tbump.toml rename to opr/tbump.toml diff --git a/server/Dockerfile b/srv/Dockerfile similarity index 100% rename from server/Dockerfile rename to srv/Dockerfile diff --git a/srv/__init__.py b/srv/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/server/requirements.txt b/srv/requirements.txt similarity index 100% rename from server/requirements.txt rename to srv/requirements.txt diff --git a/server/server.py b/srv/server.py similarity index 100% rename from server/server.py rename to srv/server.py diff --git a/server/tbump.toml b/srv/tbump.toml similarity index 100% rename from server/tbump.toml rename to srv/tbump.toml diff --git a/testing.requirements.txt b/testing.requirements.txt new file mode 100644 index 0000000..44e9792 --- /dev/null +++ b/testing.requirements.txt @@ -0,0 +1,5 @@ +pytest +pytest-asyncio +pytest-cov +pytest-mock +pytest-tornado \ No newline at end of file diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/opr/__init__.py b/tests/opr/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/srv/__init__.py b/tests/srv/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/srv/test_key_handler.py b/tests/srv/test_key_handler.py new file mode 100644 index 0000000..4504763 --- /dev/null +++ b/tests/srv/test_key_handler.py @@ -0,0 +1,31 @@ +import json +import os.path +import pathlib + +from tornado.httpclient import HTTPClientError + +import pytest + +from srv.server import make_app + + +@pytest.fixture +def app(tmp_path): + return make_app(tmp_path) + + +@pytest.mark.gen_test +async def test_key_not_found(http_client, base_url): + with pytest.raises(HTTPClientError) as e: + await http_client.fetch(os.path.join(base_url, "key", "non_existent")) + assert e.value.code == 404 + + +@pytest.mark.gen_test +async def test_key_not_found(http_client, base_url, app): + path: pathlib.Path = app.settings["config_values"] + test_file = path / "test" + test_file.write_text(json.dumps({"foo": "bar"})) + response = await http_client.fetch(os.path.join(base_url, "key", "test")) + assert response.code == 200 + assert response.body.decode() == json.dumps({"foo": "bar"})