Skip to content

Commit 234a559

Browse files
tiwilliaclaude
andcommitted
Add comprehensive test coverage reporting and documentation enhancements
- Add code coverage reporting to unit and integration tests - Enhance testing documentation with coverage details - Fix core library dependency issue by removing invalid replace directive 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 0350a34 commit 234a559

File tree

10 files changed

+622
-17
lines changed

10 files changed

+622
-17
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
/config/master.key
2929

3030
/coverage
31+
coverage-*.out
32+
coverage-*.html
3133

3234
# Ignore built binaries
3335
/trex

Makefile

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ jwks_url:=https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-con
6060
# Test output files
6161
unit_test_json_output ?= ${PWD}/unit-test-results.json
6262
integration_test_json_output ?= ${PWD}/integration-test-results.json
63+
unit_coverage_output ?= ${PWD}/coverage-unit.out
64+
integration_coverage_output ?= ${PWD}/coverage-integration.out
6365

6466
# Prints a list of useful targets.
6567
help:
@@ -74,6 +76,8 @@ help:
7476
@echo "make run/docs run swagger and host the api spec"
7577
@echo "make test run unit tests"
7678
@echo "make test-integration run integration tests"
79+
@echo "make coverage-html generate HTML coverage reports"
80+
@echo "make coverage-func show function-level coverage summary"
7781
@echo "make generate generate openapi modules"
7882
@echo "make image build docker image"
7983
@echo "make push push docker image"
@@ -171,7 +175,7 @@ install: check-gopath
171175
# Examples:
172176
# make test TESTFLAGS="-run TestSomething"
173177
test: install
174-
OCM_ENV=testing gotestsum --format short-verbose -- -p 1 -v $(TESTFLAGS) \
178+
OCM_ENV=testing gotestsum --format short-verbose -- -p 1 -v -coverprofile=$(unit_coverage_output) -coverpkg=./... $(TESTFLAGS) \
175179
./pkg/... \
176180
./cmd/...
177181
.PHONY: test
@@ -185,7 +189,7 @@ test: install
185189
# make test-unit-json TESTFLAGS="-run TestSomething"
186190
ci-test-unit: install
187191
@echo $(db_password) > ${PWD}/secrets/db.password
188-
OCM_ENV=testing gotestsum --jsonfile-timing-events=$(unit_test_json_output) --format short-verbose -- -p 1 -v $(TESTFLAGS) \
192+
OCM_ENV=testing gotestsum --jsonfile-timing-events=$(unit_test_json_output) --format short-verbose -- -p 1 -v -coverprofile=$(unit_coverage_output) -coverpkg=./... $(TESTFLAGS) \
189193
./pkg/... \
190194
./cmd/...
191195
.PHONY: ci-test-unit
@@ -202,7 +206,7 @@ ci-test-unit: install
202206
# make test-integration TESTFLAGS="-short" skips long-run tests
203207
ci-test-integration: install
204208
@echo $(db_password) > ${PWD}/secrets/db.password
205-
OCM_ENV=testing gotestsum --jsonfile-timing-events=$(integration_test_json_output) --format $(TEST_SUMMARY_FORMAT) -- -p 1 -ldflags -s -v -timeout 1h $(TESTFLAGS) \
209+
OCM_ENV=testing gotestsum --jsonfile-timing-events=$(integration_test_json_output) --format $(TEST_SUMMARY_FORMAT) -- -p 1 -ldflags -s -v -timeout 1h -coverprofile=$(integration_coverage_output) -coverpkg=./... $(TESTFLAGS) \
206210
./test/integration
207211
.PHONY: ci-test-integration
208212

@@ -218,7 +222,7 @@ ci-test-integration: install
218222
# make test-integration TESTFLAGS="-short" skips long-run tests
219223
test-integration: install
220224
@echo $(db_password) > ${PWD}/secrets/db.password
221-
OCM_ENV=testing gotestsum --format $(TEST_SUMMARY_FORMAT) -- -p 1 -ldflags -s -v -timeout 1h $(TESTFLAGS) \
225+
OCM_ENV=testing gotestsum --format $(TEST_SUMMARY_FORMAT) -- -p 1 -ldflags -s -v -timeout 1h -coverprofile=$(integration_coverage_output) -coverpkg=./... $(TESTFLAGS) \
222226
./test/integration
223227
.PHONY: test-integration
224228

