From 84edf12f0f3a876bae0d5b72651533d7e4421b7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Victor=20Oliveira=20Couto?= Date: Wed, 31 Mar 2021 16:21:25 -0300 Subject: [PATCH 1/2] :bug: Fixed error with no badger options being loaded --- badger/config.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/badger/config.go b/badger/config.go index 32338c0c4..24e3d89ee 100644 --- a/badger/config.go +++ b/badger/config.go @@ -68,7 +68,10 @@ func configDefault(config ...Config) Config { cfg.GCInterval = ConfigDefault.GCInterval } overrideLogger := false - if cfg.BadgerOptions.Dir == defaultDatabase && cfg.BadgerOptions.Dir != cfg.Database { + // Detecting if no default Badger option was given + // Also detects when a default badger option is given with a custom database name + if cfg.BadgerOptions.ValueLogFileSize <= 0 || cfg.BadgerOptions.Dir == "" || cfg.BadgerOptions.ValueDir == "" || + (cfg.BadgerOptions.Dir == defaultDatabase && cfg.BadgerOptions.Dir != cfg.Database) { cfg.BadgerOptions = badger.DefaultOptions(cfg.Database) overrideLogger = true } From 56f8f92922e878c84ec182d9ef6c31c5f696a493 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Victor=20Oliveira=20Couto?= Date: Tue, 6 Apr 2021 10:42:26 -0300 Subject: [PATCH 2/2] :steam_locomotive: Added config tests - Using recover function to test panic - Added .gitignore to ignore generated test directories --- badger/.gitignore | 3 +++ badger/config_test.go | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 badger/.gitignore create mode 100644 badger/config_test.go diff --git a/badger/.gitignore b/badger/.gitignore new file mode 100644 index 000000000..2630c3407 --- /dev/null +++ b/badger/.gitignore @@ -0,0 +1,3 @@ +fiber.badger/ +fiber.config.badger/ +fiber.with_options.badger/ diff --git a/badger/config_test.go b/badger/config_test.go new file mode 100644 index 000000000..85258436a --- /dev/null +++ b/badger/config_test.go @@ -0,0 +1,36 @@ +package badger + +import ( + "github.com/dgraph-io/badger/v3" + "github.com/gofiber/utils" + "testing" +) + +func assertRecoveryPanic(t *testing.T) { + err := recover() + utils.AssertEqual(t, nil, err) +} + +func Test_Badger_Only_Name(t *testing.T) { + defer assertRecoveryPanic(t) + testDB := New(Config{ + Database: "fiber.config.badger", + UseLogger: false, + }) + utils.AssertEqual(t, nil, testDB.Close()) +} + +func Test_Badger_Options(t *testing.T) { + defer assertRecoveryPanic(t) + testDB := New(Config{ + BadgerOptions: badger.DefaultOptions("fiber.with_options.badger"), + UseLogger: false, + }) + utils.AssertEqual(t, nil, testDB.Close()) +} + +func Test_Empty_Config(t *testing.T) { + defer assertRecoveryPanic(t) + testDB := New(Config{}) + utils.AssertEqual(t, nil, testDB.Close()) +}