mirror of
https://github.com/luxfi/zapdb.git
synced 2026-10-30 15:12:20 +00:00
The module has been github.com/luxfi/zapdb for a while, but the package inside it still declared itself badger, so every consumer had to write zapdb "github.com/luxfi/zapdb" // package badger and the alias existed only to paper over the mismatch. 56 root files and the 134 qualified references inside the repo now say zapdb. Backward compatible in both directions: an existing consumer with the alias keeps compiling (the alias is now merely redundant), and one without it starts compiling instead of failing on an undefined zapdb. Directory badger/ and its cmd package are untouched — that is the CLI, and its binary is named badger. Build and vet clean; suite green except TestZRestore, which wants a /tmp/zb/src benchmark fixture and fails identically without this change. Co-authored-by: Hanzo Dev <[email protected]>
84 lines
2.1 KiB
Go
84 lines
2.1 KiB
Go
/*
|
|
* SPDX-FileCopyrightText: © 2017-2025 Istari Digital, Inc.
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
package zapdb
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/luxfi/zapdb/options"
|
|
)
|
|
|
|
func TestOptions(t *testing.T) {
|
|
t.Run("default options", func(t *testing.T) {
|
|
// copy all the default options over to a big SuperFlag string
|
|
defaultSuperFlag := generateSuperFlag(DefaultOptions(""))
|
|
// fill an empty Options with values from the SuperFlag
|
|
generated := Options{}.FromSuperFlag(defaultSuperFlag)
|
|
// make sure they're equal
|
|
if !optionsEqual(DefaultOptions(""), generated) {
|
|
t.Fatal("generated default SuperFlag != default Options")
|
|
}
|
|
// check that values are overwritten properly
|
|
overwritten := DefaultOptions("").FromSuperFlag("numgoroutines=1234")
|
|
if overwritten.NumGoroutines != 1234 {
|
|
t.Fatal("Option value not overwritten by SuperFlag value")
|
|
}
|
|
})
|
|
|
|
t.Run("special flags", func(t *testing.T) {
|
|
o1 := DefaultOptions("")
|
|
o1.NamespaceOffset = 10
|
|
o1.Compression = options.ZSTD
|
|
o1.ZSTDCompressionLevel = 2
|
|
o1.NumGoroutines = 20
|
|
|
|
o2 := DefaultOptions("")
|
|
o2.NamespaceOffset = 10
|
|
o2 = o2.FromSuperFlag("compression=zstd:2; numgoroutines=20;")
|
|
|
|
// make sure they're equal
|
|
if !optionsEqual(o1, o2) {
|
|
t.Fatal("generated superFlag != expected options")
|
|
}
|
|
})
|
|
}
|
|
|
|
// optionsEqual just compares the values of two Options structs
|
|
func optionsEqual(o1, o2 Options) bool {
|
|
o1v := reflect.ValueOf(&o1).Elem()
|
|
o2v := reflect.ValueOf(&o2).Elem()
|
|
for i := 0; i < o1v.NumField(); i++ {
|
|
if o1v.Field(i).CanInterface() {
|
|
kind := o1v.Field(i).Kind()
|
|
// compare values
|
|
switch kind {
|
|
case reflect.Bool:
|
|
if o1v.Field(i).Bool() != o2v.Field(i).Bool() {
|
|
return false
|
|
}
|
|
case reflect.Int, reflect.Int64:
|
|
if o1v.Field(i).Int() != o2v.Field(i).Int() {
|
|
return false
|
|
}
|
|
case reflect.Uint32, reflect.Uint64:
|
|
if o1v.Field(i).Uint() != o2v.Field(i).Uint() {
|
|
return false
|
|
}
|
|
case reflect.Float64:
|
|
if o1v.Field(i).Float() != o2v.Field(i).Float() {
|
|
return false
|
|
}
|
|
case reflect.String:
|
|
if o1v.Field(i).String() != o2v.Field(i).String() {
|
|
return false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return true
|
|
}
|