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]>
61 lines
1.3 KiB
Go
61 lines
1.3 KiB
Go
/*
|
|
* SPDX-FileCopyrightText: © 2017-2025 Istari Digital, Inc.
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
package zapdb
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
type mockLogger struct {
|
|
output string
|
|
}
|
|
|
|
func (l *mockLogger) Errorf(f string, v ...interface{}) {
|
|
l.output = fmt.Sprintf("ERROR: "+f, v...)
|
|
}
|
|
|
|
func (l *mockLogger) Infof(f string, v ...interface{}) {
|
|
l.output = fmt.Sprintf("INFO: "+f, v...)
|
|
}
|
|
|
|
func (l *mockLogger) Warningf(f string, v ...interface{}) {
|
|
l.output = fmt.Sprintf("WARNING: "+f, v...)
|
|
}
|
|
|
|
func (l *mockLogger) Debugf(f string, v ...interface{}) {
|
|
l.output = fmt.Sprintf("DEBUG: "+f, v...)
|
|
}
|
|
|
|
// Test that the DB-specific log is used instead of the global log.
|
|
func TestDbLog(t *testing.T) {
|
|
l := &mockLogger{}
|
|
opt := Options{Logger: l}
|
|
|
|
opt.Errorf("test")
|
|
require.Equal(t, "ERROR: test", l.output)
|
|
opt.Infof("test")
|
|
require.Equal(t, "INFO: test", l.output)
|
|
opt.Warningf("test")
|
|
require.Equal(t, "WARNING: test", l.output)
|
|
}
|
|
|
|
// Test that the global logger is used when no logger is specified in Options.
|
|
func TestNoDbLog(t *testing.T) {
|
|
l := &mockLogger{}
|
|
opt := Options{}
|
|
opt.Logger = l
|
|
|
|
opt.Errorf("test")
|
|
require.Equal(t, "ERROR: test", l.output)
|
|
opt.Infof("test")
|
|
require.Equal(t, "INFO: test", l.output)
|
|
opt.Warningf("test")
|
|
require.Equal(t, "WARNING: test", l.output)
|
|
}
|