Skip to content

Commit

Permalink
[FAB-7721] Move AutoVendor to golang platform
Browse files Browse the repository at this point in the history
The AutoVendor code is used by the golang chaincode platform test. This
is the last remaining user of apps in the top level test directory.

Change-Id: Idac7218d94bfc5a4032ae39b76884efa336eb2f2
Signed-off-by: Matthew Sykes <[email protected]>
  • Loading branch information
sykesm committed Apr 12, 2018
1 parent f3d14f8 commit 0511d42
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 10 deletions.
31 changes: 21 additions & 10 deletions core/chaincode/platforms/golang/platform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,22 +321,32 @@ func TestGetLDFlagsOpts(t *testing.T) {

//TestGenerateDockerBuild goes through the functions needed to do docker build
func TestGenerateDockerBuild(t *testing.T) {
defaultGopath := os.Getenv("GOPATH")
testdataPath, err := filepath.Abs("testdata")
require.NoError(t, err)

tests := []struct {
gopath string
spec spec
}{
{gopath: defaultGopath, spec: spec{CCName: "NoCode", Path: "path/to/nowhere", File: "/bin/warez", Mode: 0100400, SuccessExpected: false}},
{gopath: defaultGopath, spec: spec{CCName: "invalidhttp", Path: "https://not/a/valid/path", SuccessExpected: false, RealGen: true}},
{gopath: defaultGopath, spec: spec{CCName: "map", Path: "github.com/hyperledger/fabric/examples/chaincode/go/map", SuccessExpected: true, RealGen: true}},
{gopath: defaultGopath, spec: spec{CCName: "mapBadPath", Path: "github.com/hyperledger/fabric/examples/chaincode/go/map", File: "/src/github.com/hyperledger/fabric/examples/bad/path/to/map.go", Mode: 0100400, SuccessExpected: false}},
{gopath: defaultGopath, spec: spec{CCName: "mapBadMode", Path: "github.com/hyperledger/fabric/examples/chaincode/go/map", File: "/src/github.com/hyperledger/fabric/examples/chaincode/go/map/map.go", Mode: 0100555, SuccessExpected: false}},
{gopath: testdataPath, spec: spec{CCName: "AutoVendor", Path: "chaincodes/AutoVendor/chaincode", SuccessExpected: true, RealGen: true}},
}

platform := &Platform{}
for _, test := range tests {
tst := test.spec
reset := updateGopath(t, test.gopath)

specs := make([]spec, 0)
specs = append(specs, spec{CCName: "NoCode", Path: "path/to/nowhere", File: "/bin/warez", Mode: 0100400, SuccessExpected: false})
specs = append(specs, spec{CCName: "invalidhttp", Path: "https://not/a/valid/path", File: "/src/github.com/hyperledger/fabric/examples/chaincode/go/map/map.go", Mode: 0100400, SuccessExpected: false, RealGen: true})
specs = append(specs, spec{CCName: "map", Path: "github.com/hyperledger/fabric/examples/chaincode/go/map", File: "/src/github.com/hyperledger/fabric/examples/chaincode/go/map/map.go", Mode: 0100400, SuccessExpected: true, RealGen: true})
specs = append(specs, spec{CCName: "AutoVendor", Path: "github.com/hyperledger/fabric/test/chaincodes/AutoVendor/chaincode", File: "/src/github.com/hyperledger/fabric/test/chaincodes/AutoVendor/chaincode/main.go", Mode: 0100400, SuccessExpected: true, RealGen: true})
specs = append(specs, spec{CCName: "mapBadPath", Path: "github.com/hyperledger/fabric/examples/chaincode/go/map", File: "/src/github.com/hyperledger/fabric/examples/bad/path/to/map.go", Mode: 0100400, SuccessExpected: false})
specs = append(specs, spec{CCName: "mapBadMode", Path: "github.com/hyperledger/fabric/examples/chaincode/go/map", File: "/src/github.com/hyperledger/fabric/examples/chaincode/go/map/map.go", Mode: 0100555, SuccessExpected: false})

var err error
for _, tst := range specs {
inputbuf := bytes.NewBuffer(nil)
tw := tar.NewWriter(inputbuf)

var cds *pb.ChaincodeDeploymentSpec
var err error
if tst.RealGen {
cds = &pb.ChaincodeDeploymentSpec{
ChaincodeSpec: &pb.ChaincodeSpec{
Expand All @@ -362,6 +372,7 @@ func TestGenerateDockerBuild(t *testing.T) {
if err = testerr(err, tst.SuccessExpected); err != nil {
t.Errorf("Error validating chaincode spec: %s, %s", cds.ChaincodeSpec.ChaincodeId.Path, err)
}
reset()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright Greg Haskins All Rights Reserved
*
* SPDX-License-Identifier: Apache-2.0
*
* The purpose of this test code is to prove that the system properly packages
* up dependencies. We therefore synthesize the scenario where a chaincode
* imports non-standard dependencies both directly and indirectly and then
* expect a unit-test to verify that the package includes everything needed
* and ultimately builds properly.
*
*/

package main

import (
"fmt"

"chaincodes/AutoVendor/directdep"

"github.com/hyperledger/fabric/core/chaincode/shim"
pb "github.com/hyperledger/fabric/protos/peer"
)

// SimpleChaincode example simple Chaincode implementation
type SimpleChaincode struct {
}

func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {
return shim.Error("NOT IMPL")
}

func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
return shim.Error("NOT IMPL")
}

func main() {
directdep.PointlessFunction()

err := shim.Start(new(SimpleChaincode))
if err != nil {
fmt.Printf("Error starting Simple chaincode: %s", err)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright Greg Haskins All Rights Reserved
*
* SPDX-License-Identifier: Apache-2.0
*
* See github.com/hyperledger/fabric/test/chaincodes/AutoVendor/chaincode/main.go for details
*/
package directdep

import (
"chaincodes/AutoVendor/indirectdep"
)

func PointlessFunction() {
// delegate to our indirect dependency
indirectdep.PointlessFunction()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright Greg Haskins All Rights Reserved
*
* SPDX-License-Identifier: Apache-2.0
*
* See github.com/hyperledger/fabric/test/chaincodes/AutoVendor/chaincode/main.go for details
*/
package indirectdep

import "fmt"

func PointlessFunction() {
fmt.Printf("Successfully invoked pointless function\n")
}

0 comments on commit 0511d42

Please sign in to comment.