Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support deleting namespaced Workers in DeleteWorker #1737

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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