test: add comprehensive tests for API Gateway implementation

- Add unit tests for gateway service (services/gateway/gateway_test.go)
  - Test gateway creation, route setup, service discovery, and error handling
  - Achieve 67.9% code coverage for gateway service
  - Test all HTTP methods are properly handled
  - Test route matching and 404 handling

- Add tests for API Gateway main entry point (cmd/api-gateway/main_test.go)
  - Test DI container setup and structure
  - Test service instance creation logic
  - Test lifecycle hooks registration

- Add testify dependency for assertions (go.mod)

All tests pass successfully. Proxy forwarding tests are noted for integration
test suite as they require real HTTP connections (per ADR-0028 testing strategy).
This commit is contained in:
2025-11-06 09:52:16 +01:00
parent fbc3fc37e4
commit 260bc07114
2 changed files with 430 additions and 0 deletions

3
go.mod
View File

@@ -33,6 +33,7 @@ require (
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cloudwego/base64x v0.1.6 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.10 // indirect
@@ -70,6 +71,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/common v0.66.1 // indirect
github.com/prometheus/procfs v0.16.1 // indirect
@@ -79,6 +81,7 @@ require (
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.11.1 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.3.0 // indirect