Skip to content

Commit f521d95

Browse files
committed
Add integration tests
Signed-off-by: kerthcet <[email protected]>
1 parent c1f5c4c commit f521d95

File tree

8 files changed

+122
-21
lines changed

8 files changed

+122
-21
lines changed

.env.integration-test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
METADATA_DB_URL=sqlite:///:memory:
2-
ARTIFACT_REGISTRY_URL=europe-west2-docker.pkg.dev/runsandbox-449400/
1+
METADATA_DB_URL=postgresql+psycopg2://at_user:at_pass@localhost:5432/at_db
2+
ARTIFACT_REGISTRY_URL=localhost:5001
33
LOG_LEVEL=INFO

.github/workflows/python-ci.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,7 @@ jobs:
3131

3232
- name: Run tests
3333
run: make test
34+
35+
- name: Run integration tests
36+
run: |
37+
make test-integration

Makefile

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,24 @@ publish: build
1212
launch:
1313
docker-compose up -d
1414

15+
.PHONY: lint
16+
lint:
17+
$(POETRY) run ruff check .
18+
1519
.PHONY: format
1620
format:
1721
$(POETRY) run ruff format .
18-
$(POETRY) run ruff check .
1922

2023
.PHONY: test
21-
test: format
24+
test: lint
2225
$(POETRY) run pytest tests/unit
2326

2427
.PHONY: test-integration
25-
test-integration: format
26-
$(POETRY) run pytest tests/integration
28+
test-integration: lint
29+
@bash -c '\
30+
set -e; \
31+
docker-compose up -d; \
32+
trap "docker-compose down" EXIT; \
33+
until docker exec postgres pg_isready -U at_user; do sleep 1; done; \
34+
$(POETRY) run pytest tests/integration; \
35+
'

alphatrion/artifact/artifact.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99

1010

1111
class Artifact:
12-
def __init__(self, runtime: Runtime):
12+
def __init__(self, runtime: Runtime, insecure: bool = False):
1313
self._runtime = runtime
1414
self._url = os.environ.get(consts.ARTIFACT_REGISTRY_URL)
1515
self._url = self._url.replace("https://", "").replace("http://", "")
1616
self._client = oras.client.OrasClient(
17-
hostname=self._url.strip("/"), auth_backend="token"
17+
hostname=self._url.strip("/"), auth_backend="token", insecure=insecure
1818
)
1919

2020
def push(self, experiment_name: str, files: list[str], version: str = "latest"):

docker-compose.yaml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
1-
version: "3.9"
2-
31
services:
42
postgres:
3+
container_name: postgres
54
image: postgres:16
65
environment:
76
POSTGRES_USER: at_user
87
POSTGRES_PASSWORD: at_pass
98
POSTGRES_DB: at_db
109
ports:
1110
- "5432:5432"
12-
volumes:
13-
- pg_data:/var/lib/postgresql/data
11+
# volumes:
12+
# - pg_data:/var/lib/postgresql/data
1413
deploy:
1514
replicas: 1
1615
restart_policy:
1716
condition: any
18-
19-
volumes:
20-
pg_data:
17+
registry:
18+
container_name: registry
19+
image: registry:3
20+
ports:
21+
- "5001:5000"
22+
# volumes:
23+
# - oras-data:/data
24+
# volumes:
25+
# pg_data:
26+
# oras-data:

poetry.lock

Lines changed: 79 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ dependencies = [
1010
"sqlalchemy (>=2.0.43,<3.0.0)",
1111
"python-dotenv (>=1.1.1,<2.0.0)",
1212
"oras (>=0.2.38,<0.3.0)",
13+
"psycopg2-binary (>=2.9.10,<3.0.0)",
1314
]
1415

1516
[tool.poetry.group.dev.dependencies]

tests/integration/artifact/test_artifact.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111

1212
@pytest.fixture
1313
def artifact():
14-
runtime = Runtime(project_id="ckpt")
15-
artifact = Artifact(runtime=runtime)
14+
# We use a local registry for testing, it doesn't mean
15+
# it will always successfully with cloud registries.
16+
# We may need e2e tests for that.
17+
runtime = Runtime(project_id="test_project")
18+
artifact = Artifact(runtime=runtime, insecure=True)
1619
yield artifact
1720

1821

@@ -35,6 +38,6 @@ def test_push(artifact):
3538
tags = artifact.list_tags("test_experiment")
3639
assert "v1" in tags
3740

38-
# artifact.delete_tags(experiment_name="test_experiment", versions="v1")
39-
# tags = artifact.list_tags("test_experiment")
40-
# assert "v1" not in tags
41+
artifact.delete_tags(experiment_name="test_experiment", versions="v1")
42+
tags = artifact.list_tags("test_experiment")
43+
assert "v1" not in tags

0 commit comments

Comments
 (0)