Skip to content

Commit

Permalink
Refactor API chaining to remove UpdatedConfig and related types
Browse files Browse the repository at this point in the history
FAB-17744

Signed-off-by: Will Lahti <[email protected]>
  • Loading branch information
wlahti committed May 4, 2020
1 parent 57e4825 commit 7202497
Show file tree
Hide file tree
Showing 14 changed files with 368 additions and 592 deletions.
174 changes: 54 additions & 120 deletions configtx/application.go

Large diffs are not rendered by default.

63 changes: 31 additions & 32 deletions configtx/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,13 @@ func TestAddAnchorPeer(t *testing.T) {
err = protolator.DeepUnmarshalJSON(bytes.NewBufferString(expectedUpdatedConfigJSON), expectedUpdatedConfig)
gt.Expect(err).ToNot(HaveOccurred())

err = c.UpdatedConfig().Application().Organization("Org1").AddAnchorPeer(newOrg1AnchorPeer)
err = c.Application().Organization("Org1").AddAnchorPeer(newOrg1AnchorPeer)
gt.Expect(err).NotTo(HaveOccurred())

err = c.UpdatedConfig().Application().Organization("Org2").AddAnchorPeer(newOrg2AnchorPeer)
err = c.Application().Organization("Org2").AddAnchorPeer(newOrg2AnchorPeer)
gt.Expect(err).NotTo(HaveOccurred())

gt.Expect(proto.Equal(c.UpdatedConfig().Config, expectedUpdatedConfig)).To(BeTrue())
gt.Expect(proto.Equal(c.updated, expectedUpdatedConfig)).To(BeTrue())
}

