Skip to content

Commit

Permalink
Add support for deployments.delete endpoint (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattt authored Jul 1, 2024
1 parent 8c277a5 commit 8328597
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
24 changes: 24 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2254,6 +2254,30 @@ func TestUpdateDeployment(t *testing.T) {
}
}

func TestDeleteDeployment(t *testing.T) {
deploymentOwner := "acme"
deploymentName := "existing-deployment"
mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodDelete, r.Method)
assert.Equal(t, fmt.Sprintf("/deployments/%s/%s", deploymentOwner, deploymentName), r.URL.Path)
w.WriteHeader(http.StatusNoContent)
}))
defer mockServer.Close()

client, err := replicate.NewClient(
replicate.WithToken("test-token"),
replicate.WithBaseURL(mockServer.URL),
)
require.NotNil(t, client)
require.NoError(t, err)

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

err = client.DeleteDeployment(ctx, deploymentOwner, deploymentName)
assert.NoError(t, err)
}

func TestDeleteModel(t *testing.T) {
modelName := "replicate"
modelOwner := "hello-world"
Expand Down
10 changes: 10 additions & 0 deletions deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,13 @@ func (c *Client) UpdateDeployment(ctx context.Context, deploymentOwner string, d

return deployment, nil
}

// DeleteDeployment deletes an existing deployment.
func (c *Client) DeleteDeployment(ctx context.Context, deploymentOwner string, deploymentName string) error {
path := fmt.Sprintf("/deployments/%s/%s", deploymentOwner, deploymentName)
err := c.fetch(ctx, http.MethodDelete, path, nil, nil)
if err != nil {
return fmt.Errorf("failed to delete deployment: %w", err)
}
return nil
}

0 comments on commit 8328597

Please sign in to comment.