Skip to content

Commit

Permalink
feat: support deletion for memory resolver (#607)
Browse files Browse the repository at this point in the history
Part 2/4 of #454 

Based on draft PR #582

---------

Signed-off-by: Xiaoxuan Wang <[email protected]>
Co-authored-by: Terry Howe <[email protected]>
  • Loading branch information
wangxiaoxuan273 and Terry Howe authored Oct 2, 2023
1 parent a428ca6 commit 6456d16
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/resolver/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ func (m *Memory) Tag(_ context.Context, desc ocispec.Descriptor, reference strin
return nil
}

// Untag removes a reference from index map.
func (m *Memory) Untag(reference string) {
m.index.Delete(reference)
}

// Map dumps the memory into a built-in map structure.
// Like other operations, calling Map() is go-routine safe. However, it does not
// necessarily correspond to any consistent snapshot of the storage contents.
Expand Down
9 changes: 9 additions & 0 deletions internal/resolver/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ func TestMemorySuccess(t *testing.T) {
if got := len(s.Map()); got != 1 {
t.Errorf("Memory.Map() = %v, want %v", got, 1)
}

s.Untag(ref)
_, err = s.Resolve(ctx, ref)
if !errors.Is(err, errdef.ErrNotFound) {
t.Errorf("Memory.Resolve() error = %v, want %v", err, errdef.ErrNotFound)
}
if got := len(s.Map()); got != 0 {
t.Errorf("Memory.Map() = %v, want %v", got, 0)
}
}

func TestMemoryNotFound(t *testing.T) {
Expand Down

0 comments on commit 6456d16

Please sign in to comment.