Skip to content

Commit

Permalink
Simplify chain for consortium
Browse files Browse the repository at this point in the history
Change from c.Consortiums().Consortium() to
c.Consortium().

FAB-17744

Signed-off-by: Will Lahti <[email protected]>
  • Loading branch information
wlahti committed May 9, 2020
1 parent c15af93 commit bcf7f8a
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 23 deletions.
13 changes: 9 additions & 4 deletions configtx/consortiums.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func (c *ConfigTx) Consortiums() *ConsortiumsGroup {
}

// Consortium returns a consortium group from the updated config.
func (c *ConsortiumsGroup) Consortium(name string) *ConsortiumGroup {
consortiumGroup, ok := c.consortiumsGroup.Groups[name]
func (c *ConfigTx) Consortium(name string) *ConsortiumGroup {
consortiumGroup, ok := c.updated.ChannelGroup.Groups[ConsortiumsGroupKey].Groups[name]
if !ok {
return nil
}
Expand All @@ -64,7 +64,7 @@ func (c *ConsortiumsGroup) SetConsortium(consortium Consortium) error {
c.consortiumsGroup.Groups[consortium.Name] = newConfigGroup()

for _, org := range consortium.Organizations {
err := c.Consortium(consortium.Name).SetOrganization(org)
err := c.consortium(consortium.Name).SetOrganization(org)
if err != nil {
return err
}
Expand All @@ -73,6 +73,11 @@ func (c *ConsortiumsGroup) SetConsortium(consortium Consortium) error {
return nil
}

func (c *ConsortiumsGroup) consortium(name string) *ConsortiumGroup {
consortiumGroup := c.consortiumsGroup.Groups[name]
return &ConsortiumGroup{name: name, consortiumGroup: consortiumGroup}
}

// RemoveConsortium removes a consortium from a channel configuration.
// Removal will panic if the consortiums group does not exist.
func (c *ConsortiumsGroup) RemoveConsortium(name string) {
Expand Down Expand Up @@ -114,7 +119,7 @@ func (c *ConsortiumGroup) RemoveOrganization(name string) {
func (c *ConsortiumsGroup) Configuration() ([]Consortium, error) {
consortiums := []Consortium{}
for consortiumName := range c.consortiumsGroup.Groups {
consortium, err := c.Consortium(consortiumName).Configuration()
consortium, err := c.consortium(consortiumName).Configuration()
if err != nil {
return nil, err
}
Expand Down
7 changes: 3 additions & 4 deletions configtx/consortiums_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ func TestSetConsortiumOrg(t *testing.T) {
err = protolator.DeepUnmarshalJSON(bytes.NewBufferString(expectedConfigJSON), expectedConfigProto)
gt.Expect(err).NotTo(HaveOccurred())

err = c.Consortiums().Consortium("Consortium1").SetOrganization(orgToAdd)
err = c.Consortium("Consortium1").SetOrganization(orgToAdd)
gt.Expect(err).NotTo(HaveOccurred())

gt.Expect(proto.Equal(c.updated, expectedConfigProto)).To(BeTrue())
Expand Down Expand Up @@ -797,7 +797,7 @@ func TestSetConsortiumOrgFailures(t *testing.T) {

c := New(config)

err = c.Consortiums().Consortium(test.consortium).SetOrganization(test.org)
err = c.Consortium(test.consortium).SetOrganization(test.org)
gt.Expect(err).To(MatchError(test.expectedErr))
})
}
Expand Down Expand Up @@ -826,8 +826,7 @@ func TestRemoveConsortium(t *testing.T) {

c.Consortiums().RemoveConsortium("Consortium1")

updatedConsortiumsGroup := c.Consortiums()
gt.Expect(updatedConsortiumsGroup.Consortium("Consortium1")).To(BeNil())
gt.Expect(c.Consortium("Consortium1")).To(BeNil())
}

func TestGetConsortiums(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions configtx/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func Example_basic() {
baseConfig := fetchSystemChannelConfig()
c := configtx.New(baseConfig)

err := c.Consortiums().Consortium("SampleConsortium").SetChannelCreationPolicy(
err := c.Consortium("SampleConsortium").SetChannelCreationPolicy(
configtx.Policy{Type: configtx.ImplicitMetaPolicyType,
Rule: "MAJORITY Admins"})
if err != nil {
Expand Down Expand Up @@ -565,7 +565,7 @@ func ExampleConsortiumOrg_SetMSP() {
baseConfig := fetchSystemChannelConfig()
c := configtx.New(baseConfig)

sampleConsortiumOrg1 := c.Consortiums().Consortium("SampleConsortium").Organization("Org1")
sampleConsortiumOrg1 := c.Consortium("SampleConsortium").Organization("Org1")

msp, err := sampleConsortiumOrg1.MSP()
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions configtx/msp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestConsortiumMSP(t *testing.T) {

c := New(config)

msp, err := c.Consortiums().Consortium("Consortium1").Organization("Org1").MSP()
msp, err := c.Consortium("Consortium1").Organization("Org1").MSP()
gt.Expect(err).NotTo(HaveOccurred())
gt.Expect(msp).To(Equal(expectedMSP))
}
Expand Down Expand Up @@ -288,7 +288,7 @@ func TestMSPConfigurationFailures(t *testing.T) {
_, err := c.Orderer().Organization(tt.orgName).MSP()
gt.Expect(err).To(MatchError(tt.expectedErr))
case ConsortiumsGroupKey:
_, err := c.Consortiums().Consortium(tt.consortiumName).Organization(tt.orgName).MSP()
_, err := c.Consortium(tt.consortiumName).Organization(tt.orgName).MSP()
gt.Expect(err).To(MatchError(tt.expectedErr))
default:
t.Fatalf("invalid org type %s", tt.orgType)
Expand Down Expand Up @@ -432,7 +432,7 @@ func TestSetConsortiumMSP(t *testing.T) {
}
c := New(config)

consortium1 := c.Consortiums().Consortium("Consortium1")
consortium1 := c.Consortium("Consortium1")
consortiumOrg1MSP, err := consortium1.Organization("Org1").MSP()
gt.Expect(err).NotTo(HaveOccurred())
consortiumOrg2MSP, err := consortium1.Organization("Org2").MSP()
Expand Down Expand Up @@ -809,7 +809,7 @@ func TestSetConsortiumMSPFailure(t *testing.T) {
}
c := New(config)

consortiumOrg1 := c.Consortiums().Consortium("Consortium1").Organization("Org1")
consortiumOrg1 := c.Consortium("Consortium1").Organization("Org1")
consortiumOrg1MSP, err := consortiumOrg1.MSP()
gt.Expect(err).NotTo(HaveOccurred())

Expand Down
6 changes: 3 additions & 3 deletions configtx/organization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func TestConsortiumOrg(t *testing.T) {
t.Parallel()
gt := NewGomegaWithT(t)

org, err := c.Consortiums().Consortium(tc.consortiumName).Organization(tc.orgName).Configuration()
org, err := c.Consortium(tc.consortiumName).Organization(tc.orgName).Configuration()
if tc.expectedErr != "" {
gt.Expect(Organization{}).To(Equal(org))
gt.Expect(err).To(MatchError(tc.expectedErr))
Expand All @@ -232,8 +232,8 @@ func TestRemoveConsortiumOrg(t *testing.T) {

c := New(config)

c.Consortiums().Consortium("Consortium1").RemoveOrganization("Org1")
gt.Expect(c.Consortiums().Consortium("Consortium1").Organization("Org1")).To(BeNil())
c.Consortium("Consortium1").RemoveOrganization("Org1")
gt.Expect(c.Consortium("Consortium1").Organization("Org1")).To(BeNil())
}

func TestNewOrgConfigGroup(t *testing.T) {
Expand Down
12 changes: 6 additions & 6 deletions configtx/policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ func TestSetConsortiumOrgPolicy(t *testing.T) {
},
}

consortium1Org1 := c.Consortiums().Consortium("Consortium1").Organization("Org1")
consortium1Org1 := c.Consortium("Consortium1").Organization("Org1")
err = consortium1Org1.SetPolicy("TestPolicy", Policy{Type: ImplicitMetaPolicyType, Rule: "MAJORITY Endorsement"})
gt.Expect(err).NotTo(HaveOccurred())

Expand Down Expand Up @@ -410,7 +410,7 @@ func TestSetConsortiumOrgPolicyFailures(t *testing.T) {
expectedErr: "failed to set policy 'TestPolicy' to consortium org 'Org1': unknown policy type: ",
},
} {
err := c.Consortiums().Consortium(test.consortium).Organization(test.org).SetPolicy("TestPolicy", test.policy)
err := c.Consortium(test.consortium).Organization(test.org).SetPolicy("TestPolicy", test.policy)
gt.Expect(err).To(MatchError(test.expectedErr))
}
}
Expand Down Expand Up @@ -456,7 +456,7 @@ func TestRemoveConsortiumOrgPolicy(t *testing.T) {
},
}

consortium1Org1 := c.Consortiums().Consortium("Consortium1").Organization("Org1")
consortium1Org1 := c.Consortium("Consortium1").Organization("Org1")
consortium1Org1.RemovePolicy("TestPolicy")

updatedPolicies, err := consortium1Org1.Policies()
Expand Down Expand Up @@ -788,7 +788,7 @@ func TestSetConsortiumChannelCreationPolicy(t *testing.T) {

updatedPolicy := Policy{Type: ImplicitMetaPolicyType, Rule: "MAJORITY Admins"}

consortium1 := c.Consortiums().Consortium("Consortium1")
consortium1 := c.Consortium("Consortium1")
err = consortium1.SetChannelCreationPolicy(updatedPolicy)
gt.Expect(err).NotTo(HaveOccurred())

Expand Down Expand Up @@ -841,7 +841,7 @@ func TestSetConsortiumChannelCreationPolicyFailures(t *testing.T) {
tt := tt
t.Run(tt.name, func(t *testing.T) {
gt := NewGomegaWithT(t)
err := c.Consortiums().Consortium(tt.consortiumName).SetChannelCreationPolicy(tt.updatedpolicy)
err := c.Consortium(tt.consortiumName).SetChannelCreationPolicy(tt.updatedpolicy)
gt.Expect(err).To(MatchError(tt.expectedErr))
})
}
Expand Down Expand Up @@ -976,7 +976,7 @@ func TestConsortiumOrgPolicies(t *testing.T) {
},
}

policies, err := c.Consortiums().Consortium("Consortium1").Organization("Org1").Policies()
policies, err := c.Consortium("Consortium1").Organization("Org1").Policies()
gt.Expect(err).NotTo(HaveOccurred())
gt.Expect(policies).To(Equal(expectedPolicies))
}

0 comments on commit bcf7f8a

Please sign in to comment.