Files
zapdb/cmd/replicate/badger_smoke_test.go
zeekayandHanzo Dev fe8d85d663 rename package badger -> zapdb
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]>
2026-07-27 14:24:18 -07:00

54 lines
1.3 KiB
Go

package main_test
import (
"bytes"
"testing"
zapdb "github.com/luxfi/zapdb"
"github.com/stretchr/testify/require"
)
// TestBadgerSmoke confirms our understanding of badger's
// Backup/Load is correct, independent of the chunkwriter/vfs stack.
//
// If this fails, the bug is in our use of badger, not in the chunk
// layer.
func TestBadgerSmoke(t *testing.T) {
srcOpts := zapdb.DefaultOptions(t.TempDir())
srcOpts.Logger = nil
src, err := zapdb.Open(srcOpts)
require.NoError(t, err)
require.NoError(t, src.Update(func(txn *zapdb.Txn) error {
for i := 0; i < 10; i++ {
if err := txn.Set([]byte{byte('a' + i)}, []byte{byte('A' + i)}); err != nil {
return err
}
}
return nil
}))
var buf bytes.Buffer
until, err := src.Backup(&buf, 0)
require.NoError(t, err)
require.Greater(t, until, uint64(0))
require.NoError(t, src.Close())
dstOpts := zapdb.DefaultOptions(t.TempDir())
dstOpts.Logger = nil
dst, err := zapdb.Open(dstOpts)
require.NoError(t, err)
require.NoError(t, dst.Load(&buf, 16))
require.NoError(t, dst.View(func(txn *zapdb.Txn) error {
for i := 0; i < 10; i++ {
item, err := txn.Get([]byte{byte('a' + i)})
require.NoError(t, err)
val, err := item.ValueCopy(nil)
require.NoError(t, err)
require.Equal(t, []byte{byte('A' + i)}, val, "key %c", 'a'+i)
}
return nil
}))
require.NoError(t, dst.Close())
}