Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions pkg/mcp/tools_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,68 @@ import (
"knative.dev/func/pkg/mcp/mock"
)

// TestTool_Delete_Readonly ensures the delete tool returns an error when the server is in readonly mode.
func TestTool_Delete_Readonly(t *testing.T) {
client, _, err := newTestPairWithReadonly(t, true)
if err != nil {
t.Fatal(err)
}

result, err := client.CallTool(t.Context(), &mcp.CallToolParams{
Name: "delete",
Arguments: map[string]any{"name": "my-function"},
})
if err != nil {
t.Fatal(err)
}
if !result.IsError {
t.Fatal("expected error result for readonly server, got success")
}
}

// TestTool_Delete_BothPathAndName ensures the delete tool returns a validation error
// when both path and name are provided simultaneously.
func TestTool_Delete_BothPathAndName(t *testing.T) {
client, _, err := newTestPair(t)
if err != nil {
t.Fatal(err)
}

result, err := client.CallTool(t.Context(), &mcp.CallToolParams{
Name: "delete",
Arguments: map[string]any{
"path": "/some/path",
"name": "my-function",
},
})
if err != nil {
t.Fatal(err)
}
if !result.IsError {
t.Fatal("expected error result when both path and name are provided, got success")
}
}

// TestTool_Delete_NeitherPathNorName ensures the delete tool returns a validation error
// when neither path nor name is provided.
func TestTool_Delete_NeitherPathNorName(t *testing.T) {
client, _, err := newTestPair(t)
if err != nil {
t.Fatal(err)
}

result, err := client.CallTool(t.Context(), &mcp.CallToolParams{
Name: "delete",
Arguments: map[string]any{},
})
if err != nil {
t.Fatal(err)
}
if !result.IsError {
t.Fatal("expected error result when neither path nor name is provided, got success")
}
}

// TestTool_Delete_Args ensures the delete tool executes with all arguments passed correctly.
func TestTool_Delete_Args(t *testing.T) {
// Test data - defined once and used for both input and validation
Expand Down
19 changes: 19 additions & 0 deletions pkg/mcp/tools_deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,25 @@ import (
"knative.dev/func/pkg/mcp/mock"
)

// TestTool_Deploy_Readonly ensures the deploy tool returns an error when the server is in readonly mode.
func TestTool_Deploy_Readonly(t *testing.T) {
client, _, err := newTestPairWithReadonly(t, true)
if err != nil {
t.Fatal(err)
}

result, err := client.CallTool(t.Context(), &mcp.CallToolParams{
Name: "deploy",
Arguments: map[string]any{"path": "."},
})
if err != nil {
t.Fatal(err)
}
if !result.IsError {
t.Fatal("expected error result for readonly server, got success")
}
}

// TestTool_Deploy_Args ensures the deploy tool executes with all arguments passed correctly.
func TestTool_Deploy_Args(t *testing.T) {
// Test data - defined once and used for both input and validation
Expand Down
Loading