From a5eff054e71850cc50fb1571b93d1b9e490195b4 Mon Sep 17 00:00:00 2001 From: PJ Date: Thu, 7 Apr 2022 14:45:07 +0200 Subject: [PATCH] Fix missing test --- database/database_test.go | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/database/database_test.go b/database/database_test.go index 53e41b5..4a036a8 100644 --- a/database/database_test.go +++ b/database/database_test.go @@ -51,7 +51,7 @@ func TestDatabase(t *testing.T) { name string test func(t *testing.T) }{ - + { name: "BlockedHashes", test: testBlockedHashes, @@ -109,6 +109,37 @@ func testBlockedHashes(t *testing.T) { t.Fatal(err) } }() + + // assert there's no hash that needs to be blocked + toBlock, err := db.HashesToBlock(ctx, time.Time{}) + if err != nil { + t.Fatal(err) + } + if len(toBlock) != 0 { + t.Fatalf("expected 0 hashes, instead it was %v", len(toBlock)) + } + + // insert a regular document + hash := HashBytes([]byte("skylink_1")) + err = db.CreateBlockedSkylink(ctx, &BlockedSkylink{ + Skylink: "skylink_1", + Hash: hash, + Reporter: Reporter{}, + Tags: []string{"tag_1"}, + TimestampAdded: time.Now().UTC(), + }) + if err != nil { + t.Fatal(err) + } + + // assert there's one hash that needs to be blocked + toBlock, err = db.HashesToBlock(ctx, time.Time{}) + if err != nil { + t.Fatal(err) + } + if len(toBlock) != 1 { + t.Fatalf("expected 1 hash, instead it was %v", len(toBlock)) + } } // testCreateBlockedSkylink tests creating and fetching a blocked skylink from @@ -567,7 +598,6 @@ func testMarkInvalid(t *testing.T) { } } - // testPing is a unit test for the database's Ping method. func testPing(t *testing.T) { // create context