mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-13 23:11:40 +00:00
fix/mcp resource deletion
This commit is contained in:
parent
cfb0853c5b
commit
98fb823dc2
2 changed files with 49 additions and 1 deletions
|
|
@ -270,7 +270,7 @@ func resourceLiteLLMMCPServerDelete(d *schema.ResourceData, m interface{}) error
|
|||
defer resp.Body.Close()
|
||||
|
||||
// For delete operations, we expect a simple string response
|
||||
if resp.StatusCode != 200 {
|
||||
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||
return fmt.Errorf("failed to delete MCP server: unexpected status code %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,59 @@
|
|||
package litellm
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func TestMCPServerDeleteAcceptsFullSuccessRange(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
statusCode int
|
||||
wantErr bool
|
||||
}{
|
||||
{name: "200 OK", statusCode: http.StatusOK, wantErr: false},
|
||||
{name: "202 Accepted", statusCode: http.StatusAccepted, wantErr: false},
|
||||
{name: "404 Not Found", statusCode: http.StatusNotFound, wantErr: true},
|
||||
{name: "500 Internal Server Error", statusCode: http.StatusInternalServerError, wantErr: true},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(tt.statusCode)
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
d := schema.TestResourceDataRaw(t, resourceLiteLLMMCPServer().Schema, map[string]interface{}{
|
||||
"server_name": "gh",
|
||||
"transport": "stdio",
|
||||
"command": "npx",
|
||||
})
|
||||
d.SetId("srv-1")
|
||||
|
||||
client := NewClient(srv.URL, "test-key", true)
|
||||
err := resourceLiteLLMMCPServerDelete(d, client)
|
||||
|
||||
if tt.wantErr {
|
||||
if err == nil {
|
||||
t.Fatalf("resourceLiteLLMMCPServerDelete returned no error for status %d", tt.statusCode)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("resourceLiteLLMMCPServerDelete returned unexpected error: %v", err)
|
||||
}
|
||||
if d.Id() != "" {
|
||||
t.Errorf("resource ID not cleared after successful delete, got %q", d.Id())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMCPServerReadDoesNotPersistServerEnv(t *testing.T) {
|
||||
d := schema.TestResourceDataRaw(t, resourceLiteLLMMCPServer().Schema, map[string]interface{}{
|
||||
"server_name": "gh",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue