Skip to content

Commit 7c22861

Browse files
committed
feat: Add integration tests for HTTP, WebSocket, Redis, and PostgreSQL handlers
- Implemented integration tests for various HTTP endpoints including user creation, retrieval, and health checks. - Added WebSocket tests for connection, message sending, and receiving. - Created Redis tests for key-value operations, TTL verification, and hash operations. - Developed PostgreSQL tests for data insertion, querying, and raw SQL execution. - Introduced Kafka feature tests for topic creation and message publishing. - Established shell command tests for executing commands and checking outputs. - Configured a YAML file for test settings, including container setups for PostgreSQL and Redis. - Added coverage for user workflows and error handling scenarios.
1 parent 1352b66 commit 7c22861

24 files changed

+2166
-307
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
bin
2+
coverage-*
3+
coverage/

Makefile

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: build test lint clean install run help
1+
.PHONY: build test lint clean install run help integration-test integration-test-coverage coverage-all
22

33
# Build variables
44
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
@@ -83,7 +83,8 @@ deps:
8383
clean:
8484
@echo "Cleaning..."
8585
@rm -rf ./bin
86-
@rm -f coverage.out coverage.html
86+
@rm -rf ./coverage ./coverage-merged
87+
@rm -f coverage.out coverage.html coverage-integration.out coverage-integration.html coverage-all.out coverage-all.html
8788

8889
## run: Run tomato with example config
8990
run: build
@@ -99,6 +100,36 @@ docker-build:
99100
docker build -t tomatool/tomato:$(VERSION) .
100101
docker tag tomatool/tomato:$(VERSION) tomatool/tomato:latest
101102

103+
## integration-test: Run integration tests using tomato to test itself
104+
integration-test: build
105+
@echo "Running integration tests..."
106+
$(BINARY_PATH) run -c ./tests/tomato.yml
107+
108+
## integration-test-coverage: Run integration tests with coverage (Cloudflare technique)
109+
integration-test-coverage:
110+
@echo "Building coverage-instrumented binary..."
111+
@mkdir -p ./bin
112+
$(GOCMD) build -cover -covermode=atomic -coverpkg=./... $(LDFLAGS) -o ./bin/tomato-coverage .
113+
@echo "Running integration tests with coverage..."
114+
@mkdir -p ./coverage
115+
GOCOVERDIR=./coverage ./bin/tomato-coverage run -c ./tests/tomato.yml || true
116+
@echo "Converting coverage data..."
117+
$(GOCMD) tool covdata textfmt -i=./coverage -o=coverage-integration.out
118+
@echo "Generating coverage report..."
119+
$(GOCMD) tool cover -html=coverage-integration.out -o coverage-integration.html
120+
@echo "Integration coverage report: coverage-integration.html"
121+
122+
## coverage-all: Run both unit tests and integration tests with combined coverage
123+
coverage-all: test-coverage integration-test-coverage
124+
@echo "Merging coverage reports..."
125+
@if [ -f coverage.out ] && [ -f coverage-integration.out ]; then \
126+
$(GOCMD) tool covdata merge -i=./coverage -o=./coverage-merged 2>/dev/null || true; \
127+
cat coverage.out > coverage-all.out; \
128+
tail -n +2 coverage-integration.out >> coverage-all.out; \
129+
$(GOCMD) tool cover -html=coverage-all.out -o coverage-all.html; \
130+
echo "Combined coverage report: coverage-all.html"; \
131+
fi
132+
102133
## release: Create a release build for multiple platforms
103134
release: clean
104135
@echo "Building releases..."

command/docs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func collectStepCategories() []handler.StepCategory {
6464
categories := []handler.StepCategory{}
6565

6666
// HTTP steps
67-
httpHandler, _ := handler.NewHTTP("api", handler.DummyConfig(), nil)
67+
httpHandler, _ := handler.NewHTTPClient("api", handler.DummyConfig(), nil)
6868
categories = append(categories, httpHandler.Steps())
6969

7070
// Redis steps
@@ -80,7 +80,7 @@ func collectStepCategories() []handler.StepCategory {
8080
categories = append(categories, kafkaHandler.Steps())
8181

8282
// WebSocket steps
83-
wsHandler, _ := handler.NewWebSocket("ws", handler.DummyConfig(), nil)
83+
wsHandler, _ := handler.NewWebSocketClient("ws", handler.DummyConfig(), nil)
8484
categories = append(categories, wsHandler.Steps())
8585

8686
// Shell steps

internal/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ type Resource struct {
122122
Type string `yaml:"type"`
123123
Container string `yaml:"container"`
124124
Options map[string]any `yaml:"options"`
125+
// Reset configuration
126+
Reset *bool `yaml:"reset,omitempty"` // nil = use global setting, true = always reset, false = never reset
125127
// Database specific
126128
Database string `yaml:"database,omitempty"`
127129
// HTTP specific

internal/handler/handler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ type CacheStore interface {
5252
Exists(ctx context.Context, key string) (bool, error)
5353
}
5454

55-
// WebSocketClient is implemented by handlers that can handle WebSocket connections
56-
type WebSocketClient interface {
55+
// WebSocketClientInterface is implemented by handlers that can handle WebSocket connections
56+
type WebSocketClientInterface interface {
5757
Connect(ctx context.Context, headers map[string]string) error
5858
Send(ctx context.Context, message []byte) error
5959
Receive(ctx context.Context, timeout int) ([]byte, error)

0 commit comments

Comments
 (0)