From b64cce52d9011d9c85bc68041e998f2a0c513867 Mon Sep 17 00:00:00 2001 From: siddharth ravikumar Date: Sun, 25 Dec 2022 11:58:47 -0500 Subject: db: add `defaultDBPath` For storing the default db path. The `dbPath` gets changed during tests. The `defaultDBPath` can be used to reset `dbPath` back to the default db path through the `resetDBPath` function. --- db/db.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/db/db.go b/db/db.go index d935467..c13f6d1 100644 --- a/db/db.go +++ b/db/db.go @@ -14,6 +14,7 @@ import ( ) var dbPath string +var defaultDBPath string // Contains information about list of media that where already // download for different feeds. @@ -34,8 +35,8 @@ func init() { if err != nil { return } - dbPath = path.Join(h, ".config", "fern", "db.json") - + defaultDBPath = path.Join(h, ".config", "fern", "db.json") + dbPath = defaultDBPath } // Reads the fern db from disk and unmarshals it into a FernDB @@ -140,3 +141,9 @@ func (fdb *FernDB) Write() error { } return nil } + +// Sets DB path to the default path. This function is meant to be used +// by tests. +func resetDBPath() { + dbPath = defaultDBPath +} -- cgit v1.2.3