- Added context-aware server initialization in cmd/server/main.go - Implemented graceful shutdown handling with SIGINT/SIGTERM signals - Added 30-second shutdown timeout for active connections - Updated Greet service to use context.Context as first parameter - Enhanced Zerolog integration with Trace level logging - Added context-aware logging in Greet function calls - Fixed route structure to use /api/v1/greet/* prefix - Updated all handlers and tests to use context - Comprehensive AGENTS.md documentation with verified commands - Added server context management architecture section - Updated API endpoint documentation with working examples Changes: - cmd/server/main.go: Complete rewrite with context and graceful shutdown - pkg/greet/greet.go: Added context parameter and trace logging - pkg/greet/api_v1.go: Updated interface and handlers for context - pkg/greet/greet_test.go: Updated tests to use context - cmd/greet/main.go: Updated CLI to use context - pkg/server/server.go: Trace level config and context logging - AGENTS.md: Comprehensive documentation update - go.mod/go.sum: Added Zerolog dependency All tests passing, server working with graceful shutdown verified.
28 lines
554 B
Go
28 lines
554 B
Go
package greet
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
)
|
|
|
|
func TestService_Greet(t *testing.T) {
|
|
service := NewService()
|
|
tests := []struct {
|
|
name string
|
|
expected string
|
|
}{
|
|
{"", "Hello world!"},
|
|
{"John", "Hello John!"},
|
|
{"Alice", "Hello Alice!"},
|
|
{" ", "Hello !"}, // spaces are not considered empty
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result := service.Greet(context.Background(), tt.name)
|
|
if result != tt.expected {
|
|
t.Errorf("Greet(%q) = %q, want %q", tt.name, result, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
} |