func TestRemoveAnchorPeer(t *testing.T) {
Expand Down Expand Up @@ -484,17 +484,18 @@ func TestRemoveAnchorPeer(t *testing.T) {
`

anchorPeer1 := Address{Host: "host1", Port: 123}
err = c.UpdatedConfig().Application().Organization("Org1").AddAnchorPeer(anchorPeer1)
applicationOrg1 := c.Application().Organization("Org1")
err = applicationOrg1.AddAnchorPeer(anchorPeer1)
gt.Expect(err).NotTo(HaveOccurred())
expectedUpdatedConfig := &cb.Config{}

err = protolator.DeepUnmarshalJSON(bytes.NewBufferString(expectedUpdatedConfigJSON), expectedUpdatedConfig)
gt.Expect(err).NotTo(HaveOccurred())

err = c.UpdatedConfig().Application().Organization("Org1").RemoveAnchorPeer(anchorPeer1)
err = applicationOrg1.RemoveAnchorPeer(anchorPeer1)
gt.Expect(err).NotTo(HaveOccurred())

gt.Expect(proto.Equal(c.UpdatedConfig().Config, expectedUpdatedConfig)).To(BeTrue())
gt.Expect(proto.Equal(c.updated, expectedUpdatedConfig)).To(BeTrue())
}

func TestRemoveAnchorPeerFailure(t *testing.T) {
Expand Down Expand Up @@ -540,7 +541,7 @@ func TestRemoveAnchorPeerFailure(t *testing.T) {

c := New(config)

err = c.UpdatedConfig().Application().Organization(tt.orgName).RemoveAnchorPeer(tt.anchorPeerToRemove)
err = c.Application().Organization(tt.orgName).RemoveAnchorPeer(tt.anchorPeerToRemove)
gt.Expect(err).To(MatchError(tt.expectedErr))
})
}
Expand All @@ -563,24 +564,24 @@ func TestAnchorPeers(t *testing.T) {

c := New(config)

anchorPeers, err := c.UpdatedConfig().Application().Organization("Org1").AnchorPeers()
anchorPeers, err := c.Application().Organization("Org1").AnchorPeers()
gt.Expect(err).NotTo(HaveOccurred())
gt.Expect(anchorPeers).To(BeNil())
gt.Expect(anchorPeers).To(HaveLen(0))

expectedAnchorPeer := Address{Host: "host1", Port: 123}
err = c.UpdatedConfig().Application().Organization("Org1").AddAnchorPeer(expectedAnchorPeer)
err = c.Application().Organization("Org1").AddAnchorPeer(expectedAnchorPeer)
gt.Expect(err).NotTo(HaveOccurred())

anchorPeers, err = c.UpdatedConfig().Application().Organization("Org1").AnchorPeers()
anchorPeers, err = c.Application().Organization("Org1").AnchorPeers()
gt.Expect(err).NotTo(HaveOccurred())
gt.Expect(anchorPeers).To(HaveLen(1))
gt.Expect(anchorPeers[0]).To(Equal(expectedAnchorPeer))

err = c.UpdatedConfig().Application().Organization("Org1").RemoveAnchorPeer(expectedAnchorPeer)
err = c.Application().Organization("Org1").RemoveAnchorPeer(expectedAnchorPeer)
gt.Expect(err).NotTo(HaveOccurred())

anchorPeers, err = c.UpdatedConfig().Application().Organization("Org1").AnchorPeers()
anchorPeers, err = c.Application().Organization("Org1").AnchorPeers()
gt.Expect(err).NotTo(HaveOccurred())
gt.Expect(anchorPeers).To(BeNil())
gt.Expect(anchorPeers).To(HaveLen(0))
Expand Down Expand Up @@ -628,24 +629,24 @@ func TestSetACL(t *testing.T) {
config := &cb.Config{
ChannelGroup: channelGroup,
}
expectedOriginalACL := map[string]string{"acl1": "hi"}
// expectedOriginalACL := map[string]string{"acl1": "hi"}
if tt.configMod != nil {
tt.configMod(config)
}
c := New(config)

err = c.UpdatedConfig().Application().SetACLs(tt.newACL)
err = c.Application().SetACLs(tt.newACL)
if tt.expectedErr != "" {
gt.Expect(err).To(MatchError(tt.expectedErr))
} else {
gt.Expect(err).NotTo(HaveOccurred())
acls, err := c.UpdatedConfig().Application().ACLs()
acls, err := c.Application().ACLs()
gt.Expect(err).NotTo(HaveOccurred())
gt.Expect(acls).To(Equal(tt.expectedACL))

originalACLs, err := c.OriginalConfig().Application().ACLs()
gt.Expect(err).NotTo(HaveOccurred())
gt.Expect(originalACLs).To(Equal(expectedOriginalACL))
// originalACLs, err := c.OriginalConfig().Application().ACLs()
// gt.Expect(err).NotTo(HaveOccurred())
// gt.Expect(originalACLs).To(Equal(expectedOriginalACL))
}
})
}
Expand Down Expand Up @@ -703,12 +704,12 @@ func TestRemoveACL(t *testing.T) {

c := New(config)

err = c.UpdatedConfig().Application().RemoveACLs(tt.removeACL)
err = c.Application().RemoveACLs(tt.removeACL)
if tt.expectedErr != "" {
gt.Expect(err).To(MatchError(tt.expectedErr))
} else {
gt.Expect(err).NotTo(HaveOccurred())
acls, err := c.UpdatedConfig().Application().ACLs()
acls, err := c.Application().ACLs()
gt.Expect(err).NotTo(HaveOccurred())
gt.Expect(acls).To(Equal(tt.expectedACL))
}
Expand Down Expand Up @@ -890,10 +891,10 @@ func TestSetApplicationOrg(t *testing.T) {
}
`, certBase64, crlBase64, pkBase64)

err = c.UpdatedConfig().Application().SetOrganization(org)
err = c.Application().SetOrganization(org)
gt.Expect(err).NotTo(HaveOccurred())

actualApplicationConfigGroup := c.UpdatedConfig().ChannelGroup.Groups[ApplicationGroupKey].Groups["Org3"]
actualApplicationConfigGroup := c.Application().Organization("Org3").orgGroup
buf := bytes.Buffer{}
err = protolator.DeepMarshalJSON(&buf, &peerext.DynamicApplicationOrgGroup{ConfigGroup: actualApplicationConfigGroup})
gt.Expect(err).NotTo(HaveOccurred())
Expand Down Expand Up @@ -922,7 +923,7 @@ func TestSetApplicationOrgFailures(t *testing.T) {
Name: "Org3",
}

err = c.UpdatedConfig().Application().SetOrganization(org)
err = c.Application().SetOrganization(org)
gt.Expect(err).To(MatchError("failed to create application org Org3: no policies defined"))
}

