forked from hyperledger/fabric
/
couchdb_test_export.go
41 lines (34 loc) · 1.26 KB
/
couchdb_test_export.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
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package statecouchdb
import (
"testing"
"github.com/hyperledger/fabric/common/metrics/disabled"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/integration/runner"
"github.com/stretchr/testify/require"
)
// StartCouchDB starts the CouchDB if it is not running already
func StartCouchDB(t *testing.T, binds []string) (addr string, stopCouchDBFunc func()) {
couchDB := &runner.CouchDB{Binds: binds}
require.NoError(t, couchDB.Start())
return couchDB.Address(), func() { require.NoError(t, couchDB.Stop()) }
}
// IsEmpty returns whether or not the couchdb is empty
func IsEmpty(t testing.TB, config *ledger.CouchDBConfig) bool {
couchInstance, err := createCouchInstance(config, &disabled.Provider{})
require.NoError(t, err)
dbEmpty, err := couchInstance.isEmpty(nil)
require.NoError(t, err)
return dbEmpty
}
// RetrieveApplicationDBNames retrieves application DB names
func RetrieveApplicationDBNames(t testing.TB, config *ledger.CouchDBConfig) []string {
couchInstance, err := createCouchInstance(config, &disabled.Provider{})
require.NoError(t, err)
appDBNames, err := couchInstance.retrieveApplicationDBNames()
require.NoError(t, err)
return appDBNames
}