github.com/kaituanwang/hyperledger@v2.0.1+incompatible/core/ledger/kvledger/bookkeeping/test_exports.go (about) 1 /* 2 Copyright IBM Corp. 2017 All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package bookkeeping 18 19 import ( 20 "io/ioutil" 21 "os" 22 "testing" 23 24 "github.com/stretchr/testify/require" 25 ) 26 27 // TestEnv provides the bookkeeper provider env for testing 28 type TestEnv struct { 29 t testing.TB 30 TestProvider Provider 31 dbPath string 32 } 33 34 // NewTestEnv construct a TestEnv for testing 35 func NewTestEnv(t testing.TB) *TestEnv { 36 dbPath, err := ioutil.TempDir("", "bookkeep") 37 require.NoError(t, err) 38 provider, err := NewProvider(dbPath) 39 require.NoError(t, err) 40 return &TestEnv{t, provider, dbPath} 41 } 42 43 // Cleanup cleansup the store env after testing 44 func (te *TestEnv) Cleanup() { 45 te.TestProvider.Close() 46 os.RemoveAll(te.dbPath) 47 }