44 "context"
55 "net/http"
66 "os"
7- "path/filepath"
87 "runtime"
98 "testing"
109 "time"
@@ -15,38 +14,47 @@ import (
1514 "github.com/stretchr/testify/suite"
1615)
1716
18- func TestWatchKubeConfig (t * testing.T ) {
17+ type WatchKubeConfigSuite struct {
18+ BaseMcpSuite
19+ }
20+
21+ func (s * WatchKubeConfigSuite ) SetupTest () {
22+ s .BaseMcpSuite .SetupTest ()
23+ kubeconfig := test .KubeConfigFake ()
24+ s .Cfg .KubeConfig = test .KubeconfigFile (s .T (), kubeconfig )
25+ }
26+
27+ func (s * WatchKubeConfigSuite ) TestNotifiesToolsChange () {
1928 if runtime .GOOS != "linux" && runtime .GOOS != "darwin" {
20- t .Skip ("Skipping test on non-Unix-like platforms" )
29+ s . T () .Skip ("Skipping test on non-Unix-like platforms" )
2130 }
22- testCase (t , func (c * mcpContext ) {
23- // Given
24- withTimeout , cancel := context .WithTimeout (c .ctx , 5 * time .Second )
25- defer cancel ()
26- var notification * mcp.JSONRPCNotification
27- c .mcpClient .OnNotification (func (n mcp.JSONRPCNotification ) {
28- notification = & n
29- })
30- // When
31- f , _ := os .OpenFile (filepath .Join (c .tempDir , "config" ), os .O_APPEND | os .O_WRONLY , 0644 )
32- _ , _ = f .WriteString ("\n " )
33- for notification == nil {
34- select {
35- case <- withTimeout .Done ():
36- default :
37- time .Sleep (100 * time .Millisecond )
38- }
39- }
40- // Then
41- t .Run ("WatchKubeConfig notifies tools change" , func (t * testing.T ) {
42- if notification == nil {
43- t .Fatalf ("WatchKubeConfig did not notify" )
44- }
45- if notification .Method != "notifications/tools/list_changed" {
46- t .Fatalf ("WatchKubeConfig did not notify tools change, got %s" , notification .Method )
47- }
48- })
31+ // Given
32+ s .InitMcpClient ()
33+ withTimeout , cancel := context .WithTimeout (s .T ().Context (), 5 * time .Second )
34+ defer cancel ()
35+ var notification * mcp.JSONRPCNotification
36+ s .OnNotification (func (n mcp.JSONRPCNotification ) {
37+ notification = & n
4938 })
39+ // When
40+ f , _ := os .OpenFile (s .Cfg .KubeConfig , os .O_APPEND | os .O_WRONLY , 0644 )
41+ _ , _ = f .WriteString ("\n " )
42+ _ = f .Close ()
43+ for notification == nil {
44+ select {
45+ case <- withTimeout .Done ():
46+ s .FailNow ("timeout waiting for WatchKubeConfig notification" )
47+ default :
48+ time .Sleep (100 * time .Millisecond )
49+ }
50+ }
51+ // Then
52+ s .NotNil (notification , "WatchKubeConfig did not notify" )
53+ s .Equal ("notifications/tools/list_changed" , notification .Method , "WatchKubeConfig did not notify tools change" )
54+ }
55+
56+ func TestWatchKubeConfig (t * testing.T ) {
57+ suite .Run (t , new (WatchKubeConfigSuite ))
5058}
5159
5260type McpHeadersSuite struct {
0 commit comments