|
| 1 | +package mcp |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/mark3labs/mcp-go/mcp" |
| 5 | + "slices" |
| 6 | + "strings" |
| 7 | + "testing" |
| 8 | +) |
| 9 | + |
| 10 | +func TestFullProfileTools(t *testing.T) { |
| 11 | + expectedNames := []string{ |
| 12 | + "configuration_view", |
| 13 | + "events_list", |
| 14 | + "helm_install", |
| 15 | + "helm_list", |
| 16 | + "helm_uninstall", |
| 17 | + "namespaces_list", |
| 18 | + "pods_list", |
| 19 | + "pods_list_in_namespace", |
| 20 | + "pods_get", |
| 21 | + "pods_delete", |
| 22 | + "pods_log", |
| 23 | + "pods_run", |
| 24 | + "pods_exec", |
| 25 | + "resources_list", |
| 26 | + "resources_get", |
| 27 | + "resources_create_or_update", |
| 28 | + "resources_delete", |
| 29 | + } |
| 30 | + mcpCtx := &mcpContext{profile: &FullProfile{}} |
| 31 | + testCaseWithContext(t, mcpCtx, func(c *mcpContext) { |
| 32 | + tools, err := c.mcpClient.ListTools(c.ctx, mcp.ListToolsRequest{}) |
| 33 | + t.Run("ListTools returns tools", func(t *testing.T) { |
| 34 | + if err != nil { |
| 35 | + t.Fatalf("call ListTools failed %v", err) |
| 36 | + return |
| 37 | + } |
| 38 | + }) |
| 39 | + nameSet := make(map[string]bool) |
| 40 | + for _, tool := range tools.Tools { |
| 41 | + nameSet[tool.Name] = true |
| 42 | + } |
| 43 | + for _, name := range expectedNames { |
| 44 | + t.Run("ListTools has "+name+" tool", func(t *testing.T) { |
| 45 | + if nameSet[name] != true { |
| 46 | + t.Fatalf("tool %s not found", name) |
| 47 | + return |
| 48 | + } |
| 49 | + }) |
| 50 | + } |
| 51 | + }) |
| 52 | +} |
| 53 | + |
| 54 | +func TestFullProfileToolsInOpenShift(t *testing.T) { |
| 55 | + var after func(c *mcpContext) |
| 56 | + before := func(c *mcpContext) { |
| 57 | + cleanCrds := c.inOpenShift() |
| 58 | + after = func(_ *mcpContext) { |
| 59 | + cleanCrds() |
| 60 | + } |
| 61 | + } |
| 62 | + mcpCtx := &mcpContext{ |
| 63 | + profile: &FullProfile{}, |
| 64 | + before: &before, |
| 65 | + after: &after, |
| 66 | + } |
| 67 | + testCaseWithContext(t, mcpCtx, func(c *mcpContext) { |
| 68 | + tools, err := c.mcpClient.ListTools(c.ctx, mcp.ListToolsRequest{}) |
| 69 | + t.Run("ListTools returns tools", func(t *testing.T) { |
| 70 | + if err != nil { |
| 71 | + t.Fatalf("call ListTools failed %v", err) |
| 72 | + } |
| 73 | + }) |
| 74 | + t.Run("ListTools contains projects_list tool", func(t *testing.T) { |
| 75 | + idx := slices.IndexFunc(tools.Tools, func(tool mcp.Tool) bool { |
| 76 | + return tool.Name == "projects_list" |
| 77 | + }) |
| 78 | + if idx == -1 { |
| 79 | + t.Fatalf("tool projects_list not found") |
| 80 | + } |
| 81 | + }) |
| 82 | + t.Run("ListTools has resources_list tool with OpenShift hint", func(t *testing.T) { |
| 83 | + idx := slices.IndexFunc(tools.Tools, func(tool mcp.Tool) bool { |
| 84 | + return tool.Name == "resources_list" |
| 85 | + }) |
| 86 | + if idx == -1 { |
| 87 | + t.Fatalf("tool resources_list not found") |
| 88 | + } |
| 89 | + if !strings.Contains(tools.Tools[idx].Description, ", route.openshift.io/v1 Route") { |
| 90 | + t.Fatalf("tool resources_list does not have OpenShift hint, got %s", tools.Tools[9].Description) |
| 91 | + } |
| 92 | + }) |
| 93 | + }) |
| 94 | +} |
0 commit comments