Skip to content

Commit

Permalink
Rename packages to 'opr' because 'operator' is a package in the pytho…
Browse files Browse the repository at this point in the history
…n standard library and imports fail otherwise

Rename 'server' to 'srv' for consistency
Add pytest tests for tornado
  • Loading branch information
meffmadd committed Jul 9, 2024
1 parent 2b73723 commit 01a119c
Show file tree
Hide file tree
Showing 18 changed files with 44 additions and 7 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

File renamed without changes.
Empty file added opr/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file added srv/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions testing.requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pytest
pytest-asyncio
pytest-cov
pytest-mock
pytest-tornado
Empty file added tests/__init__.py
Empty file.
Empty file added tests/opr/__init__.py
Empty file.
Empty file added tests/srv/__init__.py
Empty file.
31 changes: 31 additions & 0 deletions tests/srv/test_key_handler.py
Original file line number Diff line number Diff line change
@@ -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"})

0 comments on commit 01a119c

Please sign in to comment.