1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
// Copyright 2013 The LevelDB-Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package leveldb
import (
"path/filepath"
"testing"
)
func TestParseDBFilename(t *testing.T) {
testCases := map[string]bool{
"000000.log": true,
"000000.log.zip": false,
"000000..log": false,
"a000000.log": false,
"abcdef.log": false,
"000001ldb": false,
"000001.ldb": true,
"000002.sst": true,
"CURRENT": true,
"CURRaNT": false,
"LOCK": true,
"xLOCK": false,
"x.LOCK": false,
"MANIFEST": false,
"MANIFEST123456": false,
"MANIFEST-": false,
"MANIFEST-123456": true,
"MANIFEST-123456.doc": false,
}
for tc, want := range testCases {
_, _, got := parseDBFilename(filepath.Join("foo", tc))
if got != want {
t.Errorf("%q: got %v, want %v", tc, got, want)
}
}
}
func TestFilenameRoundTrip(t *testing.T) {
testCases := map[fileType]bool{
// CURRENT and LOCK files aren't numbered.
fileTypeCurrent: false,
fileTypeLock: false,
// The remaining file types are numbered.
fileTypeLog: true,
fileTypeManifest: true,
fileTypeOldFashionedTable: true,
fileTypeTable: true,
}
for fileType, numbered := range testCases {
fileNums := []uint64{0}
if numbered {
fileNums = []uint64{0, 1, 2, 3, 10, 42, 99, 1001}
}
for _, fileNum := range fileNums {
filename := dbFilename("foo", fileType, fileNum)
gotFT, gotFN, gotOK := parseDBFilename(filename)
if !gotOK {
t.Errorf("could not parse %q", filename)
continue
}
if gotFT != fileType || gotFN != fileNum {
t.Errorf("filename=%q: got %v, %v, want %v, %v", filename, gotFT, gotFN, fileType, fileNum)
continue
}
}
}
}
|