Skip to content

Commit d6019c8

Browse files
committed
Create an IntegrationTestScenario
This patch adds a definition for an integration test that is triggered by Konflux after each build. The test exercises most of the API. The `.tekton/cts-integration-test.yaml` is the actual K8S CRD that needs to be created in the cluster. The test pipeline uses an ephemeral namespace in which it starts a PostgreSQL database and CTS from the currently built image. There is a code change in the service itself to enable setting database URL in DevConfiguration. Assisted-By: Claude
1 parent 64cdf28 commit d6019c8

5 files changed

Lines changed: 1121 additions & 0 deletions

File tree

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# CTS Integration Tests for Konflux CI
2+
3+
## Overview
4+
5+
The integration test scenario validates that the built CTS container image
6+
works correctly by provisioning an ephemeral environment and deploying the
7+
service with a real PostgreSQL database.
8+
9+
## Files
10+
11+
### Integration Test Scenario
12+
13+
- **`cts-integration-test.yaml`** - IntegrationTestScenario CRD that defines
14+
when and how tests run
15+
- Runs automatically after successful builds
16+
- References the test pipeline
17+
- Marks failed builds if tests fail
18+
19+
### Test Pipelines
20+
21+
- **`integration-test-eaas.yaml`** - EaaS-based integration test
22+
- Uses Konflux EaaS (Environment as a Service) to provision ephemeral namespace
23+
- Deploys real PostgreSQL database
24+
- Deploys CTS service with the built image
25+
- Tests actual API functionality
26+
- Automatically cleans up when pipeline completes
27+
- Full integration testing with proper Kubernetes resources
28+
29+
### Test Scripts
30+
31+
- **`../tests/test_integration_api.py`** - Integration tests using pytest
32+
- Supports both local testing and CI pipeline testing
33+
- Uses pytest fixtures for clean test setup
34+
- Two modes:
35+
- **Direct HTTP**: `CTS_URL=http://localhost:5005 pytest tests/test_integration_api.py -v`
36+
- **Kubectl exec**: `KUBECTL_POD=<pod-name> pytest tests/test_integration_api.py -v`
37+
- In CI, uses kubectl exec mode to run curl commands inside the CTS pod
38+
- Tests all major API endpoints
39+
- Edit this file to add or modify integration tests
40+
41+
## What Gets Tested
42+
43+
The integration tests validate:
44+
45+
-**Service Startup** - Container starts without errors
46+
-**Database Connectivity** - Migrations run successfully
47+
-**API Endpoints** - All major endpoints respond correctly:
48+
- `GET /api/1/` - API root
49+
- `GET /api/1/about/` - Version information
50+
- `GET /api/1/composes/` - Compose listing
51+
- `GET /api/1/openapi.json` - OpenAPI specification
52+
-**Error Handling** - 404 responses for invalid endpoints
53+
-**Pagination** - Query parameters work correctly
54+
55+
## How It Works
56+
57+
### In Konflux CI
58+
59+
1. Code is pushed to the repository or PR is created
60+
2. Tekton build pipeline builds the container image
61+
3. **IntegrationTestScenario** automatically triggers
62+
4. Test pipeline deploys and validates the image
63+
5. Results are reported back to the PR/commit
64+
65+
### Pipeline Execution Flow (EaaS approach)
66+
67+
```
68+
┌─────────────────────────────┐
69+
│ 1. Parse Snapshot │ Extract image URL, git URL, git revision
70+
└─────────────┬───────────────┘
71+
72+
┌─────────────▼───────────────┐
73+
│ 2. Provision Environment │ Create ephemeral namespace via EaaS
74+
│ │ Returns kubeconfig secret
75+
└─────────────┬───────────────┘
76+
77+
┌─────────────▼───────────────┐
78+
│ 3. Deploy PostgreSQL │ Create Deployment & Service in ephemeral ns
79+
└─────────────┬───────────────┘
80+
81+
┌─────────────▼───────────────┐
82+
│ 4. Deploy CTS Service │ Create Deployment & Service in ephemeral ns
83+
└─────────────┬───────────────┘
84+
85+
┌─────────────▼───────────────┐
86+
│ 5. Run Integration Tests │ Clone repo, run tests via kubectl exec
87+
│ │
88+
└─────────────┬───────────────┘
89+
90+
┌─────────────▼───────────────┐
91+
│ 6. Automatic Cleanup │ Ephemeral namespace deleted by EaaS
92+
└─────────────────────────────┘
93+
```
94+
95+
## Running Tests Locally
96+
97+
```bash
98+
# Point to your deployment
99+
CTS_URL=https://cts.example.com pytest tests/test_integration_api.py -v
100+
```
101+
102+
103+
## Customizing Tests
104+
105+
### Adding New Test Cases
106+
107+
Edit `tests/test_integration_api.py` and add new test functions:
108+
109+
```python
110+
def test_my_new_feature(http_client):
111+
"""Test my new API endpoint"""
112+
status, data = http_client.get('/api/1/my-endpoint/')
113+
assert status == 200
114+
assert 'expected_field' in data
115+
```
116+
117+
That's it! Pytest automatically discovers and runs all `test_*` functions.
118+
No need to manually register tests or track results.
119+
120+
### Modifying the Test Environment
121+
122+
Edit `.tekton/integration-test-eaas.yaml` to change:
123+
124+
- Database configuration (in the `deploy-database` task's Deployment spec)
125+
- CTS environment variables (in the `deploy-cts` task's Deployment spec)
126+
- Test execution logic (in the `run-tests` task's Python script)
127+
128+
129+
## Related Documentation
130+
131+
- [Konflux Integration Tests](https://konflux-ci.dev/docs/how-tos/testing/integration/)
132+
- [Tekton Pipelines](https://tekton.dev/docs/pipelines/)

.tekton/cts-integration-test.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apiVersion: appstudio.redhat.com/v1beta1
2+
kind: IntegrationTestScenario
3+
metadata:
4+
name: cts-integration-test
5+
namespace: team-sp-rhelcmp-tenant
6+
labels:
7+
test.appstudio.openshift.io/optional: "false"
8+
spec:
9+
application: cts
10+
resolverRef:
11+
resolver: git
12+
params:
13+
- name: url
14+
value: https://github.com/release-engineering/cts
15+
- name: revision
16+
value: main
17+
- name: pathInRepo
18+
value: .tekton/integration-test-eaas.yaml
19+
contexts:
20+
- name: service-validation
21+
description: |
22+
Tests the CTS container image by:
23+
- Provisioning ephemeral namespace using EaaS
24+
- Deploying PostgreSQL database
25+
- Deploying CTS service with the built image
26+
- Validating API endpoints respond correctly
27+
- Testing database connectivity and migrations

0 commit comments

Comments
 (0)