hash-of-wisdom/test/integration/helpers_test.go

57 lines
1.4 KiB
Go
Raw Normal View History

2025-08-23 14:50:15 +03:00
package integration
import (
"context"
"testing"
"time"
"hash-of-wisdom/internal/lib/sl"
"hash-of-wisdom/internal/pow/challenge"
"hash-of-wisdom/internal/quotes"
"hash-of-wisdom/internal/server"
"hash-of-wisdom/internal/service"
"github.com/stretchr/testify/require"
)
// testQuoteService provides static quotes for testing
type testQuoteService struct{}
func (s *testQuoteService) GetRandomQuote(ctx context.Context) (*quotes.Quote, error) {
return &quotes.Quote{
Text: "Test quote for integration testing",
Author: "Test Author",
}, nil
}
func setupTestServerWithConfig(t *testing.T, serverConfig *server.Config) *server.TCPServer {
// Create test components
challengeConfig := challenge.TestConfig()
generator := challenge.NewGenerator(challengeConfig)
verifier := challenge.NewVerifier(challengeConfig)
// Create a simple test quote service
quoteService := &testQuoteService{}
// Wire up service
genAdapter := service.NewGeneratorAdapter(generator)
wisdomService := service.NewWisdomService(genAdapter, verifier, quoteService)
// Create server with custom config using functional options
logger := sl.NewMockLogger()
srv := server.NewTCPServer(wisdomService, serverConfig,
server.WithLogger(logger))
// Start server
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
err := srv.Start(ctx)
require.NoError(t, err)
// Give server time to start
time.Sleep(100 * time.Millisecond)
return srv
}