Skip to content

Commit

Permalink
Support deleting namespaced Workers in DeleteWorker
Browse files Browse the repository at this point in the history
  • Loading branch information
WalshyDev committed Apr 10, 2024
1 parent 04b1c77 commit 47e555c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/1737.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
workers: support deleting namespaced Workers
```
7 changes: 7 additions & 0 deletions workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ type ListWorkersParams struct{}

type DeleteWorkerParams struct {
ScriptName string

// DispatchNamespaceName is the dispatch namespace the Worker is uploaded to.
DispatchNamespace *string
}

type PlacementMode string
Expand All @@ -242,6 +245,10 @@ func (api *API) DeleteWorker(ctx context.Context, rc *ResourceContainer, params
}

uri := fmt.Sprintf("/accounts/%s/workers/scripts/%s", rc.Identifier, params.ScriptName)
if params.DispatchNamespace != nil && *params.DispatchNamespace != "" {
uri = fmt.Sprintf("/accounts/%s/workers/dispatch/namespaces/%s/scripts/%s", rc.Identifier, *params.DispatchNamespace, params.ScriptName)
}

res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil)

var r WorkerScriptResponse
Expand Down
17 changes: 17 additions & 0 deletions workers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,23 @@ func TestDeleteWorker(t *testing.T) {
assert.NoError(t, err)
}

func TestDeleteNamespacedWorker(t *testing.T) {
setup()
defer teardown()

mux.HandleFunc("/accounts/"+testAccountID+"/workers/dispatch/namespaces/foo/scripts/bar", func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodDelete, r.Method, "Expected method 'DELETE', got %s", r.Method)
w.Header().Set("content-type", "application/javascript")
fmt.Fprint(w, deleteWorkerResponseData)
})

err := client.DeleteWorker(context.Background(), AccountIdentifier(testAccountID), DeleteWorkerParams{
ScriptName: "bar",
DispatchNamespace: &[]string{"foo"}[0],
})
assert.NoError(t, err)
}

func TestGetWorker(t *testing.T) {
setup()
defer teardown()
Expand Down

0 comments on commit 47e555c

Please sign in to comment.