1
- // +build ! go1.9
1
+ // +build go1.9
2
2
3
3
/*
4
4
Copyright IBM Corp. All Rights Reserved.
@@ -14,6 +14,7 @@ import (
14
14
"compress/gzip"
15
15
"fmt"
16
16
"os"
17
+ "path/filepath"
17
18
"strings"
18
19
"testing"
19
20
"time"
@@ -100,18 +101,15 @@ func TestValidateCDS(t *testing.T) {
100
101
}
101
102
102
103
func TestPlatform_GoPathNotSet (t * testing.T ) {
103
- p := & Platform {}
104
- spec := & pb.ChaincodeSpec {
105
- ChaincodeId : & pb.ChaincodeID {
106
- Path : "/opt/gopath/src/github.com/hyperledger/fabric" ,
107
- },
108
- }
109
104
gopath := os .Getenv ("GOPATH" )
110
105
defer os .Setenv ("GOPATH" , gopath )
111
106
os .Setenv ("GOPATH" , "" )
112
107
113
- err := p .ValidateSpec (spec )
114
- assert .Contains (t , err .Error (), "invalid GOPATH environment variable value" )
108
+ // Go 1.9 sets GOPATH to $HOME/go if GOPATH is not set
109
+ defaultGopath := filepath .Join (os .Getenv ("HOME" ), "go" )
110
+ currentGopath , err := getGopath ()
111
+ assert .NoError (t , err , "Expected default GOPATH" )
112
+ assert .Equal (t , defaultGopath , currentGopath )
115
113
}
116
114
117
115
func Test_findSource (t * testing.T ) {
@@ -225,6 +223,10 @@ func TestValidateSpec(t *testing.T) {
225
223
}
226
224
227
225
func TestGetDeploymentPayload (t * testing.T ) {
226
+ emptyDir := fmt .Sprintf ("pkg%d" , os .Getpid ())
227
+ os .Mkdir (emptyDir , os .ModePerm )
228
+ defer os .Remove (emptyDir )
229
+
228
230
platform := & Platform {}
229
231
230
232
var tests = []struct {
@@ -234,16 +236,30 @@ func TestGetDeploymentPayload(t *testing.T) {
234
236
{spec : & pb.ChaincodeSpec {ChaincodeId : & pb.ChaincodeID {Name : "Test Chaincode" , Path : "github.com/hyperledger/fabric/examples/chaincode/go/map" }}, succ : true },
235
237
{spec : & pb.ChaincodeSpec {ChaincodeId : & pb.ChaincodeID {Name : "Test Chaincode" , Path : "github.com/hyperledger/fabric/examples/bad/go/map" }}, succ : false },
236
238
{spec : & pb.ChaincodeSpec {ChaincodeId : & pb.ChaincodeID {Name : "Test Chaincode" , Path : "github.com/hyperledger/fabric/test/chaincodes/BadImport" }}, succ : false },
239
+ {spec : & pb.ChaincodeSpec {ChaincodeId : & pb.ChaincodeID {Name : "Test Chaincode" , Path : "github.com/hyperledger/fabric/core/chaincode/platforms/golang/" + emptyDir }}, succ : false },
237
240
}
238
241
239
242
for _ , tst := range tests {
240
243
_ , err := platform .GetDeploymentPayload (tst .spec )
244
+ t .Log (err )
241
245
if err = testerr (err , tst .succ ); err != nil {
242
246
t .Errorf ("Error validating chaincode spec: %s, %s" , tst .spec .ChaincodeId .Path , err )
243
247
}
244
248
}
245
249
}
246
250
251
+ //TestGetLDFlagsOpts tests handling of chaincode.golang.dynamicLink
252
+ func TestGetLDFlagsOpts (t * testing.T ) {
253
+ viper .Set ("chaincode.golang.dynamicLink" , true )
254
+ if getLDFlagsOpts () != dynamicLDFlagsOpts {
255
+ t .Error ("Error handling chaincode.golang.dynamicLink configuration. ldflags should be for dynamic linkink" )
256
+ }
257
+ viper .Set ("chaincode.golang.dynamicLink" , false )
258
+ if getLDFlagsOpts () != staticLDFlagsOpts {
259
+ t .Error ("Error handling chaincode.golang.dynamicLink configuration. ldflags should be for static linkink" )
260
+ }
261
+ }
262
+
247
263
//TestGenerateDockerBuild goes through the functions needed to do docker build
248
264
func TestGenerateDockerBuild (t * testing.T ) {
249
265
platform := & Platform {}
0 commit comments