From de279c6fe3590fb80a8d6f1d7bc41b46dc9d15e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torjus=20H=C3=A5kestad?= Date: Sat, 15 Jan 2022 21:31:32 +0100 Subject: [PATCH] Add test for delete --- file.go => filestore.go | 0 filestore_memory.go | 2 +- filestore_test.go | 13 +++++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) rename file.go => filestore.go (100%) diff --git a/file.go b/filestore.go similarity index 100% rename from file.go rename to filestore.go diff --git a/filestore_memory.go b/filestore_memory.go index 8576fd7..3011796 100644 --- a/filestore_memory.go +++ b/filestore_memory.go @@ -65,7 +65,7 @@ func (s *MemoryFileStore) Get(id string) (*File, error) { func (s *MemoryFileStore) Delete(id string) error { s.lock.Lock() - defer s.lock.RUnlock() + defer s.lock.Unlock() delete(s.data, id) return nil } diff --git a/filestore_test.go b/filestore_test.go index ed70c55..7395a43 100644 --- a/filestore_test.go +++ b/filestore_test.go @@ -59,5 +59,18 @@ func RunFilestoreTest(s gpaste.FileStore, t *testing.T) { if ids[0] != id { t.Fatalf("ID is wrong. Got %s want %s", ids[0], id) } + + // Delete + if err := s.Delete(id); err != nil { + t.Fatalf("Error deleting file: %s", err) + } + + ids, err = s.List() + if err != nil { + t.Fatalf("Error listing after delete: %s", err) + } + if len(ids) != 0 { + t.Fatalf("List after delete has wrong length: %d", len(ids)) + } }) }