Add tag delete API
Signed-off-by: João Pereira <484633+joaodrp@users.noreply.github.com>
This commit is contained in:
@@ -364,7 +364,30 @@ func (t *tags) Tag(ctx context.Context, tag string, desc distribution.Descriptor
|
||||
}
|
||||
|
||||
func (t *tags) Untag(ctx context.Context, tag string) error {
|
||||
panic("not implemented")
|
||||
ref, err := reference.WithTag(t.name, tag)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
u, err := t.ub.BuildManifestURL(ref)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("DELETE", u, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
resp, err := t.client.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if SuccessStatus(resp.StatusCode) {
|
||||
return nil
|
||||
}
|
||||
return HandleErrorResponse(resp)
|
||||
}
|
||||
|
||||
type manifests struct {
|
||||
|
@@ -1425,6 +1425,43 @@ func TestManifestTags(t *testing.T) {
|
||||
// TODO(dmcgowan): Check for error cases
|
||||
}
|
||||
|
||||
func TestTagDelete(t *testing.T) {
|
||||
tag := "latest"
|
||||
repo, _ := reference.WithName("test.example.com/repo/delete")
|
||||
newRandomSchemaV1Manifest(repo, tag, 1)
|
||||
|
||||
var m testutil.RequestResponseMap
|
||||
m = append(m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "DELETE",
|
||||
Route: "/v2/" + repo.Name() + "/manifests/" + tag,
|
||||
},
|
||||
Response: testutil.Response{
|
||||
StatusCode: http.StatusAccepted,
|
||||
Headers: map[string][]string{
|
||||
"Content-Length": {"0"},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
e, c := testServer(m)
|
||||
defer c()
|
||||
|
||||
r, err := NewRepository(repo, e, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ctx := context.Background()
|
||||
ts := r.Tags(ctx)
|
||||
|
||||
if err := ts.Untag(ctx, tag); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := ts.Untag(ctx, tag); err == nil {
|
||||
t.Fatal("expected error deleting unknown tag")
|
||||
}
|
||||
}
|
||||
|
||||
func TestObtainsErrorForMissingTag(t *testing.T) {
|
||||
repo, _ := reference.WithName("test.example.com/repo")
|
||||
|
||||
|
Reference in New Issue
Block a user