From 16a1ae6ba6d118aeeac8ed9c219558ba5f331c0d Mon Sep 17 00:00:00 2001 From: Xiaoxuan Wang Date: Mon, 25 Sep 2023 08:03:46 +0000 Subject: [PATCH] feat: support deletion for memory resolver Signed-off-by: Xiaoxuan Wang --- internal/resolver/memory.go | 5 +++++ internal/resolver/memory_test.go | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/internal/resolver/memory.go b/internal/resolver/memory.go index 6fac5e2d..27d6a59d 100644 --- a/internal/resolver/memory.go +++ b/internal/resolver/memory.go @@ -48,6 +48,11 @@ func (m *Memory) Tag(_ context.Context, desc ocispec.Descriptor, reference strin return nil } +// Delete removes a reference from index map. +func (m *Memory) Delete(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. diff --git a/internal/resolver/memory_test.go b/internal/resolver/memory_test.go index eb9e1e56..fe365cca 100644 --- a/internal/resolver/memory_test.go +++ b/internal/resolver/memory_test.go @@ -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.Delete(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) {