forked from tw-bc-group/fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_exports.go
61 lines (51 loc) · 1.53 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
58
59
60
61
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package pvtdatastorage
import (
"os"
"testing"
"github.com/hyperledger/fabric/core/ledger/pvtdatapolicy"
"github.com/hyperledger/fabric/core/ledger/ledgerconfig"
"github.com/stretchr/testify/assert"
)
// StoreEnv provides the store env for testing
type StoreEnv struct {
t testing.TB
TestStoreProvider Provider
TestStore Store
ledgerid string
btlPolicy pvtdatapolicy.BTLPolicy
}
// NewTestStoreEnv construct a StoreEnv for testing
func NewTestStoreEnv(t *testing.T, ledgerid string, btlPolicy pvtdatapolicy.BTLPolicy) *StoreEnv {
removeStorePath(t)
assert := assert.New(t)
testStoreProvider := NewProvider()
testStore, err := testStoreProvider.OpenStore(ledgerid)
testStore.Init(btlPolicy)
assert.NoError(err)
return &StoreEnv{t, testStoreProvider, testStore, ledgerid, btlPolicy}
}
// 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(env.ledgerid)
env.TestStore.Init(env.btlPolicy)
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()
}
}