// testBoltStorage creates a temporary bolt database. In order to clean // resources, stop function must be run at the end of each test. func testBoltStorage() (st storage.ValueInterface, stop func(), err error) { testpath, err := ioutil.TempDir("", "machinegroup") if err != nil { return nil, nil, err } db, err := bolt.Open(filepath.Join(testpath, "test.db"), 0600, nil) if err != nil { return nil, nil, err } stop = func() { db.Close() os.RemoveAll(testpath) } bstorage, err := storage.NewBoltStorageBucket(db, []byte("klient")) if err != nil { stop() return nil, nil, err } return &storage.EncodingStorage{ Interface: bstorage, }, stop, nil }
// NewCache returns new cache value backed by BoltDB. func NewBoltCache(options *CacheOptions) (*Cache, error) { db, err := newBoltDB(options) if err != nil { return nil, err } bolt, err := storage.NewBoltStorageBucket(db, options.Bucket) if err != nil { return nil, err } return &Cache{ EncodingStorage: &storage.EncodingStorage{ Interface: bolt, }, }, nil }