[#137] metabase: Implement Path method

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-11-02 10:37:16 +03:00 committed by Alex Vanin
parent 8125b544b4
commit fc2038e929
2 changed files with 24 additions and 0 deletions

View file

@ -8,6 +8,8 @@ import (
// DB represents local metabase of storage node. // DB represents local metabase of storage node.
type DB struct { type DB struct {
path string
boltDB *bbolt.DB boltDB *bbolt.DB
matchers map[object.SearchMatchType]func(string, string, string) bool matchers map[object.SearchMatchType]func(string, string, string) bool
@ -16,6 +18,7 @@ type DB struct {
// NewDB creates, initializes and returns DB instance. // NewDB creates, initializes and returns DB instance.
func NewDB(boltDB *bbolt.DB) *DB { func NewDB(boltDB *bbolt.DB) *DB {
return &DB{ return &DB{
path: boltDB.Path(),
boltDB: boltDB, boltDB: boltDB,
matchers: map[object.SearchMatchType]func(string, string, string) bool{ matchers: map[object.SearchMatchType]func(string, string, string) bool{
object.MatchStringEqual: stringEqualMatcher, object.MatchStringEqual: stringEqualMatcher,
@ -27,6 +30,11 @@ func (db *DB) Close() error {
return db.boltDB.Close() return db.boltDB.Close()
} }
// Path returns the path to meta database.
func (db *DB) Path() string {
return db.path
}
func stringEqualMatcher(key, objVal, filterVal string) bool { func stringEqualMatcher(key, objVal, filterVal string) bool {
switch key { switch key {
default: default:

View file

@ -236,3 +236,19 @@ func TestDB_SelectProperties(t *testing.T) {
fs.AddFilter(v2object.FilterPropertyChildfree, "some false value", objectSDK.MatchStringEqual) fs.AddFilter(v2object.FilterPropertyChildfree, "some false value", objectSDK.MatchStringEqual)
testSelect(t, db, fs, lnkAddr) testSelect(t, db, fs, lnkAddr)
} }
func TestDB_Path(t *testing.T) {
path := t.Name()
bdb, err := bbolt.Open(path, 0600, nil)
require.NoError(t, err)
defer func() {
bdb.Close()
os.Remove(path)
}()
db := NewDB(bdb)
require.Equal(t, path, db.Path())
}