Skip to content

Commit 0511d42

Browse files
committed
[FAB-7721] Move AutoVendor to golang platform
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 <sykesmat@us.ibm.com>
1 parent f3d14f8 commit 0511d42

File tree

4 files changed

+96
-10
lines changed

4 files changed

+96
-10
lines changed

core/chaincode/platforms/golang/platform_test.go

+21-10
Original file line numberDiff line numberDiff line change
@@ -321,22 +321,32 @@ func TestGetLDFlagsOpts(t *testing.T) {
321321

322322
//TestGenerateDockerBuild goes through the functions needed to do docker build
323323
func TestGenerateDockerBuild(t *testing.T) {
324+
defaultGopath := os.Getenv("GOPATH")
325+
testdataPath, err := filepath.Abs("testdata")
326+
require.NoError(t, err)
327+
328+
tests := []struct {
329+
gopath string
330+
spec spec
331+
}{
332+
{gopath: defaultGopath, spec: spec{CCName: "NoCode", Path: "path/to/nowhere", File: "/bin/warez", Mode: 0100400, SuccessExpected: false}},
333+
{gopath: defaultGopath, spec: spec{CCName: "invalidhttp", Path: "https://not/a/valid/path", SuccessExpected: false, RealGen: true}},
334+
{gopath: defaultGopath, spec: spec{CCName: "map", Path: "github.com/hyperledger/fabric/examples/chaincode/go/map", SuccessExpected: true, RealGen: true}},
335+
{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}},
336+
{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}},
337+
{gopath: testdataPath, spec: spec{CCName: "AutoVendor", Path: "chaincodes/AutoVendor/chaincode", SuccessExpected: true, RealGen: true}},
338+
}
339+
324340
platform := &Platform{}
341+
for _, test := range tests {
342+
tst := test.spec
343+
reset := updateGopath(t, test.gopath)
325344

326-
specs := make([]spec, 0)
327-
specs = append(specs, spec{CCName: "NoCode", Path: "path/to/nowhere", File: "/bin/warez", Mode: 0100400, SuccessExpected: false})
328-
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})
329-
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})
330-
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})
331-
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})
332-
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})
333-
334-
var err error
335-
for _, tst := range specs {
336345
inputbuf := bytes.NewBuffer(nil)
337346
tw := tar.NewWriter(inputbuf)
338347

339348
var cds *pb.ChaincodeDeploymentSpec
349+
var err error
340350
if tst.RealGen {
341351
cds = &pb.ChaincodeDeploymentSpec{
342352
ChaincodeSpec: &pb.ChaincodeSpec{
@@ -362,6 +372,7 @@ func TestGenerateDockerBuild(t *testing.T) {
362372
if err = testerr(err, tst.SuccessExpected); err != nil {
363373
t.Errorf("Error validating chaincode spec: %s, %s", cds.ChaincodeSpec.ChaincodeId.Path, err)
364374
}
375+
reset()
365376
}
366377
}
367378

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright Greg Haskins All Rights Reserved
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* The purpose of this test code is to prove that the system properly packages
7+
* up dependencies. We therefore synthesize the scenario where a chaincode
8+
* imports non-standard dependencies both directly and indirectly and then
9+
* expect a unit-test to verify that the package includes everything needed
10+
* and ultimately builds properly.
11+
*
12+
*/
13+
14+
package main
15+
16+
import (
17+
"fmt"
18+
19+
"chaincodes/AutoVendor/directdep"
20+
21+
"github.com/hyperledger/fabric/core/chaincode/shim"
22+
pb "github.com/hyperledger/fabric/protos/peer"
23+
)
24+
25+
// SimpleChaincode example simple Chaincode implementation
26+
type SimpleChaincode struct {
27+
}
28+
29+
func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {
30+
return shim.Error("NOT IMPL")
31+
}
32+
33+
func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
34+
return shim.Error("NOT IMPL")
35+
}
36+
37+
func main() {
38+
directdep.PointlessFunction()
39+
40+
err := shim.Start(new(SimpleChaincode))
41+
if err != nil {
42+
fmt.Printf("Error starting Simple chaincode: %s", err)
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright Greg Haskins All Rights Reserved
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* See github.com/hyperledger/fabric/test/chaincodes/AutoVendor/chaincode/main.go for details
7+
*/
8+
package directdep
9+
10+
import (
11+
"chaincodes/AutoVendor/indirectdep"
12+
)
13+
14+
func PointlessFunction() {
15+
// delegate to our indirect dependency
16+
indirectdep.PointlessFunction()
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright Greg Haskins All Rights Reserved
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* See github.com/hyperledger/fabric/test/chaincodes/AutoVendor/chaincode/main.go for details
7+
*/
8+
package indirectdep
9+
10+
import "fmt"
11+
12+
func PointlessFunction() {
13+
fmt.Printf("Successfully invoked pointless function\n")
14+
}

0 commit comments

Comments
 (0)