From c8034066c9a48477ab25b2f67b1ac6b88abba665 Mon Sep 17 00:00:00 2001 From: saji Date: Thu, 7 Mar 2024 07:34:55 -0600 Subject: [PATCH] add delete document test --- db_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/db_test.go b/db_test.go index 031c19d..52c31ae 100644 --- a/db_test.go +++ b/db_test.go @@ -281,4 +281,26 @@ func TestDbDocuments(t *testing.T) { } }) + t.Run("test delete document", func(t *testing.T) { + tdb := MakeMockDatabase(t.Name()) + tdb.db.Ping() + ctx := context.Background() + doc := MockDocument("hi") + tdb.AddDocument(ctx, doc) + err := tdb.DeleteDocument(ctx, "hi") + if err != nil { + t.Fatalf("DeleteDocument expected no error, got err=%v", err) + } + }) + + t.Run("test delete nonexistent document", func(t *testing.T) { + tdb := MakeMockDatabase(t.Name()) + tdb.db.Ping() + ctx := context.Background() + err := tdb.DeleteDocument(ctx, "hi") + if !errors.Is(err, DocumentNotFoundError("hi")) { + t.Fatalf("DeleteDocument expected not found, got err=%v", err) + } + }) + }