MCPcopy Create free account
hub / github.com/astercloud/aster / setupTestServer

Function setupTestServer

server/server_test.go:21–79  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

19)
20
21func setupTestServer(t *testing.T) (*Server, func()) {
22 // Create test store
23 st, err := store.NewJSONStore(t.TempDir())
24 require.NoError(t, err)
25
26 // Create dependencies
27 toolRegistry := tools.NewRegistry()
28 sandboxFactory := sandbox.NewFactory()
29 providerFactory := NewMockProviderFactory()
30 templateRegistry := agent.NewTemplateRegistry()
31
32 // Register test templates
33 chatTemplate := &types.AgentTemplateDefinition{
34 ID: "chat",
35 Version: "1.0.0",
36 SystemPrompt: "You are a helpful assistant.",
37 Model: "test-model",
38 Tools: []string{},
39 }
40 templateRegistry.Register(chatTemplate)
41
42 defaultModel := &types.ModelConfig{
43 Provider: "mock",
44 Model: "test-model",
45 }
46 routes := []router.StaticRouteEntry{
47 {Task: "chat", Priority: router.PriorityQuality, Model: defaultModel},
48 }
49 rt := router.NewStaticRouter(defaultModel, routes)
50
51 agentDeps := &agent.Dependencies{
52 Store: st,
53 ToolRegistry: toolRegistry,
54 SandboxFactory: sandboxFactory,
55 ProviderFactory: providerFactory,
56 TemplateRegistry: templateRegistry,
57 Router: rt,
58 }
59
60 deps := &Dependencies{
61 Store: st,
62 AgentDeps: agentDeps,
63 }
64
65 // Create server with test config
66 config := DefaultConfig()
67 config.Auth.APIKey.Enabled = false // Disable auth for tests
68
69 srv, err := New(config, deps)
70 require.NoError(t, err)
71
72 cleanup := func() {
73 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
74 defer cancel()
75 _ = srv.Stop(ctx)
76 }
77
78 return srv, cleanup

Callers 15

TestToolHandlersFunction · 0.85
TestMiddlewareHandlersFunction · 0.85
TestTelemetryHandlersFunction · 0.85
TestSystemHandlersFunction · 0.85
TestMCPHandlersFunction · 0.85
TestEvalHandlersFunction · 0.85
TestValidationErrorsFunction · 0.85
TestQueryParametersFunction · 0.85
TestResponseFormatFunction · 0.85
TestServerHealthFunction · 0.85
TestServerMetricsFunction · 0.85

Calls 12

RegisterMethod · 0.95
NewJSONStoreFunction · 0.92
NewRegistryFunction · 0.92
NewFactoryFunction · 0.92
NewTemplateRegistryFunction · 0.92
NewStaticRouterFunction · 0.92
cancelFunction · 0.85
NewMockProviderFactoryFunction · 0.70
DefaultConfigFunction · 0.70
NewFunction · 0.70
StopMethod · 0.65
WithTimeoutMethod · 0.45

Tested by

no test coverage detected