Skip to content

Commit 6456d16

Browse files
wangxiaoxuan273Terry Howe
and
Terry Howe
authored
feat: support deletion for memory resolver (#607)
Part 2/4 of #454 Based on draft PR #582 --------- Signed-off-by: Xiaoxuan Wang <[email protected]> Co-authored-by: Terry Howe <[email protected]>
1 parent a428ca6 commit 6456d16

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

internal/resolver/memory.go

+5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ func (m *Memory) Tag(_ context.Context, desc ocispec.Descriptor, reference strin
4848
return nil
4949
}
5050

51+
// Untag removes a reference from index map.
52+
func (m *Memory) Untag(reference string) {
53+
m.index.Delete(reference)
54+
}
55+
5156
// Map dumps the memory into a built-in map structure.
5257
// Like other operations, calling Map() is go-routine safe. However, it does not
5358
// necessarily correspond to any consistent snapshot of the storage contents.

internal/resolver/memory_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ func TestMemorySuccess(t *testing.T) {
5454
if got := len(s.Map()); got != 1 {
5555
t.Errorf("Memory.Map() = %v, want %v", got, 1)
5656
}
57+
58+
s.Untag(ref)
59+
_, err = s.Resolve(ctx, ref)
60+
if !errors.Is(err, errdef.ErrNotFound) {
61+
t.Errorf("Memory.Resolve() error = %v, want %v", err, errdef.ErrNotFound)
62+
}
63+
if got := len(s.Map()); got != 0 {
64+
t.Errorf("Memory.Map() = %v, want %v", got, 0)
65+
}
5766
}
5867

5968
func TestMemoryNotFound(t *testing.T) {

0 commit comments

Comments
 (0)