@@ -21,7 +21,7 @@ import (
21
21
"fmt"
22
22
"testing"
23
23
24
- kvledgerconfig "github.com/hyperledger/fabric/core/ledger/kvledger/kvledgerconfig"
24
+ "github.com/hyperledger/fabric/core/ledger/kvledger/kvledgerconfig"
25
25
"github.com/hyperledger/fabric/core/ledger/testutil"
26
26
)
27
27
@@ -34,8 +34,8 @@ type Asset struct {
34
34
Owner string `json:"owner"`
35
35
}
36
36
37
- var hostname = "localhost"
38
- var port = 5984
37
+ var connectURL = "localhost:5984 "
38
+ var badConnectURL = "localhost:5990"
39
39
var database = "testdb1"
40
40
var username = ""
41
41
var password = ""
@@ -44,16 +44,19 @@ var assetJSON = []byte(`{"asset_name":"marble1","color":"blue","size":"35","owne
44
44
45
45
func TestDBConnectionDef (t * testing.T ) {
46
46
47
+ //call a helper method to load the core.yaml
48
+ testutil .SetupCoreYAMLConfig ("./../../../../../../peer" )
49
+
47
50
//create a new connection
48
- _ , err := CreateConnectionDefinition ("localhost" , 5984 , "database" , "" , "" )
51
+ _ , err := CreateConnectionDefinition (connectURL , "database" , "" , "" )
49
52
testutil .AssertNoError (t , err , fmt .Sprintf ("Error when trying to create database connection definition" ))
50
53
51
54
}
52
55
53
56
func TestDBBadConnectionDef (t * testing.T ) {
54
57
55
58
//create a new connection
56
- _ , err := CreateConnectionDefinition ("^^^localhost" , 5984 , "database" , "" , "" )
59
+ _ , err := CreateConnectionDefinition ("^^^localhost: 5984" , "database" , "" , "" )
57
60
testutil .AssertError (t , err , fmt .Sprintf ("Did not receive error when trying to create database connection definition with a bad hostname" ))
58
61
59
62
}
@@ -66,7 +69,7 @@ func TestDBCreateSaveWithoutRevision(t *testing.T) {
66
69
defer cleanup ()
67
70
68
71
//create a new connection
69
- db , err := CreateConnectionDefinition (hostname , port , database , username , password )
72
+ db , err := CreateConnectionDefinition (connectURL , database , username , password )
70
73
testutil .AssertNoError (t , err , fmt .Sprintf ("Error when trying to create database connection definition" ))
71
74
72
75
//create a new database
@@ -85,7 +88,7 @@ func TestDBBadConnection(t *testing.T) {
85
88
if kvledgerconfig .IsCouchDBEnabled () == true {
86
89
87
90
//create a new connection
88
- db , err := CreateConnectionDefinition (hostname , port + 5 , database , username , password )
91
+ db , err := CreateConnectionDefinition (badConnectURL , database , username , password )
89
92
testutil .AssertNoError (t , err , fmt .Sprintf ("Error when trying to create database connection definition" ))
90
93
91
94
//create a new database
@@ -110,7 +113,7 @@ func TestDBCreateDatabaseAndPersist(t *testing.T) {
110
113
cleanup ()
111
114
112
115
//create a new connection
113
- db , err := CreateConnectionDefinition (hostname , port , database , username , password )
116
+ db , err := CreateConnectionDefinition (connectURL , database , username , password )
114
117
testutil .AssertNoError (t , err , fmt .Sprintf ("Error when trying to create database connection definition" ))
115
118
116
119
//create a new database
@@ -177,7 +180,7 @@ func TestDBBadJSON(t *testing.T) {
177
180
cleanup ()
178
181
179
182
//create a new connection
180
- db , err := CreateConnectionDefinition (hostname , port , database , username , password )
183
+ db , err := CreateConnectionDefinition (connectURL , database , username , password )
181
184
testutil .AssertNoError (t , err , fmt .Sprintf ("Error when trying to create database connection definition" ))
182
185
183
186
//create a new database
@@ -216,7 +219,7 @@ func TestDBSaveAttachment(t *testing.T) {
216
219
attachments = append (attachments , attachment )
217
220
218
221
//create a new connection
219
- db , err := CreateConnectionDefinition (hostname , port , database , username , password )
222
+ db , err := CreateConnectionDefinition (connectURL , database , username , password )
220
223
testutil .AssertNoError (t , err , fmt .Sprintf ("Error when trying to create database connection definition" ))
221
224
222
225
//create a new database
@@ -242,7 +245,7 @@ func TestDBRetrieveNonExistingDocument(t *testing.T) {
242
245
defer cleanup ()
243
246
244
247
//create a new connection
245
- db , err := CreateConnectionDefinition (hostname , port , database , username , password )
248
+ db , err := CreateConnectionDefinition (connectURL , database , username , password )
246
249
testutil .AssertNoError (t , err , fmt .Sprintf ("Error when trying to create database connection definition" ))
247
250
248
251
//create a new database
@@ -264,7 +267,7 @@ func TestDBTestExistingDB(t *testing.T) {
264
267
defer cleanup ()
265
268
266
269
//create a new connection
267
- db , err := CreateConnectionDefinition (hostname , port , database , username , password )
270
+ db , err := CreateConnectionDefinition (connectURL , database , username , password )
268
271
testutil .AssertNoError (t , err , fmt .Sprintf ("Error when trying to create database connection definition" ))
269
272
270
273
//create a new database
@@ -286,7 +289,7 @@ func TestDBTestDropNonExistDatabase(t *testing.T) {
286
289
defer cleanup ()
287
290
288
291
//create a new connection
289
- db , err := CreateConnectionDefinition (hostname , port , database , username , password )
292
+ db , err := CreateConnectionDefinition (connectURL , database , username , password )
290
293
testutil .AssertNoError (t , err , fmt .Sprintf ("Error when trying to create database connection definition" ))
291
294
292
295
//Attempt to drop the database without creating first
@@ -304,7 +307,7 @@ func TestDBTestDropDatabaseBadConnection(t *testing.T) {
304
307
defer cleanup ()
305
308
306
309
//create a new connection
307
- db , err := CreateConnectionDefinition (hostname , port + 4 , database , username , password )
310
+ db , err := CreateConnectionDefinition (badConnectURL , database , username , password )
308
311
testutil .AssertNoError (t , err , fmt .Sprintf ("Error when trying to create database connection definition" ))
309
312
310
313
//Attempt to drop the database without creating first
@@ -317,7 +320,7 @@ func TestDBTestDropDatabaseBadConnection(t *testing.T) {
317
320
func cleanup () {
318
321
319
322
//create a new connection
320
- db , _ := CreateConnectionDefinition (hostname , port , database , username , password )
323
+ db , _ := CreateConnectionDefinition (connectURL , database , username , password )
321
324
322
325
//drop the test database
323
326
db .DropDatabase ()
0 commit comments