Unverified Commit df3ef22a authored by Jason Yellick's avatar Jason Yellick Committed by Artem Barger
Browse files

FAB-14035 Add tests for configtxgen encoder



The tests currently covering the configtxgen encoder are almost entirely
based on sample config and really cover almost none of the non-green
paths.  This CR simply replaces all of the existing test with a new
ginkgo suite covering 98.4% of lines.  The uncovered lines are
unreachable and will be removed in a later CR.

Change-Id: I2d2bfd7f4437511258a7832a7df0735fab2a2fbf
Signed-off-by: default avatarJason Yellick <jyellick@us.ibm.com>
parent f7f806fd
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package encoder_test
import (
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/hyperledger/fabric/common/crypto"
)
//go:generate counterfeiter -o mock/local_signer.go --fake-name LocalSigner . localSigner
type localSigner interface {
crypto.LocalSigner
}
func TestEncoder(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Encoder Suite")
}
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package encoder_test
import (
"fmt"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/hyperledger/fabric/common/channelconfig"
"github.com/hyperledger/fabric/common/tools/configtxgen/configtxgentest"
"github.com/hyperledger/fabric/common/tools/configtxgen/encoder"
genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig"
cb "github.com/hyperledger/fabric/protos/common"
"github.com/pkg/errors"
)
func hasModPolicySet(groupName string, cg *cb.ConfigGroup) error {
if cg.ModPolicy == "" {
return errors.Errorf("group %s has empty mod_policy", groupName)
}
for valueName, value := range cg.Values {
if value.ModPolicy == "" {
return errors.Errorf("group %s has value %s with empty mod_policy", groupName, valueName)
}
}
for policyName, policy := range cg.Policies {
if policy.ModPolicy == "" {
return errors.Errorf("group %s has policy %s with empty mod_policy", groupName, policyName)
}
}
for groupName, group := range cg.Groups {
err := hasModPolicySet(groupName, group)
if err != nil {
return errors.WithMessage(err, fmt.Sprintf("missing sub-mod_policy for group %s", groupName))
}
}
return nil
}
var _ = Describe("Integration", func() {
for _, profile := range []string{
genesisconfig.SampleInsecureSoloProfile,
genesisconfig.SampleSingleMSPSoloProfile,
genesisconfig.SampleDevModeSoloProfile,
genesisconfig.SampleInsecureKafkaProfile,
genesisconfig.SampleSingleMSPKafkaProfile,
genesisconfig.SampleDevModeKafkaProfile,
} {
It(fmt.Sprintf("successfully parses the %s profile", profile), func() {
config := configtxgentest.Load(profile)
group, err := encoder.NewChannelGroup(config)
Expect(err).NotTo(HaveOccurred())
_, err = channelconfig.NewBundle("test", &cb.Config{
ChannelGroup: group,
})
Expect(err).NotTo(HaveOccurred())
err = hasModPolicySet("Channel", group)
Expect(err).NotTo(HaveOccurred())
})
}
})
// Code generated by counterfeiter. DO NOT EDIT.
package mock
import (
"sync"
cb "github.com/hyperledger/fabric/protos/common"
)
type LocalSigner struct {
NewSignatureHeaderStub func() (*cb.SignatureHeader, error)
newSignatureHeaderMutex sync.RWMutex
newSignatureHeaderArgsForCall []struct{}
newSignatureHeaderReturns struct {
result1 *cb.SignatureHeader
result2 error
}
newSignatureHeaderReturnsOnCall map[int]struct {
result1 *cb.SignatureHeader
result2 error
}
SignStub func(message []byte) ([]byte, error)
signMutex sync.RWMutex
signArgsForCall []struct {
message []byte
}
signReturns struct {
result1 []byte
result2 error
}
signReturnsOnCall map[int]struct {
result1 []byte
result2 error
}
invocations map[string][][]interface{}
invocationsMutex sync.RWMutex
}
func (fake *LocalSigner) NewSignatureHeader() (*cb.SignatureHeader, error) {
fake.newSignatureHeaderMutex.Lock()
ret, specificReturn := fake.newSignatureHeaderReturnsOnCall[len(fake.newSignatureHeaderArgsForCall)]
fake.newSignatureHeaderArgsForCall = append(fake.newSignatureHeaderArgsForCall, struct{}{})
fake.recordInvocation("NewSignatureHeader", []interface{}{})
fake.newSignatureHeaderMutex.Unlock()
if fake.NewSignatureHeaderStub != nil {
return fake.NewSignatureHeaderStub()
}
if specificReturn {
return ret.result1, ret.result2
}
return fake.newSignatureHeaderReturns.result1, fake.newSignatureHeaderReturns.result2
}
func (fake *LocalSigner) NewSignatureHeaderCallCount() int {
fake.newSignatureHeaderMutex.RLock()
defer fake.newSignatureHeaderMutex.RUnlock()
return len(fake.newSignatureHeaderArgsForCall)
}
func (fake *LocalSigner) NewSignatureHeaderReturns(result1 *cb.SignatureHeader, result2 error) {
fake.NewSignatureHeaderStub = nil
fake.newSignatureHeaderReturns = struct {
result1 *cb.SignatureHeader
result2 error
}{result1, result2}
}
func (fake *LocalSigner) NewSignatureHeaderReturnsOnCall(i int, result1 *cb.SignatureHeader, result2 error) {
fake.NewSignatureHeaderStub = nil
if fake.newSignatureHeaderReturnsOnCall == nil {
fake.newSignatureHeaderReturnsOnCall = make(map[int]struct {
result1 *cb.SignatureHeader
result2 error
})
}
fake.newSignatureHeaderReturnsOnCall[i] = struct {
result1 *cb.SignatureHeader
result2 error
}{result1, result2}
}
func (fake *LocalSigner) Sign(message []byte) ([]byte, error) {
var messageCopy []byte
if message != nil {
messageCopy = make([]byte, len(message))
copy(messageCopy, message)
}
fake.signMutex.Lock()
ret, specificReturn := fake.signReturnsOnCall[len(fake.signArgsForCall)]
fake.signArgsForCall = append(fake.signArgsForCall, struct {
message []byte
}{messageCopy})
fake.recordInvocation("Sign", []interface{}{messageCopy})
fake.signMutex.Unlock()
if fake.SignStub != nil {
return fake.SignStub(message)
}
if specificReturn {
return ret.result1, ret.result2
}
return fake.signReturns.result1, fake.signReturns.result2
}
func (fake *LocalSigner) SignCallCount() int {
fake.signMutex.RLock()
defer fake.signMutex.RUnlock()
return len(fake.signArgsForCall)
}
func (fake *LocalSigner) SignArgsForCall(i int) []byte {
fake.signMutex.RLock()
defer fake.signMutex.RUnlock()
return fake.signArgsForCall[i].message
}
func (fake *LocalSigner) SignReturns(result1 []byte, result2 error) {
fake.SignStub = nil
fake.signReturns = struct {
result1 []byte
result2 error
}{result1, result2}
}
func (fake *LocalSigner) SignReturnsOnCall(i int, result1 []byte, result2 error) {
fake.SignStub = nil
if fake.signReturnsOnCall == nil {
fake.signReturnsOnCall = make(map[int]struct {
result1 []byte
result2 error
})
}
fake.signReturnsOnCall[i] = struct {
result1 []byte
result2 error
}{result1, result2}
}
func (fake *LocalSigner) Invocations() map[string][][]interface{} {
fake.invocationsMutex.RLock()
defer fake.invocationsMutex.RUnlock()
fake.newSignatureHeaderMutex.RLock()
defer fake.newSignatureHeaderMutex.RUnlock()
fake.signMutex.RLock()
defer fake.signMutex.RUnlock()
copiedInvocations := map[string][][]interface{}{}
for key, value := range fake.invocations {
copiedInvocations[key] = value
}
return copiedInvocations
}
func (fake *LocalSigner) recordInvocation(key string, args []interface{}) {
fake.invocationsMutex.Lock()
defer fake.invocationsMutex.Unlock()
if fake.invocations == nil {
fake.invocations = map[string][][]interface{}{}
}
if fake.invocations[key] == nil {
fake.invocations[key] = [][]interface{}{}
}
fake.invocations[key] = append(fake.invocations[key], args)
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment