-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_exports.go
57 lines (47 loc) · 1.3 KB
/
test_exports.go
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
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package pvtdatastorage
import (
"os"
"testing"
"github.com/hyperledger/fabric/core/ledger/ledgerconfig"
"github.com/stretchr/testify/assert"
)
const testStoreid = "TestStore"
// StoreEnv provides the store env for testing
type StoreEnv struct {
t testing.TB
TestStoreProvider Provider
TestStore Store
}
// NewTestStoreEnv construct a StoreEnv for testing
func NewTestStoreEnv(t *testing.T) *StoreEnv {
removeStorePath(t)
assert := assert.New(t)
testStoreProvider := NewProvider()
testStore, err := testStoreProvider.OpenStore(testStoreid)
assert.NoError(err)
return &StoreEnv{t, testStoreProvider, testStore}
}
// CloseAndReopen closes and opens the store provider
func (env *StoreEnv) CloseAndReopen() {
var err error
env.TestStoreProvider.Close()
env.TestStoreProvider = NewProvider()
env.TestStore, err = env.TestStoreProvider.OpenStore(testStoreid)
assert.NoError(env.t, err)
}
// Cleanup cleansup the store env after testing
func (env *StoreEnv) Cleanup() {
env.TestStoreProvider.Close()
removeStorePath(env.t)
}
func removeStorePath(t testing.TB) {
dbPath := ledgerconfig.GetPvtdataStorePath()
if err := os.RemoveAll(dbPath); err != nil {
t.Fatalf("Err: %s", err)
t.FailNow()
}
}