@@ -5,14 +5,65 @@ import (
5
5
"github.com/mark3labs/mcp-go/mcp"
6
6
corev1 "k8s.io/api/core/v1"
7
7
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8
+ "path/filepath"
9
+ "runtime"
8
10
"sigs.k8s.io/yaml"
11
+ "strings"
9
12
"testing"
10
13
)
11
14
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
+
12
57
func TestHelmList (t * testing.T ) {
13
58
testCase (t , func (c * mcpContext ) {
14
59
c .withEnvTest ()
15
60
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
+ }
16
67
_ = kc .CoreV1 ().Secrets ("default" ).Delete (c .ctx , "release-to-list" , metav1.DeleteOptions {})
17
68
toolResult , err := c .callTool ("helm_list" , map [string ]interface {}{})
18
69
t .Run ("helm_list with no releases, returns not found" , func (t * testing.T ) {
@@ -57,8 +108,8 @@ func TestHelmList(t *testing.T) {
57
108
if decoded [0 ]["name" ] != "release-to-list" {
58
109
t .Fatalf ("invalid helm list name, expected release-to-list, got %v" , decoded [0 ]["name" ])
59
110
}
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" ])
62
113
}
63
114
})
64
115
toolResult , err = c .callTool ("helm_list" , map [string ]interface {}{"namespace" : "ns-1" })
@@ -92,8 +143,8 @@ func TestHelmList(t *testing.T) {
92
143
if decoded [0 ]["name" ] != "release-to-list" {
93
144
t .Fatalf ("invalid helm list name, expected release-to-list, got %v" , decoded [0 ]["name" ])
94
145
}
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" ])
97
148
}
98
149
})
99
150
})
0 commit comments