Skip to content

Commit 1764d6a

Browse files
test(tray): add real unit tests for ServerAdapter with mock client
Replace documentation-style tests with 22 actual unit tests that verify adapter behavior through mock dependency injection. Changes include: - Add ClientInterface to enable mock-based testing - Refactor ServerAdapter to depend on interface instead of concrete Client - Add MockClient implementation for controlled test scenarios - Test health data preservation through GetAllServers transformation - Test isServerHealthy helper with all health level and fallback cases - Test GetUpstreamStats correctly uses health.level as source of truth - Test error handling paths for API failures - Add end-to-end health data flow integration test
1 parent cd935b9 commit 1764d6a

2 files changed

Lines changed: 515 additions & 137 deletions

File tree

cmd/mcpproxy-tray/internal/api/adapter.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ import (
1010
internalRuntime "mcpproxy-go/internal/runtime"
1111
)
1212

13+
// ClientInterface defines the methods required by ServerAdapter from the API client.
14+
// This interface allows for testing with mock implementations.
15+
type ClientInterface interface {
16+
GetServers() ([]Server, error)
17+
GetInfo() (map[string]interface{}, error)
18+
EnableServer(serverName string, enabled bool) error
19+
TriggerOAuthLogin(serverName string) error
20+
StatusChannel() <-chan StatusUpdate
21+
}
22+
1323
// isServerHealthy returns true if the server is considered healthy.
1424
// It uses health.level as the source of truth, with a fallback to the legacy
1525
// connected field for backward compatibility when health is nil.
@@ -23,11 +33,11 @@ func isServerHealthy(health *HealthStatus, legacyConnected bool) bool {
2333

2434
// ServerAdapter adapts the API client to the ServerInterface expected by the tray
2535
type ServerAdapter struct {
26-
client *Client
36+
client ClientInterface
2737
}
2838

2939
// NewServerAdapter creates a new server adapter
30-
func NewServerAdapter(client *Client) *ServerAdapter {
40+
func NewServerAdapter(client ClientInterface) *ServerAdapter {
3141
return &ServerAdapter{
3242
client: client,
3343
}

0 commit comments

Comments
 (0)