@@ -31,6 +31,10 @@ const orgChannelID = "orgchannel"
3131
3232var backend * mocks.MockConfigBackend
3333
34+ type testEntityMatchers struct {
35+ matchers map [string ][]fab.MatchConfig
36+ }
37+
3438func TestMain (m * testing.M ) {
3539 backend = setupCustomBackend ("key" )
3640 r := m .Run ()
@@ -227,10 +231,12 @@ func TestUnmarshalWithMultipleBackend(t *testing.T) {
227231
228232 //output struct
229233 networkConfig := fab.NetworkConfig {}
234+ entityMatchers := testEntityMatchers {}
235+
230236 assert .Nil (t , testLookup .UnmarshalKey ("client" , & networkConfig .Client ), "unmarshalKey supposed to succeed" )
231237 assert .Nil (t , testLookup .UnmarshalKey ("channels" , & networkConfig .Channels ), "unmarshalKey supposed to succeed" )
232238 assert .Nil (t , testLookup .UnmarshalKey ("certificateAuthorities" , & networkConfig .CertificateAuthorities ), "unmarshalKey supposed to succeed" )
233- assert .Nil (t , testLookup .UnmarshalKey ("entityMatchers" , & networkConfig . EntityMatchers ), "unmarshalKey supposed to succeed" )
239+ assert .Nil (t , testLookup .UnmarshalKey ("entityMatchers" , & entityMatchers . matchers ), "unmarshalKey supposed to succeed" )
234240 assert .Nil (t , testLookup .UnmarshalKey ("organizations" , & networkConfig .Organizations ), "unmarshalKey supposed to succeed" )
235241 assert .Nil (t , testLookup .UnmarshalKey ("orderers" , & networkConfig .Orderers ), "unmarshalKey supposed to succeed" )
236242 assert .Nil (t , testLookup .UnmarshalKey ("peers" , & networkConfig .Peers ), "unmarshalKey supposed to succeed" )
@@ -253,15 +259,15 @@ func TestUnmarshalWithMultipleBackend(t *testing.T) {
253259 assert .Equal (t , networkConfig .CertificateAuthorities ["local.ca.org2.example.com" ].URL , "https://ca.org2.example.com:8054" )
254260
255261 //EntityMatchers
256- assert .Equal (t , len (networkConfig . EntityMatchers ), 4 )
257- assert .Equal (t , len (networkConfig . EntityMatchers ["peer" ]), 8 )
258- assert .Equal (t , networkConfig . EntityMatchers ["peer" ][0 ].MappedHost , "local.peer0.org1.example.com" )
259- assert .Equal (t , len (networkConfig . EntityMatchers ["orderer" ]), 4 )
260- assert .Equal (t , networkConfig . EntityMatchers ["orderer" ][0 ].MappedHost , "local.orderer.example.com" )
261- assert .Equal (t , len (networkConfig . EntityMatchers ["certificateauthority" ]), 2 )
262- assert .Equal (t , networkConfig . EntityMatchers ["certificateauthority" ][0 ].MappedHost , "local.ca.org1.example.com" )
263- assert .Equal (t , len (networkConfig . EntityMatchers ["channel" ]), 1 )
264- assert .Equal (t , networkConfig . EntityMatchers ["channel" ][0 ].MappedName , "ch1" )
262+ assert .Equal (t , len (entityMatchers . matchers ), 4 )
263+ assert .Equal (t , len (entityMatchers . matchers ["peer" ]), 8 )
264+ assert .Equal (t , entityMatchers . matchers ["peer" ][0 ].MappedHost , "local.peer0.org1.example.com" )
265+ assert .Equal (t , len (entityMatchers . matchers ["orderer" ]), 4 )
266+ assert .Equal (t , entityMatchers . matchers ["orderer" ][0 ].MappedHost , "local.orderer.example.com" )
267+ assert .Equal (t , len (entityMatchers . matchers ["certificateauthority" ]), 2 )
268+ assert .Equal (t , entityMatchers . matchers ["certificateauthority" ][0 ].MappedHost , "local.ca.org1.example.com" )
269+ assert .Equal (t , len (entityMatchers . matchers ["channel" ]), 1 )
270+ assert .Equal (t , entityMatchers . matchers ["channel" ][0 ].MappedName , "ch1" )
265271
266272 //Organizations
267273 assert .Equal (t , len (networkConfig .Organizations ), 3 )
@@ -331,15 +337,17 @@ func TestLookupUnmarshalAgainstViperUnmarshal(t *testing.T) {
331337 /*
332338 TEST NETWORK CONFIG ENTITY MATCHERS
333339 */
340+ entityMatchers := testEntityMatchers {}
334341 //get entityMatchers backend lookup
335- err = testLookup .UnmarshalKey ("entityMatchers" , & networkConfig . EntityMatchers )
342+ err = testLookup .UnmarshalKey ("entityMatchers" , & entityMatchers . matchers )
336343 if err != nil {
337344 t .Fatal (err )
338345 }
339346 //get entityMatchers from viper
340- sampleViper .UnmarshalKey ("entityMatchers" , & networkConfigViper .EntityMatchers )
347+ viperEntityMatchers := testEntityMatchers {}
348+ sampleViper .UnmarshalKey ("entityMatchers" , & viperEntityMatchers .matchers )
341349 //now compare
342- assert .True (t , reflect .DeepEqual (& networkConfig . EntityMatchers , & networkConfigViper . EntityMatchers ), "unmarshalled value from config lookup supposed to match unmarshalled value from viper" )
350+ assert .True (t , reflect .DeepEqual (& entityMatchers , & viperEntityMatchers ), "unmarshalled value from config lookup supposed to match unmarshalled value from viper" )
343351
344352 /*
345353 TEST NETWORK CONFIG ORGANIZATIONS
@@ -382,10 +390,10 @@ func TestLookupUnmarshalAgainstViperUnmarshal(t *testing.T) {
382390
383391 //Just to make sure that empty values are not being compared
384392 assert .True (t , len (networkConfigViper .Channels ) > 0 , "expected to get valid unmarshalled value" )
385- assert .True (t , len (networkConfigViper . Organizations ) > 0 , "expected to get valid unmarshalled value" )
393+ assert .True (t , len (viperEntityMatchers . matchers ) > 0 , "expected to get valid unmarshalled value" )
386394 assert .True (t , len (networkConfigViper .Orderers ) > 0 , "expected to get valid unmarshalled value" )
387395 assert .True (t , len (networkConfigViper .Peers ) > 0 , "expected to get valid unmarshalled value" )
388- assert .True (t , len (networkConfigViper . EntityMatchers ) > 0 , "expected to get valid unmarshalled value" )
396+ assert .True (t , len (entityMatchers . matchers ) > 0 , "expected to get valid unmarshalled value" )
389397 assert .True (t , networkConfigViper .Client .Organization != "" , "expected to get valid unmarshalled value" )
390398
391399}
0 commit comments