Commit 9c774de8 authored by Jason Yellick's avatar Jason Yellick
Browse files

FAB-10824 Add ginkgo tests for platforms



This CR deletes the old unit test which was using function pointers to
add indirection in favor of using proper interfaces and mocks.  The old
test coverage was at 85%, while the new ginkgo-ized test coverage brings
us to 100%.

Change-Id: I2e309d239a6eb8f831a3528a4bbe7e4eddec19c8
Signed-off-by: default avatarJason Yellick <jyellick@us.ibm.com>
parent 683c099c
// Code generated by counterfeiter. DO NOT EDIT.
package mock
import (
"archive/tar"
"sync"
)
type PackageWriter struct {
WriteStub func(name string, payload []byte, tw *tar.Writer) error
writeMutex sync.RWMutex
writeArgsForCall []struct {
name string
payload []byte
tw *tar.Writer
}
writeReturns struct {
result1 error
}
writeReturnsOnCall map[int]struct {
result1 error
}
invocations map[string][][]interface{}
invocationsMutex sync.RWMutex
}
func (fake *PackageWriter) Write(name string, payload []byte, tw *tar.Writer) error {
var payloadCopy []byte
if payload != nil {
payloadCopy = make([]byte, len(payload))
copy(payloadCopy, payload)
}
fake.writeMutex.Lock()
ret, specificReturn := fake.writeReturnsOnCall[len(fake.writeArgsForCall)]
fake.writeArgsForCall = append(fake.writeArgsForCall, struct {
name string
payload []byte
tw *tar.Writer
}{name, payloadCopy, tw})
fake.recordInvocation("Write", []interface{}{name, payloadCopy, tw})
fake.writeMutex.Unlock()
if fake.WriteStub != nil {
return fake.WriteStub(name, payload, tw)
}
if specificReturn {
return ret.result1
}
return fake.writeReturns.result1
}
func (fake *PackageWriter) WriteCallCount() int {
fake.writeMutex.RLock()
defer fake.writeMutex.RUnlock()
return len(fake.writeArgsForCall)
}
func (fake *PackageWriter) WriteArgsForCall(i int) (string, []byte, *tar.Writer) {
fake.writeMutex.RLock()
defer fake.writeMutex.RUnlock()
return fake.writeArgsForCall[i].name, fake.writeArgsForCall[i].payload, fake.writeArgsForCall[i].tw
}
func (fake *PackageWriter) WriteReturns(result1 error) {
fake.WriteStub = nil
fake.writeReturns = struct {
result1 error
}{result1}
}
func (fake *PackageWriter) WriteReturnsOnCall(i int, result1 error) {
fake.WriteStub = nil
if fake.writeReturnsOnCall == nil {
fake.writeReturnsOnCall = make(map[int]struct {
result1 error
})
}
fake.writeReturnsOnCall[i] = struct {
result1 error
}{result1}
}
func (fake *PackageWriter) Invocations() map[string][][]interface{} {
fake.invocationsMutex.RLock()
defer fake.invocationsMutex.RUnlock()
fake.writeMutex.RLock()
defer fake.writeMutex.RUnlock()
copiedInvocations := map[string][][]interface{}{}
for key, value := range fake.invocations {
copiedInvocations[key] = value
}
return copiedInvocations
}
func (fake *PackageWriter) 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)
}
// Code generated by counterfeiter. DO NOT EDIT.
package mock
import (
"archive/tar"
"sync"
"github.com/hyperledger/fabric/core/chaincode/platforms/ccmetadata"
pb "github.com/hyperledger/fabric/protos/peer"
)
type Platform struct {
ValidateSpecStub func(spec *pb.ChaincodeSpec) error
validateSpecMutex sync.RWMutex
validateSpecArgsForCall []struct {
spec *pb.ChaincodeSpec
}
validateSpecReturns struct {
result1 error
}
validateSpecReturnsOnCall map[int]struct {
result1 error
}
ValidateDeploymentSpecStub func(spec *pb.ChaincodeDeploymentSpec) error
validateDeploymentSpecMutex sync.RWMutex
validateDeploymentSpecArgsForCall []struct {
spec *pb.ChaincodeDeploymentSpec
}
validateDeploymentSpecReturns struct {
result1 error
}
validateDeploymentSpecReturnsOnCall map[int]struct {
result1 error
}
GetDeploymentPayloadStub func(spec *pb.ChaincodeSpec) ([]byte, error)
getDeploymentPayloadMutex sync.RWMutex
getDeploymentPayloadArgsForCall []struct {
spec *pb.ChaincodeSpec
}
getDeploymentPayloadReturns struct {
result1 []byte
result2 error
}
getDeploymentPayloadReturnsOnCall map[int]struct {
result1 []byte
result2 error
}
GenerateDockerfileStub func(spec *pb.ChaincodeDeploymentSpec) (string, error)
generateDockerfileMutex sync.RWMutex
generateDockerfileArgsForCall []struct {
spec *pb.ChaincodeDeploymentSpec
}
generateDockerfileReturns struct {
result1 string
result2 error
}
generateDockerfileReturnsOnCall map[int]struct {
result1 string
result2 error
}
GenerateDockerBuildStub func(spec *pb.ChaincodeDeploymentSpec, tw *tar.Writer) error
generateDockerBuildMutex sync.RWMutex
generateDockerBuildArgsForCall []struct {
spec *pb.ChaincodeDeploymentSpec
tw *tar.Writer
}
generateDockerBuildReturns struct {
result1 error
}
generateDockerBuildReturnsOnCall map[int]struct {
result1 error
}
GetMetadataProviderStub func(spec *pb.ChaincodeDeploymentSpec) ccmetadata.MetadataProvider
getMetadataProviderMutex sync.RWMutex
getMetadataProviderArgsForCall []struct {
spec *pb.ChaincodeDeploymentSpec
}
getMetadataProviderReturns struct {
result1 ccmetadata.MetadataProvider
}
getMetadataProviderReturnsOnCall map[int]struct {
result1 ccmetadata.MetadataProvider
}
invocations map[string][][]interface{}
invocationsMutex sync.RWMutex
}
func (fake *Platform) ValidateSpec(spec *pb.ChaincodeSpec) error {
fake.validateSpecMutex.Lock()
ret, specificReturn := fake.validateSpecReturnsOnCall[len(fake.validateSpecArgsForCall)]
fake.validateSpecArgsForCall = append(fake.validateSpecArgsForCall, struct {
spec *pb.ChaincodeSpec
}{spec})
fake.recordInvocation("ValidateSpec", []interface{}{spec})
fake.validateSpecMutex.Unlock()
if fake.ValidateSpecStub != nil {
return fake.ValidateSpecStub(spec)
}
if specificReturn {
return ret.result1
}
return fake.validateSpecReturns.result1
}
func (fake *Platform) ValidateSpecCallCount() int {
fake.validateSpecMutex.RLock()
defer fake.validateSpecMutex.RUnlock()
return len(fake.validateSpecArgsForCall)
}
func (fake *Platform) ValidateSpecArgsForCall(i int) *pb.ChaincodeSpec {
fake.validateSpecMutex.RLock()
defer fake.validateSpecMutex.RUnlock()
return fake.validateSpecArgsForCall[i].spec
}
func (fake *Platform) ValidateSpecReturns(result1 error) {
fake.ValidateSpecStub = nil
fake.validateSpecReturns = struct {
result1 error
}{result1}
}
func (fake *Platform) ValidateSpecReturnsOnCall(i int, result1 error) {
fake.ValidateSpecStub = nil
if fake.validateSpecReturnsOnCall == nil {
fake.validateSpecReturnsOnCall = make(map[int]struct {
result1 error
})
}
fake.validateSpecReturnsOnCall[i] = struct {
result1 error
}{result1}
}
func (fake *Platform) ValidateDeploymentSpec(spec *pb.ChaincodeDeploymentSpec) error {
fake.validateDeploymentSpecMutex.Lock()
ret, specificReturn := fake.validateDeploymentSpecReturnsOnCall[len(fake.validateDeploymentSpecArgsForCall)]
fake.validateDeploymentSpecArgsForCall = append(fake.validateDeploymentSpecArgsForCall, struct {
spec *pb.ChaincodeDeploymentSpec
}{spec})
fake.recordInvocation("ValidateDeploymentSpec", []interface{}{spec})
fake.validateDeploymentSpecMutex.Unlock()
if fake.ValidateDeploymentSpecStub != nil {
return fake.ValidateDeploymentSpecStub(spec)
}
if specificReturn {
return ret.result1
}
return fake.validateDeploymentSpecReturns.result1
}
func (fake *Platform) ValidateDeploymentSpecCallCount() int {
fake.validateDeploymentSpecMutex.RLock()
defer fake.validateDeploymentSpecMutex.RUnlock()
return len(fake.validateDeploymentSpecArgsForCall)
}
func (fake *Platform) ValidateDeploymentSpecArgsForCall(i int) *pb.ChaincodeDeploymentSpec {
fake.validateDeploymentSpecMutex.RLock()
defer fake.validateDeploymentSpecMutex.RUnlock()
return fake.validateDeploymentSpecArgsForCall[i].spec
}
func (fake *Platform) ValidateDeploymentSpecReturns(result1 error) {
fake.ValidateDeploymentSpecStub = nil
fake.validateDeploymentSpecReturns = struct {
result1 error
}{result1}
}
func (fake *Platform) ValidateDeploymentSpecReturnsOnCall(i int, result1 error) {
fake.ValidateDeploymentSpecStub = nil
if fake.validateDeploymentSpecReturnsOnCall == nil {
fake.validateDeploymentSpecReturnsOnCall = make(map[int]struct {
result1 error
})
}
fake.validateDeploymentSpecReturnsOnCall[i] = struct {
result1 error
}{result1}
}
func (fake *Platform) GetDeploymentPayload(spec *pb.ChaincodeSpec) ([]byte, error) {
fake.getDeploymentPayloadMutex.Lock()
ret, specificReturn := fake.getDeploymentPayloadReturnsOnCall[len(fake.getDeploymentPayloadArgsForCall)]
fake.getDeploymentPayloadArgsForCall = append(fake.getDeploymentPayloadArgsForCall, struct {
spec *pb.ChaincodeSpec
}{spec})
fake.recordInvocation("GetDeploymentPayload", []interface{}{spec})
fake.getDeploymentPayloadMutex.Unlock()
if fake.GetDeploymentPayloadStub != nil {
return fake.GetDeploymentPayloadStub(spec)
}
if specificReturn {
return ret.result1, ret.result2
}
return fake.getDeploymentPayloadReturns.result1, fake.getDeploymentPayloadReturns.result2
}
func (fake *Platform) GetDeploymentPayloadCallCount() int {
fake.getDeploymentPayloadMutex.RLock()
defer fake.getDeploymentPayloadMutex.RUnlock()
return len(fake.getDeploymentPayloadArgsForCall)
}
func (fake *Platform) GetDeploymentPayloadArgsForCall(i int) *pb.ChaincodeSpec {
fake.getDeploymentPayloadMutex.RLock()
defer fake.getDeploymentPayloadMutex.RUnlock()
return fake.getDeploymentPayloadArgsForCall[i].spec
}
func (fake *Platform) GetDeploymentPayloadReturns(result1 []byte, result2 error) {
fake.GetDeploymentPayloadStub = nil
fake.getDeploymentPayloadReturns = struct {
result1 []byte
result2 error
}{result1, result2}
}
func (fake *Platform) GetDeploymentPayloadReturnsOnCall(i int, result1 []byte, result2 error) {
fake.GetDeploymentPayloadStub = nil
if fake.getDeploymentPayloadReturnsOnCall == nil {
fake.getDeploymentPayloadReturnsOnCall = make(map[int]struct {
result1 []byte
result2 error
})
}
fake.getDeploymentPayloadReturnsOnCall[i] = struct {
result1 []byte
result2 error
}{result1, result2}
}
func (fake *Platform) GenerateDockerfile(spec *pb.ChaincodeDeploymentSpec) (string, error) {
fake.generateDockerfileMutex.Lock()
ret, specificReturn := fake.generateDockerfileReturnsOnCall[len(fake.generateDockerfileArgsForCall)]
fake.generateDockerfileArgsForCall = append(fake.generateDockerfileArgsForCall, struct {
spec *pb.ChaincodeDeploymentSpec
}{spec})
fake.recordInvocation("GenerateDockerfile", []interface{}{spec})
fake.generateDockerfileMutex.Unlock()
if fake.GenerateDockerfileStub != nil {
return fake.GenerateDockerfileStub(spec)
}
if specificReturn {
return ret.result1, ret.result2
}
return fake.generateDockerfileReturns.result1, fake.generateDockerfileReturns.result2
}
func (fake *Platform) GenerateDockerfileCallCount() int {
fake.generateDockerfileMutex.RLock()
defer fake.generateDockerfileMutex.RUnlock()
return len(fake.generateDockerfileArgsForCall)
}
func (fake *Platform) GenerateDockerfileArgsForCall(i int) *pb.ChaincodeDeploymentSpec {
fake.generateDockerfileMutex.RLock()
defer fake.generateDockerfileMutex.RUnlock()
return fake.generateDockerfileArgsForCall[i].spec
}
func (fake *Platform) GenerateDockerfileReturns(result1 string, result2 error) {
fake.GenerateDockerfileStub = nil
fake.generateDockerfileReturns = struct {
result1 string
result2 error
}{result1, result2}
}
func (fake *Platform) GenerateDockerfileReturnsOnCall(i int, result1 string, result2 error) {
fake.GenerateDockerfileStub = nil
if fake.generateDockerfileReturnsOnCall == nil {
fake.generateDockerfileReturnsOnCall = make(map[int]struct {
result1 string
result2 error
})
}
fake.generateDockerfileReturnsOnCall[i] = struct {
result1 string
result2 error
}{result1, result2}
}
func (fake *Platform) GenerateDockerBuild(spec *pb.ChaincodeDeploymentSpec, tw *tar.Writer) error {
fake.generateDockerBuildMutex.Lock()
ret, specificReturn := fake.generateDockerBuildReturnsOnCall[len(fake.generateDockerBuildArgsForCall)]
fake.generateDockerBuildArgsForCall = append(fake.generateDockerBuildArgsForCall, struct {
spec *pb.ChaincodeDeploymentSpec
tw *tar.Writer
}{spec, tw})
fake.recordInvocation("GenerateDockerBuild", []interface{}{spec, tw})
fake.generateDockerBuildMutex.Unlock()
if fake.GenerateDockerBuildStub != nil {
return fake.GenerateDockerBuildStub(spec, tw)
}
if specificReturn {
return ret.result1
}
return fake.generateDockerBuildReturns.result1
}
func (fake *Platform) GenerateDockerBuildCallCount() int {
fake.generateDockerBuildMutex.RLock()
defer fake.generateDockerBuildMutex.RUnlock()
return len(fake.generateDockerBuildArgsForCall)
}
func (fake *Platform) GenerateDockerBuildArgsForCall(i int) (*pb.ChaincodeDeploymentSpec, *tar.Writer) {
fake.generateDockerBuildMutex.RLock()
defer fake.generateDockerBuildMutex.RUnlock()
return fake.generateDockerBuildArgsForCall[i].spec, fake.generateDockerBuildArgsForCall[i].tw
}
func (fake *Platform) GenerateDockerBuildReturns(result1 error) {
fake.GenerateDockerBuildStub = nil
fake.generateDockerBuildReturns = struct {
result1 error
}{result1}
}
func (fake *Platform) GenerateDockerBuildReturnsOnCall(i int, result1 error) {
fake.GenerateDockerBuildStub = nil
if fake.generateDockerBuildReturnsOnCall == nil {
fake.generateDockerBuildReturnsOnCall = make(map[int]struct {
result1 error
})
}
fake.generateDockerBuildReturnsOnCall[i] = struct {
result1 error
}{result1}
}
func (fake *Platform) GetMetadataProvider(spec *pb.ChaincodeDeploymentSpec) ccmetadata.MetadataProvider {
fake.getMetadataProviderMutex.Lock()
ret, specificReturn := fake.getMetadataProviderReturnsOnCall[len(fake.getMetadataProviderArgsForCall)]
fake.getMetadataProviderArgsForCall = append(fake.getMetadataProviderArgsForCall, struct {
spec *pb.ChaincodeDeploymentSpec
}{spec})
fake.recordInvocation("GetMetadataProvider", []interface{}{spec})
fake.getMetadataProviderMutex.Unlock()
if fake.GetMetadataProviderStub != nil {
return fake.GetMetadataProviderStub(spec)
}
if specificReturn {
return ret.result1
}
return fake.getMetadataProviderReturns.result1
}
func (fake *Platform) GetMetadataProviderCallCount() int {
fake.getMetadataProviderMutex.RLock()
defer fake.getMetadataProviderMutex.RUnlock()
return len(fake.getMetadataProviderArgsForCall)
}
func (fake *Platform) GetMetadataProviderArgsForCall(i int) *pb.ChaincodeDeploymentSpec {
fake.getMetadataProviderMutex.RLock()
defer fake.getMetadataProviderMutex.RUnlock()
return fake.getMetadataProviderArgsForCall[i].spec
}
func (fake *Platform) GetMetadataProviderReturns(result1 ccmetadata.MetadataProvider) {
fake.GetMetadataProviderStub = nil
fake.getMetadataProviderReturns = struct {
result1 ccmetadata.MetadataProvider
}{result1}
}
func (fake *Platform) GetMetadataProviderReturnsOnCall(i int, result1 ccmetadata.MetadataProvider) {
fake.GetMetadataProviderStub = nil
if fake.getMetadataProviderReturnsOnCall == nil {
fake.getMetadataProviderReturnsOnCall = make(map[int]struct {
result1 ccmetadata.MetadataProvider
})
}
fake.getMetadataProviderReturnsOnCall[i] = struct {
result1 ccmetadata.MetadataProvider
}{result1}
}
func (fake *Platform) Invocations() map[string][][]interface{} {
fake.invocationsMutex.RLock()
defer fake.invocationsMutex.RUnlock()
fake.validateSpecMutex.RLock()
defer fake.validateSpecMutex.RUnlock()
fake.validateDeploymentSpecMutex.RLock()
defer fake.validateDeploymentSpecMutex.RUnlock()
fake.getDeploymentPayloadMutex.RLock()
defer fake.getDeploymentPayloadMutex.RUnlock()
fake.generateDockerfileMutex.RLock()
defer fake.generateDockerfileMutex.RUnlock()
fake.generateDockerBuildMutex.RLock()
defer fake.generateDockerBuildMutex.RUnlock()
fake.getMetadataProviderMutex.RLock()
defer fake.getMetadataProviderMutex.RUnlock()
copiedInvocations := map[string][][]interface{}{}
for key, value := range fake.invocations {
copiedInvocations[key] = value
}
return copiedInvocations
}
func (fake *Platform) 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)
}
......@@ -36,74 +36,74 @@ type Platform interface {
GetMetadataProvider(spec *pb.ChaincodeDeploymentSpec) ccmetadata.MetadataProvider
}
var logger = flogging.MustGetLogger("chaincode-platform")
type PackageWriter interface {
Write(name string, payload []byte, tw *tar.Writer) error
}
// XXX Temporary singleton hack to allow tests to continue to work
var r = NewRegistry()
type PackageWriterWrapper func(name string, payload []byte, tw *tar.Writer) error
// Added for unit testing purposes
var _Find = find
var _CUtilWriteBytesToPackage = cutil.WriteBytesToPackage
var _generateDockerfile = r.generateDockerfile
var _generateDockerBuild = r.generateDockerBuild
func (pw PackageWriterWrapper) Write(name string, payload []byte, tw *tar.Writer) error {
return pw(name, payload, tw)
}
type Registry struct{}
type Registry struct {
Platforms map[string]Platform
PackageWriter PackageWriter
}
var logger = flogging.MustGetLogger("chaincode-platform")
// TODO, ultimately this should take the platforms as parameters
func NewRegistry() *Registry {
return &Registry{}
return &Registry{
Platforms: map[string]Platform{
pb.ChaincodeSpec_GOLANG.String(): &golang.Platform{},
pb.ChaincodeSpec_CAR.String(): &car.Platform{},
pb.ChaincodeSpec_JAVA.String(): &java.Platform{},
pb.ChaincodeSpec_NODE.String(): &node.Platform{},
},
PackageWriter: PackageWriterWrapper(cutil.WriteBytesToPackage),
}
}
func (r *Registry) ValidateSpec(spec *pb.ChaincodeSpec) error {
p, err := _Find(spec.Type)
if err != nil {
return err
platform, ok := r.Platforms[spec.Type.String()]
if !ok {
return fmt.Errorf("Unknown chaincodeType: %s", spec.Type)
}
return p.ValidateSpec(spec)
return platform.ValidateSpec(spec)
}
func (r *Registry) ValidateDeploymentSpec(spec *pb.ChaincodeDeploymentSpec) error {
p, err := _Find(spec.ChaincodeSpec.Type)
if err != nil {
return err
platform, ok := r.Platforms[spec.ChaincodeSpec.Type.String()]
if !ok {
return fmt.Errorf("Unknown chaincodeType: %s", spec.ChaincodeSpec.Type)
}
return p.ValidateDeploymentSpec(spec)
return platform.ValidateDeploymentSpec(spec)
}
func (r *Registry) GetMetadataProvider(spec *pb.ChaincodeDeploymentSpec) (ccmetadata.MetadataProvider, error) {
p, err := _Find(spec.ChaincodeSpec.Type)