Expand All @@ -945,13 +946,11 @@ func TestApplicationConfiguration(t *testing.T) {
c := New(config)

for _, org := range baseApplicationConf.Organizations {
err = c.UpdatedConfig().Application().SetOrganization(org)
err = c.Application().SetOrganization(org)
gt.Expect(err).NotTo(HaveOccurred())
}

c = New(c.UpdatedConfig().Config)

applicationConfig, err := c.OriginalConfig().Application().Configuration()
applicationConfig, err := c.Application().Configuration()
gt.Expect(err).NotTo(HaveOccurred())
gt.Expect(applicationConfig.ACLs).To(Equal(baseApplicationConf.ACLs))
gt.Expect(applicationConfig.Capabilities).To(Equal(baseApplicationConf.Capabilities))
Expand All @@ -972,7 +971,7 @@ func TestApplicationConfigurationFailure(t *testing.T) {
configMod: func(c ConfigTx, appOrg Application, gt *GomegaWithT) {
for _, org := range appOrg.Organizations {
if org.Name == "Org2" {
err := c.UpdatedConfig().Application().SetOrganization(org)
err := c.Application().SetOrganization(org)
gt.Expect(err).NotTo(HaveOccurred())
}
}
Expand Down Expand Up @@ -1005,9 +1004,9 @@ func TestApplicationConfigurationFailure(t *testing.T) {
tt.configMod(c, baseApplicationConf, gt)
}

c = New(c.UpdatedConfig().Config)
c = New(c.updated)

_, err = c.OriginalConfig().Application().Configuration()
_, err = c.Application().Configuration()
gt.Expect(err).To(MatchError(tt.expectedErr))
})
}
Expand All @@ -1032,7 +1031,7 @@ func TestApplicationACLs(t *testing.T) {

c := New(config)

applicationACLs, err := c.UpdatedConfig().Application().ACLs()
applicationACLs, err := c.Application().ACLs()
gt.Expect(err).NotTo(HaveOccurred())
gt.Expect(applicationACLs).To(Equal(baseApplicationConf.ACLs))
}
Expand Down Expand Up @@ -1060,7 +1059,7 @@ func TestApplicationACLsFailure(t *testing.T) {

c := New(config)

applicationACLs, err := c.UpdatedConfig().Application().ACLs()
applicationACLs, err := c.Application().ACLs()
gt.Expect(err).To(MatchError("unmarshaling ACLs: unexpected EOF"))
gt.Expect(applicationACLs).To(BeNil())
}
Expand Down
58 changes: 29 additions & 29 deletions configtx/capabilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ func TestChannelCapabilities(t *testing.T) {
},
}

c := New(config)

err := setValue(config.ChannelGroup, capabilitiesValue(expectedCapabilities), AdminsPolicyKey)
gt.Expect(err).NotTo(HaveOccurred())

channelCapabilities, err := c.OriginalConfig().Channel().Capabilities()
c := New(config)

channelCapabilities, err := c.Channel().Capabilities()
gt.Expect(err).NotTo(HaveOccurred())
gt.Expect(channelCapabilities).To(Equal(expectedCapabilities))

