mirror of
https://github.com/luxfi/zapdb.git
synced 2026-10-30 15:12:20 +00:00
ZapDB has native streaming Backup(w, since) + Load(r). The standalone luxfi/zapdb-replicate repo was duplicate scaffolding. Sidecar daemon + restore init-container now live here under cmd/replicate/. Pre-fold lineage: standalone repo at luxfi/zapdb-replicate; final commit there c13a738 (deps Go 1.26.4 bump). No history was merged; small repo, clean copy.
40 lines
1.0 KiB
Go
40 lines
1.0 KiB
Go
package state
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestStateRoundTrip(t *testing.T) {
|
|
path := filepath.Join(t.TempDir(), "state.json")
|
|
in := &State{
|
|
Network: "mainnet",
|
|
LastVersion: 12345,
|
|
LastSnapshotKind: "increment",
|
|
LastFullVersion: 12000,
|
|
LastFullTimestamp: time.Date(2026, 6, 6, 0, 0, 0, 0, time.UTC),
|
|
}
|
|
require.NoError(t, Save(path, in))
|
|
out, err := Load(path)
|
|
require.NoError(t, err)
|
|
require.Equal(t, in.Network, out.Network)
|
|
require.Equal(t, in.LastVersion, out.LastVersion)
|
|
require.Equal(t, in.LastFullVersion, out.LastFullVersion)
|
|
require.True(t, in.LastFullTimestamp.Equal(out.LastFullTimestamp))
|
|
}
|
|
|
|
func TestLoadMissingReturnsZero(t *testing.T) {
|
|
s, err := Load(filepath.Join(t.TempDir(), "no-such-file.json"))
|
|
require.NoError(t, err)
|
|
require.NotNil(t, s)
|
|
require.Equal(t, uint64(0), s.LastVersion)
|
|
}
|
|
|
|
func TestPath(t *testing.T) {
|
|
got := Path("/data/db/mainnet")
|
|
require.Equal(t, "/data/db/.mainnet.zapdb-replicate-state.json", got)
|
|
}
|