diff options
author | siddharth <s@ricketyspace.net> | 2021-11-28 17:23:55 -0500 |
---|---|---|
committer | siddharth <s@ricketyspace.net> | 2021-11-28 17:23:55 -0500 |
commit | 0ee116a416bf1868ed6ed3e7c040b24e13fdb549 (patch) | |
tree | 17d71cf76946d5a9c246c91b8cc10e8c5921354b /db/db_test.go | |
parent | 43dade27aa1cd5e77201c3100276f299e321d213 (diff) |
db: add FernDB.Exists
Diffstat (limited to 'db/db_test.go')
-rw-r--r-- | db/db_test.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/db/db_test.go b/db/db_test.go index 37ec6ca..9a8642a 100644 --- a/db/db_test.go +++ b/db/db_test.go @@ -139,3 +139,46 @@ func TestOpenExistingDB(t *testing.T) { } } } + +func TestExists(t *testing.T) { + // Set custom path for db. + dbPath = path.Join(os.TempDir(), "fern-db.json") + defer os.Remove(dbPath) + + // Write a sample test db to fern-db.json + testDBJSON := []byte(`{"npr":["william-prince","joy-oladokun","lucy-ducas"]}`) + dbFile, err := os.Create(dbPath) + defer dbFile.Close() + if err != nil { + t.Errorf("Unable to create fern-db.json: %v", err.Error()) + return + } + n, err := dbFile.Write(testDBJSON) + if len(testDBJSON) != n { + t.Errorf("Write to fern-db.json failed: %v", err.Error()) + return + } + + // Open the db. + db, err := Open() + if err != nil { + t.Errorf("db.Open failed: %v", err.Error()) + return + } + + // Test Exists. + if db.Exists("mkbhd", "v-raptor") { + t.Errorf("db.Exists failed: mkbhd does not exist in db") + return + } + if db.Exists("npr", "julien-baker") { + t.Errorf("db.Exists failed: (%s, %s) does not exist in db", + "npr", "julien-baker") + return + } + if !db.Exists("npr", "joy-oladokun") { + t.Errorf("db.Exists failed: (%s, %s) exists in db", + "npr", "joy-oladokun") + return + } +} |