-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-14534] add type checking in tests
By declaring unnamed variables of the expected interface, we can ensure we've implemented all of the required methods of the intended protolator interface. This activity did catch one messing method on DynamicConsortiumConfigValue. Also cleaned up copy pasta in godoc for the protolator interfaces and switched from assert.Equal to gomega MatchJSON to improve the data reported during test failures and reduce the likelihood of a test failure due to changing the order of fields in the JSON. Change-Id: I404e7cfb05963f50a3053c11e80ea085e3561b00 Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
- Loading branch information
Showing
10 changed files
with
189 additions
and
31 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
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
50 changes: 50 additions & 0 deletions
50
common/tools/protolator/protoext/commonext/commonext_test.go
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. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package commonext_test | ||
|
||
import ( | ||
"github.com/hyperledger/fabric/common/tools/protolator" | ||
"github.com/hyperledger/fabric/common/tools/protolator/protoext/commonext" | ||
) | ||
|
||
// ensure structs implement expected interfaces | ||
var ( | ||
_ protolator.StaticallyOpaqueFieldProto = &commonext.Envelope{} | ||
_ protolator.DecoratedProto = &commonext.Envelope{} | ||
_ protolator.VariablyOpaqueFieldProto = &commonext.Payload{} | ||
_ protolator.DecoratedProto = &commonext.Payload{} | ||
_ protolator.StaticallyOpaqueFieldProto = &commonext.Header{} | ||
_ protolator.DecoratedProto = &commonext.Header{} | ||
_ protolator.StaticallyOpaqueFieldProto = &commonext.SignatureHeader{} | ||
_ protolator.DecoratedProto = &commonext.SignatureHeader{} | ||
_ protolator.StaticallyOpaqueSliceFieldProto = &commonext.BlockData{} | ||
_ protolator.DecoratedProto = &commonext.BlockData{} | ||
|
||
_ protolator.StaticallyOpaqueFieldProto = &commonext.ConfigUpdateEnvelope{} | ||
_ protolator.DecoratedProto = &commonext.ConfigUpdateEnvelope{} | ||
_ protolator.StaticallyOpaqueFieldProto = &commonext.ConfigSignature{} | ||
_ protolator.DecoratedProto = &commonext.ConfigSignature{} | ||
_ protolator.DynamicFieldProto = &commonext.Config{} | ||
_ protolator.DecoratedProto = &commonext.Config{} | ||
_ protolator.StaticallyOpaqueMapFieldProto = &commonext.ConfigUpdate{} | ||
_ protolator.DecoratedProto = &commonext.ConfigUpdate{} | ||
|
||
_ protolator.DynamicMapFieldProto = &commonext.DynamicChannelGroup{} | ||
_ protolator.DecoratedProto = &commonext.DynamicChannelGroup{} | ||
_ protolator.StaticallyOpaqueFieldProto = &commonext.DynamicChannelConfigValue{} | ||
_ protolator.DecoratedProto = &commonext.DynamicChannelConfigValue{} | ||
_ protolator.DynamicMapFieldProto = &commonext.DynamicConsortiumsGroup{} | ||
_ protolator.DecoratedProto = &commonext.DynamicConsortiumsGroup{} | ||
_ protolator.DynamicMapFieldProto = &commonext.DynamicConsortiumGroup{} | ||
_ protolator.DecoratedProto = &commonext.DynamicConsortiumGroup{} | ||
_ protolator.VariablyOpaqueFieldProto = &commonext.DynamicConsortiumConfigValue{} | ||
_ protolator.DecoratedProto = &commonext.DynamicConsortiumConfigValue{} | ||
_ protolator.DynamicMapFieldProto = &commonext.DynamicConsortiumOrgGroup{} | ||
_ protolator.DecoratedProto = &commonext.DynamicConsortiumOrgGroup{} | ||
_ protolator.StaticallyOpaqueFieldProto = &commonext.DynamicConsortiumOrgConfigValue{} | ||
_ protolator.DecoratedProto = &commonext.DynamicConsortiumOrgConfigValue{} | ||
) |
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
22 changes: 22 additions & 0 deletions
22
common/tools/protolator/protoext/ledger/rwsetext/rwsetext_test.go
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,22 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package rwsetext_test | ||
|
||
import ( | ||
"github.com/hyperledger/fabric/common/tools/protolator" | ||
"github.com/hyperledger/fabric/common/tools/protolator/protoext/ledger/rwsetext" | ||
) | ||
|
||
// ensure structs implement expected interfaces | ||
var ( | ||
_ protolator.DynamicSliceFieldProto = &rwsetext.TxReadWriteSet{} | ||
_ protolator.DecoratedProto = &rwsetext.TxReadWriteSet{} | ||
_ protolator.StaticallyOpaqueFieldProto = &rwsetext.DynamicNsReadWriteSet{} | ||
_ protolator.DecoratedProto = &rwsetext.DynamicNsReadWriteSet{} | ||
_ protolator.StaticallyOpaqueFieldProto = &rwsetext.DynamicCollectionHashedReadWriteSet{} | ||
_ protolator.DecoratedProto = &rwsetext.DynamicCollectionHashedReadWriteSet{} | ||
) |
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,21 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package mspext_test | ||
|
||
import ( | ||
"github.com/hyperledger/fabric/common/tools/protolator" | ||
"github.com/hyperledger/fabric/common/tools/protolator/protoext/mspext" | ||
) | ||
|
||
// ensure structs implement expected interfaces | ||
var ( | ||
_ protolator.VariablyOpaqueFieldProto = &mspext.MSPConfig{} | ||
_ protolator.DecoratedProto = &mspext.MSPConfig{} | ||
|
||
_ protolator.VariablyOpaqueFieldProto = &mspext.MSPPrincipal{} | ||
_ protolator.DecoratedProto = &mspext.MSPPrincipal{} | ||
) |
26 changes: 26 additions & 0 deletions
26
common/tools/protolator/protoext/ordererext/ordererext_test.go
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,26 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package ordererext_test | ||
|
||
import ( | ||
"github.com/hyperledger/fabric/common/tools/protolator" | ||
"github.com/hyperledger/fabric/common/tools/protolator/protoext/ordererext" | ||
) | ||
|
||
// ensure structs implement expected interfaces | ||
var ( | ||
_ protolator.DynamicMapFieldProto = &ordererext.DynamicOrdererGroup{} | ||
_ protolator.DecoratedProto = &ordererext.DynamicOrdererGroup{} | ||
_ protolator.VariablyOpaqueFieldProto = &ordererext.ConsensusType{} | ||
_ protolator.DecoratedProto = &ordererext.ConsensusType{} | ||
_ protolator.DynamicMapFieldProto = &ordererext.DynamicOrdererOrgGroup{} | ||
_ protolator.DecoratedProto = &ordererext.DynamicOrdererOrgGroup{} | ||
_ protolator.StaticallyOpaqueFieldProto = &ordererext.DynamicOrdererConfigValue{} | ||
_ protolator.DecoratedProto = &ordererext.DynamicOrdererConfigValue{} | ||
_ protolator.StaticallyOpaqueFieldProto = &ordererext.DynamicOrdererOrgConfigValue{} | ||
_ protolator.DecoratedProto = &ordererext.DynamicOrdererOrgConfigValue{} | ||
) |
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,39 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package peerext_test | ||
|
||
import ( | ||
"github.com/hyperledger/fabric/common/tools/protolator" | ||
"github.com/hyperledger/fabric/common/tools/protolator/protoext/peerext" | ||
) | ||
|
||
// ensure structs implement expected interfaces | ||
var ( | ||
_ protolator.DynamicMapFieldProto = &peerext.DynamicApplicationGroup{} | ||
_ protolator.DecoratedProto = &peerext.DynamicApplicationGroup{} | ||
_ protolator.DynamicMapFieldProto = &peerext.DynamicApplicationOrgGroup{} | ||
_ protolator.DecoratedProto = &peerext.DynamicApplicationOrgGroup{} | ||
_ protolator.StaticallyOpaqueFieldProto = &peerext.DynamicApplicationConfigValue{} | ||
_ protolator.DecoratedProto = &peerext.DynamicApplicationConfigValue{} | ||
_ protolator.StaticallyOpaqueFieldProto = &peerext.DynamicApplicationOrgConfigValue{} | ||
_ protolator.DecoratedProto = &peerext.DynamicApplicationOrgConfigValue{} | ||
|
||
_ protolator.StaticallyOpaqueFieldProto = &peerext.ChaincodeProposalPayload{} | ||
_ protolator.DecoratedProto = &peerext.ChaincodeProposalPayload{} | ||
_ protolator.StaticallyOpaqueFieldProto = &peerext.ChaincodeAction{} | ||
_ protolator.DecoratedProto = &peerext.ChaincodeAction{} | ||
|
||
_ protolator.StaticallyOpaqueFieldProto = &peerext.ProposalResponsePayload{} | ||
_ protolator.DecoratedProto = &peerext.ProposalResponsePayload{} | ||
|
||
_ protolator.StaticallyOpaqueFieldProto = &peerext.TransactionAction{} | ||
_ protolator.DecoratedProto = &peerext.TransactionAction{} | ||
_ protolator.StaticallyOpaqueFieldProto = &peerext.ChaincodeActionPayload{} | ||
_ protolator.DecoratedProto = &peerext.ChaincodeActionPayload{} | ||
_ protolator.StaticallyOpaqueFieldProto = &peerext.ChaincodeEndorsedAction{} | ||
_ protolator.DecoratedProto = &peerext.ChaincodeEndorsedAction{} | ||
) |