// Delete the capabilities key and assert retrieval to return nil
delete(config.ChannelGroup.Values, CapabilitiesKey)
channelCapabilities, err = c.OriginalConfig().Channel().Capabilities()
delete(c.Channel().channelGroup.Values, CapabilitiesKey)
channelCapabilities, err = c.Channel().Capabilities()
gt.Expect(err).NotTo(HaveOccurred())
gt.Expect(channelCapabilities).To(BeNil())
}
Expand All @@ -67,13 +67,13 @@ func TestOrdererCapabilities(t *testing.T) {

c := New(config)

ordererCapabilities, err := c.OriginalConfig().Orderer().Capabilities()
ordererCapabilities, err := c.Orderer().Capabilities()
gt.Expect(err).NotTo(HaveOccurred())
gt.Expect(ordererCapabilities).To(Equal(baseOrdererConf.Capabilities))

// Delete the capabilities key and assert retrieval to return nil
delete(c.OriginalConfig().Orderer().ordererGroup.Values, CapabilitiesKey)
ordererCapabilities, err = c.OriginalConfig().Orderer().Capabilities()
delete(c.Orderer().ordererGroup.Values, CapabilitiesKey)
ordererCapabilities, err = c.Orderer().Capabilities()
gt.Expect(err).NotTo(HaveOccurred())
gt.Expect(ordererCapabilities).To(BeNil())
}
Expand All @@ -97,13 +97,13 @@ func TestApplicationCapabilities(t *testing.T) {

c := New(config)

applicationCapabilities, err := c.OriginalConfig().Application().Capabilities()
applicationCapabilities, err := c.Application().Capabilities()
gt.Expect(err).NotTo(HaveOccurred())
gt.Expect(applicationCapabilities).To(Equal(baseApplicationConf.Capabilities))

// Delete the capabilities key and assert retrieval to return nil
delete(config.ChannelGroup.Groups[ApplicationGroupKey].Values, CapabilitiesKey)
applicationCapabilities, err = c.OriginalConfig().Application().Capabilities()
delete(c.Application().applicationGroup.Values, CapabilitiesKey)
applicationCapabilities, err = c.Application().Capabilities()
gt.Expect(err).NotTo(HaveOccurred())
gt.Expect(applicationCapabilities).To(BeNil())
}
Expand Down Expand Up @@ -142,11 +142,11 @@ func TestSetChannelCapability(t *testing.T) {
}
`

err := c.UpdatedConfig().Channel().AddCapability("V3_0")
err := c.Channel().AddCapability("V3_0")
gt.Expect(err).NotTo(HaveOccurred())

buf := bytes.Buffer{}
err = protolator.DeepMarshalJSON(&buf, &commonext.DynamicChannelGroup{ConfigGroup: c.UpdatedConfig().ChannelGroup})
err = protolator.DeepMarshalJSON(&buf, &commonext.DynamicChannelGroup{ConfigGroup: c.Channel().channelGroup})
gt.Expect(err).NotTo(HaveOccurred())

gt.Expect(buf.String()).To(Equal(expectedConfigGroupJSON))
Expand Down Expand Up @@ -186,7 +186,7 @@ func TestSetChannelCapabilityFailures(t *testing.T) {

c := New(tt.config)

err := c.UpdatedConfig().Channel().AddCapability(tt.capability)
err := c.Channel().AddCapability(tt.capability)
gt.Expect(err).To(MatchError(tt.expectedErr))
})
}
Expand Down Expand Up @@ -437,11 +437,11 @@ func TestAddOrdererCapability(t *testing.T) {
`, orgCertBase64, orgCRLBase64, orgPKBase64)

capability := "V3_0"
err = c.UpdatedConfig().Orderer().AddCapability(capability)
err = c.Orderer().AddCapability(capability)
gt.Expect(err).NotTo(HaveOccurred())

buf := bytes.Buffer{}
err = protolator.DeepMarshalJSON(&buf, &ordererext.DynamicOrdererGroup{ConfigGroup: c.UpdatedConfig().Orderer().ordererGroup})
err = protolator.DeepMarshalJSON(&buf, &ordererext.DynamicOrdererGroup{ConfigGroup: c.Orderer().ordererGroup})
gt.Expect(err).NotTo(HaveOccurred())

