@@ -5,14 +5,65 @@ import (
55	"github.com/mark3labs/mcp-go/mcp" 
66	corev1 "k8s.io/api/core/v1" 
77	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 
8+ 	"path/filepath" 
9+ 	"runtime" 
810	"sigs.k8s.io/yaml" 
11+ 	"strings" 
912	"testing" 
1013)
1114
15+ func  TestHelmInstall (t  * testing.T ) {
16+ 	testCase (t , func (c  * mcpContext ) {
17+ 		c .withEnvTest ()
18+ 		_ , file , _ , _  :=  runtime .Caller (0 )
19+ 		chartPath  :=  filepath .Join (filepath .Dir (file ), "testdata" , "helm-chart-no-op" )
20+ 		toolResult , err  :=  c .callTool ("helm_install" , map [string ]interface {}{
21+ 			"chart" : chartPath ,
22+ 		})
23+ 		t .Run ("helm_install with local chart and no release name, returns installed chart" , func (t  * testing.T ) {
24+ 			if  err  !=  nil  {
25+ 				t .Fatalf ("call tool failed %v" , err )
26+ 			}
27+ 			if  toolResult .IsError  {
28+ 				t .Fatalf ("call tool failed" )
29+ 			}
30+ 			var  decoded  []map [string ]interface {}
31+ 			err  =  yaml .Unmarshal ([]byte (toolResult .Content [0 ].(mcp.TextContent ).Text ), & decoded )
32+ 			if  err  !=  nil  {
33+ 				t .Fatalf ("invalid tool result content %v" , err )
34+ 			}
35+ 			if  ! strings .HasPrefix (decoded [0 ]["name" ].(string ), "helm-chart-no-op-" ) {
36+ 				t .Fatalf ("invalid helm install name, expected no-op-*, got %v" , decoded [0 ]["name" ])
37+ 			}
38+ 			if  decoded [0 ]["namespace" ] !=  "default"  {
39+ 				t .Fatalf ("invalid helm install namespace, expected default, got %v" , decoded [0 ]["namespace" ])
40+ 			}
41+ 			if  decoded [0 ]["chart" ] !=  "no-op"  {
42+ 				t .Fatalf ("invalid helm install name, expected release name, got empty" )
43+ 			}
44+ 			if  decoded [0 ]["chartVersion" ] !=  "1.33.7"  {
45+ 				t .Fatalf ("invalid helm install version, expected 1.33.7, got empty" )
46+ 			}
47+ 			if  decoded [0 ]["status" ] !=  "deployed"  {
48+ 				t .Fatalf ("invalid helm install status, expected deployed, got %v" , decoded [0 ]["status" ])
49+ 			}
50+ 			if  decoded [0 ]["revision" ] !=  float64 (1 ) {
51+ 				t .Fatalf ("invalid helm install revision, expected 1, got %v" , decoded [0 ]["revision" ])
52+ 			}
53+ 		})
54+ 	})
55+ }
56+ 
1257func  TestHelmList (t  * testing.T ) {
1358	testCase (t , func (c  * mcpContext ) {
1459		c .withEnvTest ()
1560		kc  :=  c .newKubernetesClient ()
61+ 		secrets , err  :=  kc .CoreV1 ().Secrets ("default" ).List (c .ctx , metav1.ListOptions {})
62+ 		for  _ , secret  :=  range  secrets .Items  {
63+ 			if  strings .HasPrefix (secret .Name , "sh.helm.release.v1." ) {
64+ 				_  =  kc .CoreV1 ().Secrets ("default" ).Delete (c .ctx , secret .Name , metav1.DeleteOptions {})
65+ 			}
66+ 		}
1667		_  =  kc .CoreV1 ().Secrets ("default" ).Delete (c .ctx , "release-to-list" , metav1.DeleteOptions {})
1768		toolResult , err  :=  c .callTool ("helm_list" , map [string ]interface {}{})
1869		t .Run ("helm_list with no releases, returns not found" , func (t  * testing.T ) {
@@ -57,8 +108,8 @@ func TestHelmList(t *testing.T) {
57108			if  decoded [0 ]["name" ] !=  "release-to-list"  {
58109				t .Fatalf ("invalid helm list name, expected release-to-list, got %v" , decoded [0 ]["name" ])
59110			}
60- 			if  decoded [0 ]["info"  ].( map [ string ] interface {})[ " status"!=  "deployed"  {
61- 				t .Fatalf ("invalid helm list status, expected deployed, got %v" , decoded [0 ]["info"  ].( map [ string ] interface {})[ " status"
111+ 			if  decoded [0 ]["status" ] !=  "deployed"  {
112+ 				t .Fatalf ("invalid helm list status, expected deployed, got %v" , decoded [0 ]["status" ])
62113			}
63114		})
64115		toolResult , err  =  c .callTool ("helm_list" , map [string ]interface {}{"namespace" : "ns-1" })
@@ -92,8 +143,8 @@ func TestHelmList(t *testing.T) {
92143			if  decoded [0 ]["name" ] !=  "release-to-list"  {
93144				t .Fatalf ("invalid helm list name, expected release-to-list, got %v" , decoded [0 ]["name" ])
94145			}
95- 			if  decoded [0 ]["info"  ].( map [ string ] interface {})[ " status"!=  "deployed"  {
96- 				t .Fatalf ("invalid helm list status, expected deployed, got %v" , decoded [0 ]["info"  ].( map [ string ] interface {})[ " status"
146+ 			if  decoded [0 ]["status" ] !=  "deployed"  {
147+ 				t .Fatalf ("invalid helm list status, expected deployed, got %v" , decoded [0 ]["status" ])
97148			}
98149		})
99150	})
0 commit comments