3d4412ffd4
For simplicity, I haven't exposed the entire badger config. Also, due to go default values and the badger implementation, I have had to extract the two loading mode config values so we can determine whether it has actually has been set by the user in the json config file. License: MIT Signed-off-by: Adrian Lanzafame <adrianlanzafame92@gmail.com>
54 lines
944 B
Go
54 lines
944 B
Go
package badger
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/dgraph-io/badger"
|
|
"github.com/dgraph-io/badger/options"
|
|
)
|
|
|
|
var cfgJSON = []byte(`
|
|
{
|
|
"folder": "test",
|
|
"value_log_loading_mode": 1
|
|
}
|
|
`)
|
|
|
|
func TestLoadJSON(t *testing.T) {
|
|
cfg := &Config{}
|
|
err := cfg.LoadJSON(cfgJSON)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestToJSON(t *testing.T) {
|
|
cfg := &Config{}
|
|
cfg.LoadJSON(cfgJSON)
|
|
|
|
if cfg.BadgerOptions.ValueLogLoadingMode != options.FileIO {
|
|
t.Fatalf("got: %d, want: %d", cfg.BadgerOptions.ValueLogLoadingMode, options.FileIO)
|
|
}
|
|
if cfg.BadgerOptions.ValueLogFileSize != badger.DefaultOptions.ValueLogFileSize {
|
|
t.Fatalf(
|
|
"got: %d, want: %d",
|
|
cfg.BadgerOptions.ValueLogFileSize,
|
|
badger.DefaultOptions.ValueLogFileSize,
|
|
)
|
|
}
|
|
|
|
fmt.Printf("%+v\n", cfg.BadgerOptions)
|
|
|
|
newjson, err := cfg.ToJSON()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
cfg = &Config{}
|
|
err = cfg.LoadJSON(newjson)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|