@@ -321,22 +321,32 @@ func TestGetLDFlagsOpts(t *testing.T) {
321
321
322
322
//TestGenerateDockerBuild goes through the functions needed to do docker build
323
323
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
+
324
340
platform := & Platform {}
341
+ for _ , test := range tests {
342
+ tst := test .spec
343
+ reset := updateGopath (t , test .gopath )
325
344
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 {
336
345
inputbuf := bytes .NewBuffer (nil )
337
346
tw := tar .NewWriter (inputbuf )
338
347
339
348
var cds * pb.ChaincodeDeploymentSpec
349
+ var err error
340
350
if tst .RealGen {
341
351
cds = & pb.ChaincodeDeploymentSpec {
342
352
ChaincodeSpec : & pb.ChaincodeSpec {
@@ -362,6 +372,7 @@ func TestGenerateDockerBuild(t *testing.T) {
362
372
if err = testerr (err , tst .SuccessExpected ); err != nil {
363
373
t .Errorf ("Error validating chaincode spec: %s, %s" , cds .ChaincodeSpec .ChaincodeId .Path , err )
364
374
}
375
+ reset ()
365
376
}
366
377
}
367
378
0 commit comments