gt.Expect(buf.String()).To(Equal(expectedConfigGroupJSON))
Expand Down Expand Up @@ -492,7 +492,7 @@ func TestAddOrdererCapabilityFailures(t *testing.T) {

c := New(config)

err = c.UpdatedConfig().Orderer().AddCapability(tt.capability)
err = c.Orderer().AddCapability(tt.capability)
gt.Expect(err).To(MatchError(tt.expectedErr))
})
}
Expand Down Expand Up @@ -696,14 +696,14 @@ func TestAddApplicationCapability(t *testing.T) {

c := New(config)

err = c.UpdatedConfig().Application().AddCapability(tt.capability)
err = c.Application().AddCapability(tt.capability)
gt.Expect(err).NotTo(HaveOccurred())

updatedApplicationGroupJSON := bytes.Buffer{}
err = protolator.DeepMarshalJSON(&updatedApplicationGroupJSON, &peerext.DynamicApplicationGroup{ConfigGroup: c.UpdatedConfig().ChannelGroup.Groups[ApplicationGroupKey]})
err = protolator.DeepMarshalJSON(&updatedApplicationGroupJSON, &peerext.DynamicApplicationGroup{ConfigGroup: c.Application().applicationGroup})
gt.Expect(err).NotTo(HaveOccurred())
originalApplicationGroupJSON := bytes.Buffer{}
err = protolator.DeepMarshalJSON(&originalApplicationGroupJSON, &peerext.DynamicApplicationGroup{ConfigGroup: c.OriginalConfig().ChannelGroup.Groups[ApplicationGroupKey]})
err = protolator.DeepMarshalJSON(&originalApplicationGroupJSON, &peerext.DynamicApplicationGroup{ConfigGroup: c.original.ChannelGroup.Groups[ApplicationGroupKey]})
gt.Expect(err).NotTo(HaveOccurred())

gt.Expect(updatedApplicationGroupJSON.String()).To(Equal(tt.expectedConfigGroupJSON))
Expand Down Expand Up @@ -761,7 +761,7 @@ func TestAddApplicationCapabilityFailures(t *testing.T) {

c := New(config)

err = c.UpdatedConfig().Application().AddCapability(tt.capability)
err = c.Application().AddCapability(tt.capability)
gt.Expect(err).To(MatchError(tt.expectedErr))
})
}
Expand Down Expand Up @@ -804,11 +804,11 @@ func TestRemoveChannelCapability(t *testing.T) {
}
`

err := c.UpdatedConfig().Channel().RemoveCapability("V3_0")
err := c.Channel().RemoveCapability("V3_0")
gt.Expect(err).NotTo(HaveOccurred())

buf := bytes.Buffer{}
err = protolator.DeepMarshalJSON(&buf, &commonext.DynamicChannelGroup{ConfigGroup: c.UpdatedConfig().ChannelGroup})
err = protolator.DeepMarshalJSON(&buf, &commonext.DynamicChannelGroup{ConfigGroup: c.Channel().channelGroup})
gt.Expect(err).NotTo(HaveOccurred())

gt.Expect(buf.String()).To(Equal(expectedConfigGroupJSON))
Expand Down Expand Up @@ -862,7 +862,7 @@ func TestRemoveChannelCapabilityFailures(t *testing.T) {

c := New(tt.config)

err := c.UpdatedConfig().Channel().RemoveCapability(tt.capability)
err := c.Channel().RemoveCapability(tt.capability)
gt.Expect(err).To(MatchError(tt.expectedErr))
})
}
Expand Down Expand Up @@ -1110,11 +1110,11 @@ func TestRemoveOrdererCapability(t *testing.T) {
`, orgCertBase64, orgCRLBase64, orgPKBase64)

capability := "V1_3"
err = c.UpdatedConfig().Orderer().RemoveCapability(capability)
err = c.Orderer().RemoveCapability(capability)
gt.Expect(err).NotTo(HaveOccurred())

buf := bytes.Buffer{}
err = protolator.DeepMarshalJSON(&buf, &ordererext.DynamicOrdererGroup{ConfigGroup: c.UpdatedConfig().Orderer().ordererGroup})
err = protolator.DeepMarshalJSON(&buf, &ordererext.DynamicOrdererGroup{ConfigGroup: c.Orderer().ordererGroup})
gt.Expect(err).NotTo(HaveOccurred())

gt.Expect(buf.String()).To(Equal(expectedConfigGroupJSON))
Expand Down Expand Up @@ -1172,7 +1172,7 @@ func TestRemoveOrdererCapabilityFailures(t *testing.T) {

c := New(config)

err = c.UpdatedConfig().Orderer().RemoveCapability(tt.capability)
err = c.Orderer().RemoveCapability(tt.capability)
gt.Expect(err).To(MatchError(tt.expectedErr))
})
}
Expand Down Expand Up @@ -1274,7 +1274,7 @@ func TestRemoveApplicationCapability(t *testing.T) {
}
`
capability := "V1_3"
err = c.UpdatedConfig().Application().RemoveCapability(capability)
err = c.Application().RemoveCapability(capability)
gt.Expect(err).NotTo(HaveOccurred())

buf := bytes.Buffer{}
Expand Down Expand Up @@ -1336,7 +1336,7 @@ func TestRemoveApplicationCapabilityFailures(t *testing.T) {

c := New(config)

err = c.UpdatedConfig().Application().RemoveCapability(tt.capability)
err = c.Application().RemoveCapability(tt.capability)
gt.Expect(err).To(MatchError(tt.expectedErr))
})
}
Expand Down
Loading

0 comments on commit 7202497

Please sign in to comment.