@@ -30,9 +30,9 @@ func TestPodsExec(t *testing.T) {
3030				_ , _  =  w .Write ([]byte (err .Error ()))
3131				return 
3232			}
33- 			defer  ctx . conn .Close ()
34- 			_ , _  =  io .WriteString (ctx .stdoutStream , strings .Join (req .URL .Query ()["command" ], " " ))
35- 			_ , _  =  io .WriteString (ctx .stdoutStream , "\n total 0 \n " )
33+ 			defer  func ( conn  io. Closer ) {  _   =   conn .Close () }( ctx . conn )
34+ 			_ , _  =  io .WriteString (ctx .stdoutStream , "command:" + strings .Join (req .URL .Query ()["command" ], " " )+ " \n " 
35+ 			_ , _  =  io .WriteString (ctx .stdoutStream , "container:"  + strings . Join ( req . URL . Query ()[ "container" ],  " " ) + " \n "
3636		}))
3737		mockServer .Handle (http .HandlerFunc (func (w  http.ResponseWriter , req  * http.Request ) {
3838			if  req .URL .Path  !=  "/api/v1/namespaces/default/pods/pod-to-exec"  {
@@ -46,20 +46,55 @@ func TestPodsExec(t *testing.T) {
4646				Spec : v1.PodSpec {Containers : []v1.Container {{Name : "container-to-exec" }}},
4747			})
4848		}))
49- 		toolResult , err  :=  c .callTool ("pods_exec" , map [string ]interface {}{
49+ 		podsExecNilNamespace , err  :=  c .callTool ("pods_exec" , map [string ]interface {}{
50+ 			"name" :    "pod-to-exec" ,
51+ 			"command" : []interface {}{"ls" , "-l" },
52+ 		})
53+ 		t .Run ("pods_exec with name and nil namespace returns command output" , func (t  * testing.T ) {
54+ 			if  err  !=  nil  {
55+ 				t .Fatalf ("call tool failed %v" , err )
56+ 			}
57+ 			if  podsExecNilNamespace .IsError  {
58+ 				t .Fatalf ("call tool failed" )
59+ 			}
60+ 			if  ! strings .Contains (podsExecNilNamespace .Content [0 ].(mcp.TextContent ).Text , "command:ls -l\n " ) {
61+ 				t .Errorf ("unexpected result %v" , podsExecNilNamespace .Content [0 ].(mcp.TextContent ).Text )
62+ 			}
63+ 		})
64+ 		podsExecInNamespace , err  :=  c .callTool ("pods_exec" , map [string ]interface {}{
65+ 			"namespace" : "default" ,
66+ 			"name" :      "pod-to-exec" ,
67+ 			"command" :   []interface {}{"ls" , "-l" },
68+ 		})
69+ 		t .Run ("pods_exec with name and namespace returns command output" , func (t  * testing.T ) {
70+ 			if  err  !=  nil  {
71+ 				t .Fatalf ("call tool failed %v" , err )
72+ 			}
73+ 			if  podsExecInNamespace .IsError  {
74+ 				t .Fatalf ("call tool failed" )
75+ 			}
76+ 			if  ! strings .Contains (podsExecNilNamespace .Content [0 ].(mcp.TextContent ).Text , "command:ls -l\n " ) {
77+ 				t .Errorf ("unexpected result %v" , podsExecInNamespace .Content [0 ].(mcp.TextContent ).Text )
78+ 			}
79+ 		})
80+ 		podsExecInNamespaceAndContainer , err  :=  c .callTool ("pods_exec" , map [string ]interface {}{
5081			"namespace" : "default" ,
5182			"name" :      "pod-to-exec" ,
5283			"command" :   []interface {}{"ls" , "-l" },
84+ 			"container" : "a-specific-container" ,
5385		})
54- 		t .Run ("pods_exec returns command output" , func (t  * testing.T ) {
86+ 		t .Run ("pods_exec with name, namespace, and container  returns command output" , func (t  * testing.T ) {
5587			if  err  !=  nil  {
5688				t .Fatalf ("call tool failed %v" , err )
5789			}
58- 			if  toolResult .IsError  {
90+ 			if  podsExecInNamespaceAndContainer .IsError  {
5991				t .Fatalf ("call tool failed" )
6092			}
61- 			if  toolResult .Content [0 ].(mcp.TextContent ).Text  !=  "ls -l\n total 0\n "  {
62- 				t .Errorf ("unexpected result %v" , toolResult .Content [0 ].(mcp.TextContent ).Text )
93+ 			if  ! strings .Contains (podsExecInNamespaceAndContainer .Content [0 ].(mcp.TextContent ).Text , "command:ls -l\n " ) {
94+ 				t .Errorf ("unexpected result %v" , podsExecInNamespaceAndContainer .Content [0 ].(mcp.TextContent ).Text )
95+ 			}
96+ 			if  ! strings .Contains (podsExecInNamespaceAndContainer .Content [0 ].(mcp.TextContent ).Text , "container:a-specific-container\n " ) {
97+ 				t .Errorf ("expected container name not found %v" , podsExecInNamespaceAndContainer .Content [0 ].(mcp.TextContent ).Text )
6398			}
6499		})
65100
0 commit comments