Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ services:
path: ./keycloak

keycloak-config-cli:
build: ./config
build: ./keycloak-config-cli
depends_on:
- keycloak
environment:
Expand Down
1 change: 1 addition & 0 deletions keycloak/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ RUN ./build_and_collect_jars.sh

# Stage 2: Build Keycloak with the SPIs and themes
FROM quay.io/keycloak/keycloak:${KEYCLOAK_VERSION} AS keycloak
ENV KC_HEALTH_ENABLED=true
COPY --from=builder /workspace/.jars/*.jar /opt/keycloak/providers/
COPY themes /opt/keycloak/themes
RUN /opt/keycloak/bin/kc.sh build
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ dependencies = [
"pydantic-settings>=2.8.1",
"pyyaml>=6.0.2",
]

[tool.uv]
dev-dependencies = [
"pytest>=6.0",
"requests>=2.25"
]
75 changes: 75 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Keycloak Smoke Tests

## Setup Instructions

1. **Clone the Repository**

If you haven't already, clone the repository:

```bash
git clone [email protected]:NASA-IMPACT/veda-keycloak.git
```

Navigate to the project directory:

```bash
cd veda-keycloak
```

2. **Install Dependencies**

Using uv, install the required dependencies:

```bash
uv sync
```

## Running the Tests

1. **Run All Tests**

Execute all tests using `pytest`:

```bash
uv run pytest
```

This command will discover and run all test files matching the pattern `test_*.py` or `*_test.py` within the current
directory and its subdirectories.


2. **Run a Specific Test File**

To execute tests in a particular test file:

```bash
uv run pytest tests/smoke/test_health_check.py
```

3. **Run a Specific Test Function**

To run a specific test function within a test file:

```bash
uv run pytest tests/smoke/test_health_check.py::test_keycloak_health_check
```

## Additional Pytest Options

- **Verbose Output**: For more detailed output, add the `-v` flag:

```bash
uv run pytest -v
```

- **Stop After First Failure**: To halt the test run after the first failure, use the `-x` option:

```bash
uv run pytest -x
```

- **Show Local Variables on Failure**: To display local variables in tracebacks, include the `-l` flag:

```bash
uv run pytest -l
```
Empty file added tests/smoke/__init__.py
Empty file.
24 changes: 24 additions & 0 deletions tests/smoke/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import os
import pytest
from pydantic_settings import BaseSettings, SettingsConfigDict


class Settings(BaseSettings):
hostname: str = os.getenv("HOSTNAME", "http://localhost:8080")

model_config = SettingsConfigDict(
env_file=".env", # Load from .env if available (only if HOSTNAME is not set)
extra="ignore"
)


@pytest.fixture(scope='session')
def settings():
"""Returns an instance of Settings"""
return Settings()


@pytest.fixture(scope='session')
def base_url(settings):
"""Extracts base_url from settings"""
return settings.hostname
13 changes: 13 additions & 0 deletions tests/smoke/test_health_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pytest
import requests


@pytest.mark.parametrize("endpoint", ["live", "ready"])
def test_keycloak_health_check(base_url, endpoint):
url = f"{base_url}/health/{endpoint}"

response = requests.get(url)
assert response.status_code == 200, f"Expected status code 200 for /health/{endpoint}, got {response.status_code}"

json_response = response.json()
assert json_response.get("status") == "UP", f"Expected status 'UP' for /health/{endpoint}, got {json_response.get('status')}"
119 changes: 119 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.