Skip to content

Commit 862e165

Browse files
immanuwellcrozzy
authored andcommitted
fix: align update operation delete api
Signed-off-by: immanuwell <pchpr.00@list.ru>
1 parent d132607 commit 862e165

7 files changed

Lines changed: 80 additions & 39 deletions

File tree

Documentation/reference/api.md

Lines changed: 8 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

httptransport/api/v1/openapi.etag

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

httptransport/api/v1/openapi.jq

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,16 @@ def responses($r):
250250
],
251251
},
252252
},
253-
"\($path_match)/internal/update_operation/{digest}": {
253+
"\($path_match)/internal/update_operation/{id}": {
254254
delete: {
255255
operationId: "DeleteUpdateOperation",
256-
responses: (responses({})),
256+
responses: (responses({
257+
"204": {
258+
description: "Success",
259+
},
260+
}) | del(.["200"])),
257261
},
258-
parameters: [ param_ref("digest") ],
262+
parameters: [ param_ref("update_operation_id") ],
259263
},
260264
"\($path_match)/internal/update_diff": {
261265
get: {
@@ -349,6 +353,16 @@ def responses($r):
349353
in: "path",
350354
schema: schema_ref("digest"),
351355
required: true,
356+
},
357+
update_operation_id: {
358+
description: "UUID of the update operation to delete.",
359+
name: "id",
360+
in: "path",
361+
schema: {
362+
type: "string",
363+
format: "uuid",
364+
},
365+
required: true,
352366
}
353367
},
354368
headers: {

httptransport/api/v1/openapi.json

Lines changed: 14 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

httptransport/api/v1/openapi.yaml

Lines changed: 11 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

httptransport/matcher_v1.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,15 @@ func (h *MatcherV1) updateOperationHandlerDelete(w http.ResponseWriter, r *http.
239239
id := filepath.Base(path)
240240
uuid, err := uuid.Parse(id)
241241
if err != nil {
242-
slog.WarnContext(ctx, "could not deserialize manifest", "reason", err)
243-
apiError(ctx, w, http.StatusBadRequest, "could not deserialize manifest: %v", err)
242+
slog.WarnContext(ctx, "could not parse update operation id", "reason", err)
243+
apiError(ctx, w, http.StatusBadRequest, "could not parse update operation id: %v", err)
244244
}
245245

246246
_, err = h.srv.DeleteUpdateOperations(ctx, uuid)
247247
if err != nil {
248248
apiError(ctx, w, http.StatusInternalServerError, "could not get update operations: %v", err)
249249
}
250-
// TODO(hank) This should return HTTP 204.
250+
w.WriteHeader(http.StatusNoContent)
251251
}
252252

253253
func init() {

httptransport/matcher_v1_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,18 @@ func testUpdateOperationHandlerGet(t *testing.T) {
346346
idStr := "\"" + id.String() + "\""
347347
var called bool
348348
var latestCalled bool
349+
var deleteCalled bool
349350
m := &matcher.Mock{
351+
DeleteUpdateOperations_: func(_ context.Context, refs ...uuid.UUID) (int64, error) {
352+
deleteCalled = true
353+
if got, want := len(refs), 1; got != want {
354+
t.Fatalf("got: %v, want: %v", got, want)
355+
}
356+
if got, want := refs[0], id; got != want {
357+
t.Fatalf("got: %v, want: %v", got, want)
358+
}
359+
return 1, nil
360+
},
350361
LatestUpdateOperation_: func(context.Context, driver.UpdateKind) (uuid.UUID, error) {
351362
return id, nil
352363
},
@@ -411,4 +422,19 @@ func testUpdateOperationHandlerGet(t *testing.T) {
411422
if etag != idStr {
412423
t.Fatalf("got: %v, want: %v", etag, id.String())
413424
}
425+
426+
req, err = httputil.NewRequestWithContext(ctx, http.MethodDelete, srv.URL+path.Join("/", "internal", "update_operation", id.String()), nil)
427+
if err != nil {
428+
t.Fatalf("failed to create request: %v", err)
429+
}
430+
resp, err = c.Do(req)
431+
if err != nil {
432+
t.Fatalf("failed to make request: %v", err)
433+
}
434+
if resp.StatusCode != http.StatusNoContent {
435+
t.Fatalf("got: %v, want: %v", resp.StatusCode, http.StatusNoContent)
436+
}
437+
if !deleteCalled {
438+
t.Fatalf("got: %v, want: %v", deleteCalled, true)
439+
}
414440
}

0 commit comments

Comments
 (0)