mirror of
https://github.com/taigrr/bitcask
synced 2025-01-18 04:03:17 -08:00
Add unit test for opening bad database with corrupted/invalid datafiles (#105)
This commit is contained in:
parent
5fe19989d4
commit
5ea05fb3c2
@ -796,6 +796,29 @@ func TestOpenErrors(t *testing.T) {
|
|||||||
_, err = Open(testdir, withBogusOption())
|
_, err = Open(testdir, withBogusOption())
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("LoadDatafilesError", func(t *testing.T) {
|
||||||
|
testdir, err := ioutil.TempDir("", "bitcask")
|
||||||
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(testdir)
|
||||||
|
|
||||||
|
db, err := Open(testdir)
|
||||||
|
assert.NoError(err)
|
||||||
|
|
||||||
|
err = db.Put([]byte("foo"), []byte("bar"))
|
||||||
|
assert.NoError(err)
|
||||||
|
|
||||||
|
err = db.Close()
|
||||||
|
assert.NoError(err)
|
||||||
|
|
||||||
|
// Simulate some horrible that happened to the datafiles!
|
||||||
|
err = os.Rename(filepath.Join(testdir, "000000000.data"), filepath.Join(testdir, "000000000xxx.data"))
|
||||||
|
assert.NoError(err)
|
||||||
|
|
||||||
|
_, err = Open(testdir)
|
||||||
|
assert.Error(err)
|
||||||
|
assert.Equal("strconv.ParseInt: parsing \"000000000xxx\": invalid syntax", err.Error())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCloseErrors(t *testing.T) {
|
func TestCloseErrors(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user