57 lines
1.4 KiB
Go
57 lines
1.4 KiB
Go
|
|
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 "es.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
|
||
|
|
}
|