@@ -242,12 +246,37 @@ run/docs:
242246
docker run -d -p 80:8080 -e SWAGGER_JSON=/trex.yaml -v $(PWD)/openapi/rh-trex.yaml:/trex.yaml swaggerapi/swagger-ui
243247
.PHONY: run/docs
244248

249+
# Run coverage reports
250+
coverage-html:
251+
@if [ -f $(unit_coverage_output) ]; then \
252+
go tool cover -html=$(unit_coverage_output) -o coverage-unit.html; \
253+
echo "Unit test coverage report generated: coverage-unit.html"; \
254+
fi
255+
@if [ -f $(integration_coverage_output) ]; then \
256+
go tool cover -html=$(integration_coverage_output) -o coverage-integration.html; \
257+
echo "Integration test coverage report generated: coverage-integration.html"; \
258+
fi
259+
.PHONY: coverage-html
260+
261+
coverage-func:
262+
@if [ -f $(unit_coverage_output) ]; then \
263+
echo "=== Unit Test Coverage ==="; \
264+
go tool cover -func=$(unit_coverage_output); \
265+
fi
266+
@if [ -f $(integration_coverage_output) ]; then \
267+
echo "=== Integration Test Coverage ==="; \
268+
go tool cover -func=$(integration_coverage_output); \
269+
fi
270+
.PHONY: coverage-func
271+
245272
# Delete temporary files
246273
clean:
247274
rm -rf \
248275
$(binary) \
249276
templates/*-template.json \
250277
data/generated/openapi/*.json \
278+
coverage-*.out \
279+
coverage-*.html \
251280
.PHONY: clean
252281

253282
.PHONY: cmds

docs/framework-development/README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,15 @@ make test
6666
## Testing Framework Changes
6767

6868
```bash
69-
# Unit tests
69+
# Unit tests with coverage
7070
make test
7171

72-
# Integration tests
72+
# Integration tests with coverage
7373
make test-integration
7474

75+
# Generate coverage reports
76+
make coverage-html
77+
7578
# Test generator
7679
go run ./scripts/generate/main.go --kind TestEntity
7780
make generate
@@ -81,6 +84,8 @@ make test
8184
go run ./scripts/clone/main.go --name test-clone --destination /tmp/test
8285
```
8386

87+
For detailed testing information, see the **[Testing Guide](../reference/testing-guide.md)**.
88+
8489
## Code Style
8590

8691
- **Semantic naming** - Clear, purpose-driven names

docs/operations/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ make binary # Build TRex
2323
make run # Start the service
2424

2525
# Development workflow
26-
make test # Run unit tests
27-
make test-integration # Run integration tests
26+
make test # Run unit tests with coverage
27+
make test-integration # Run integration tests with coverage
28+
make coverage-html # Generate coverage reports
2829
make db/teardown # Clean up database
2930
```
3031

docs/operations/local-development.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,21 @@ rh-trex=# \dt
6363
## Testing
6464

6565
```shell
66-
# Run unit tests
66+
# Run unit tests with coverage
6767
make test
6868

69-
# Run integration tests
69+
# Run integration tests with coverage
7070
make test-integration
71+
72+
# Generate HTML coverage reports
73+
make coverage-html
74+
75+
# View coverage summary in terminal
76+
make coverage-func
7177
```
7278

79+
For comprehensive testing documentation, see the **[Testing Guide](../reference/testing-guide.md)**.
80+
7381
## Running the Service
7482

7583
```shell

docs/reference/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Complete technical reference for TRex APIs, configuration, and commands.
1111

1212
- **[Configuration Options](configuration-options.md)** - All environment variables and settings
1313
- **[Command Reference](command-reference.md)** - CLI commands and options
14+
- **[Testing Guide](testing-guide.md)** - Comprehensive testing and code coverage documentation
1415

1516
## Technical Specifications
1617

docs/reference/command-reference.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,17 @@ make db/migrate # Equivalent to: ./trex migrate
5353

5454
### Testing Commands
5555
```bash
56-
# Run unit tests
56+
# Run unit tests (with coverage)
5757
make test
5858

59-
# Run integration tests
59+
# Run integration tests (with coverage)
6060
make test-integration
6161

62-
# Run tests with coverage
63-
make test-coverage
62+
# Generate HTML coverage reports
63+
make coverage-html
64+
65+
# Show function-level coverage summary
66+
make coverage-func
6467

6568
# Run CI tests (JSON output)
6669
make ci-test-unit

0 commit comments

Comments
 (0)