-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-3890] Increase coverage for common/config
Coverage for common/config and common/config/msp is over 90%. Also removed a few dead code paths as well. Change-Id: Ia74527bf6d052be27083990c3779827e2844eb01 Signed-off-by: Gari Singh <gari.r.singh@gmail.com>
- Loading branch information
1 parent
65ee7b2
commit 467a2f1
Showing
9 changed files
with
341 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
Copyright IBM Corp. 2017 All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package config | ||
|
||
import ( | ||
"testing" | ||
|
||
cb "github.com/hyperledger/fabric/protos/common" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestConsortiumGroup(t *testing.T) { | ||
|
||
cg := NewConsortiumGroup(nil) | ||
og, err := cg.NewGroup("testGroup") | ||
assert.NoError(t, err, "NewGroup should not have returned error") | ||
assert.Equal(t, "testGroup", og.(*OrganizationGroup).Name(), | ||
"Unexpected group name returned") | ||
|
||
cc := cg.Allocate() | ||
_, ok := cc.(*ConsortiumConfig) | ||
assert.Equal(t, true, ok, "Allocate should have returned a ConsortiumConfig") | ||
|
||
_, _, err = cg.BeginValueProposals(t, []string{"testGroup"}) | ||
assert.NoError(t, err, "BeginValueProposals should not have returned error") | ||
|
||
err = cg.PreCommit(t) | ||
assert.NoError(t, err, "PreCommit should not have returned error") | ||
cg.CommitProposals(t) | ||
cg.RollbackProposals(t) | ||
|
||
} | ||
|
||
func TestConsortiumConfig(t *testing.T) { | ||
cg := NewConsortiumGroup(nil) | ||
cc := NewConsortiumConfig(cg) | ||
orgs := cc.Organizations() | ||
assert.Equal(t, 0, len(orgs)) | ||
|
||
policy := cc.ChannelCreationPolicy() | ||
assert.EqualValues(t, cb.Policy_UNKNOWN, policy.Type, "Expected policy type to be UNKNOWN") | ||
|
||
cc.Commit() | ||
assert.Equal(t, cg.ConsortiumConfig, cc, "Error committing ConsortiumConfig") | ||
|
||
og, _ := cg.NewGroup("testGroup") | ||
err := cc.Validate(t, map[string]ValueProposer{ | ||
"testGroup": og, | ||
}) | ||
assert.NoError(t, err, "Validate returned unexpected error") | ||
csg := NewConsortiumsGroup() | ||
err = cc.Validate(t, map[string]ValueProposer{ | ||
"testGroup": csg, | ||
}) | ||
assert.Error(t, err, "Validate should have failed") | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
Copyright IBM Corp. 2017 All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package config | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestConsortiums(t *testing.T) { | ||
|
||
csg := NewConsortiumsGroup() | ||
cg, err := csg.NewGroup("testCG") | ||
assert.NoError(t, err, "NewGroup shuld not have returned error") | ||
_, ok := cg.(*ConsortiumGroup) | ||
assert.Equal(t, true, ok, "NewGroup should have returned a ConsortiumGroup") | ||
|
||
csc := csg.Allocate() | ||
_, ok = csc.(*ConsortiumsConfig) | ||
assert.Equal(t, true, ok, "Allocate should have returned a ConsortiumsConfig") | ||
|
||
csc.Commit() | ||
assert.Equal(t, csc, csg.ConsortiumsConfig, "Failed to commit ConsortiumsConfig") | ||
|
||
err = csc.Validate(t, map[string]ValueProposer{ | ||
"badGroup": &OrganizationGroup{}, | ||
}) | ||
assert.Error(t, err, "Validate should have returned error for wrong type of ValueProposer") | ||
err = csc.Validate(t, map[string]ValueProposer{ | ||
"testGroup": cg, | ||
}) | ||
assert.NoError(t, err, "Validate should not have returned error") | ||
assert.Equal(t, cg, csc.(*ConsortiumsConfig).Consortiums()["testGroup"], | ||
"Expected consortium groups to be the same") | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.