Add DB path tests
This commit is contained in:
4
db.go
4
db.go
@@ -135,16 +135,20 @@ func (db *DB) GenerationNamePath() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GenerationPath returns the path of a single generation.
|
// GenerationPath returns the path of a single generation.
|
||||||
|
// Panics if generation is blank.
|
||||||
func (db *DB) GenerationPath(generation string) string {
|
func (db *DB) GenerationPath(generation string) string {
|
||||||
|
assert(generation != "", "generation name required")
|
||||||
return filepath.Join(db.MetaPath(), "generations", generation)
|
return filepath.Join(db.MetaPath(), "generations", generation)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShadowWALDir returns the path of the shadow wal directory.
|
// ShadowWALDir returns the path of the shadow wal directory.
|
||||||
|
// Panics if generation is blank.
|
||||||
func (db *DB) ShadowWALDir(generation string) string {
|
func (db *DB) ShadowWALDir(generation string) string {
|
||||||
return filepath.Join(db.GenerationPath(generation), "wal")
|
return filepath.Join(db.GenerationPath(generation), "wal")
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShadowWALPath returns the path of a single shadow WAL file.
|
// ShadowWALPath returns the path of a single shadow WAL file.
|
||||||
|
// Panics if generation is blank or index is negative.
|
||||||
func (db *DB) ShadowWALPath(generation string, index int) string {
|
func (db *DB) ShadowWALPath(generation string, index int) string {
|
||||||
assert(index >= 0, "shadow wal index cannot be negative")
|
assert(index >= 0, "shadow wal index cannot be negative")
|
||||||
return filepath.Join(db.ShadowWALDir(generation), FormatWALPath(index))
|
return filepath.Join(db.ShadowWALDir(generation), FormatWALPath(index))
|
||||||
|
|||||||
57
db_test.go
57
db_test.go
@@ -10,6 +10,63 @@ import (
|
|||||||
"github.com/benbjohnson/litestream"
|
"github.com/benbjohnson/litestream"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestDB_Path(t *testing.T) {
|
||||||
|
db := litestream.NewDB("/tmp/db")
|
||||||
|
if got, want := db.Path(), `/tmp/db`; got != want {
|
||||||
|
t.Fatalf("Path()=%v, want %v", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDB_WALPath(t *testing.T) {
|
||||||
|
db := litestream.NewDB("/tmp/db")
|
||||||
|
if got, want := db.WALPath(), `/tmp/db-wal`; got != want {
|
||||||
|
t.Fatalf("WALPath()=%v, want %v", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDB_MetaPath(t *testing.T) {
|
||||||
|
t.Run("Absolute", func(t *testing.T) {
|
||||||
|
db := litestream.NewDB("/tmp/db")
|
||||||
|
if got, want := db.MetaPath(), `/tmp/.db-litestream`; got != want {
|
||||||
|
t.Fatalf("MetaPath()=%v, want %v", got, want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
t.Run("Relative", func(t *testing.T) {
|
||||||
|
db := litestream.NewDB("db")
|
||||||
|
if got, want := db.MetaPath(), `.db-litestream`; got != want {
|
||||||
|
t.Fatalf("MetaPath()=%v, want %v", got, want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDB_GenerationNamePath(t *testing.T) {
|
||||||
|
db := litestream.NewDB("/tmp/db")
|
||||||
|
if got, want := db.GenerationNamePath(), `/tmp/.db-litestream/generation`; got != want {
|
||||||
|
t.Fatalf("GenerationNamePath()=%v, want %v", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDB_GenerationPath(t *testing.T) {
|
||||||
|
db := litestream.NewDB("/tmp/db")
|
||||||
|
if got, want := db.GenerationPath("xxxx"), `/tmp/.db-litestream/generations/xxxx`; got != want {
|
||||||
|
t.Fatalf("GenerationPath()=%v, want %v", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDB_ShadowWALDir(t *testing.T) {
|
||||||
|
db := litestream.NewDB("/tmp/db")
|
||||||
|
if got, want := db.ShadowWALDir("xxxx"), `/tmp/.db-litestream/generations/xxxx/wal`; got != want {
|
||||||
|
t.Fatalf("ShadowWALDir()=%v, want %v", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDB_ShadowWALPath(t *testing.T) {
|
||||||
|
db := litestream.NewDB("/tmp/db")
|
||||||
|
if got, want := db.ShadowWALPath("xxxx", 1000), `/tmp/.db-litestream/generations/xxxx/wal/00000000000003e8.wal`; got != want {
|
||||||
|
t.Fatalf("ShadowWALPath()=%v, want %v", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure we can check the last modified time of the real database and its WAL.
|
// Ensure we can check the last modified time of the real database and its WAL.
|
||||||
func TestDB_UpdatedAt(t *testing.T) {
|
func TestDB_UpdatedAt(t *testing.T) {
|
||||||
t.Run("ErrNotExist", func(t *testing.T) {
|
t.Run("ErrNotExist", func(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user