@@ -336,12 +336,13 @@ func TestDockerBuildOptions(t *testing.T) {
336336 platform := & Platform {}
337337
338338 t .Run ("GOPROXY and GOSUMDB not set" , func (t * testing.T ) {
339- opts , err := platform .DockerBuildOptions ("the-path" )
339+ opts , err := platform .DockerBuildOptions ("the-path" , "" , "" , "" )
340340 require .NoError (t , err , "unexpected error from DockerBuildOptions" )
341341
342342 expectedOpts := util.DockerBuildOptions {
343343 Cmd : `
344344set -e
345+
345346if [ -f "/chaincode/input/src/go.mod" ] && [ -d "/chaincode/input/src/vendor" ]; then
346347 cd /chaincode/input/src
347348 GO111MODULE=on go build -v -mod=vendor -ldflags "-linkmode external -extldflags '-static'" -o /chaincode/output/chaincode the-path
@@ -368,12 +369,13 @@ echo Done!
368369 t .Setenv ("GOPROXY" , "the-goproxy" )
369370 t .Setenv ("GOSUMDB" , "the-gosumdb" )
370371
371- opts , err := platform .DockerBuildOptions ("the-path" )
372+ opts , err := platform .DockerBuildOptions ("the-path" , "" , "" , "" )
372373 require .NoError (t , err , "unexpected error from DockerBuildOptions" )
373374
374375 expectedOpts := util.DockerBuildOptions {
375376 Cmd : `
376377set -e
378+
377379if [ -f "/chaincode/input/src/go.mod" ] && [ -d "/chaincode/input/src/vendor" ]; then
378380 cd /chaincode/input/src
379381 GO111MODULE=on go build -v -mod=vendor -ldflags "-linkmode external -extldflags '-static'" -o /chaincode/output/chaincode the-path
@@ -395,6 +397,42 @@ echo Done!
395397 }
396398 require .Equal (t , expectedOpts , opts )
397399 })
400+
401+ t .Run ("Upsate version go" , func (t * testing.T ) {
402+ opts , err := platform .DockerBuildOptions ("testdata/src/chaincodes/toolchain" , "v1.25.0" , "linux" , "arm64" )
403+ require .NoError (t , err , "unexpected error from DockerBuildOptions" )
404+
405+ expectedOpts := util.DockerBuildOptions {
406+ Cmd : `
407+ set -e
408+
409+ curl -sLO https://go.dev/dl/go1.26.3.linux-arm64.tar.gz
410+ rm -rf /usr/local/go
411+ tar -C /usr/local -xzfv "go1.26.3.linux-arm64.tar.gz"
412+ rm "go1.26.3.linux-arm64.tar.gz"
413+ go version
414+
415+ if [ -f "/chaincode/input/src/go.mod" ] && [ -d "/chaincode/input/src/vendor" ]; then
416+ cd /chaincode/input/src
417+ GO111MODULE=on go build -v -mod=vendor -ldflags "-linkmode external -extldflags '-static'" -o /chaincode/output/chaincode testdata/src/chaincodes/toolchain
418+ elif [ -f "/chaincode/input/src/go.mod" ]; then
419+ cd /chaincode/input/src
420+ GO111MODULE=on go build -v -mod=readonly -ldflags "-linkmode external -extldflags '-static'" -o /chaincode/output/chaincode testdata/src/chaincodes/toolchain
421+ elif [ -f "/chaincode/input/src/testdata/src/chaincodes/toolchain/go.mod" ] && [ -d "/chaincode/input/src/testdata/src/chaincodes/toolchain/vendor" ]; then
422+ cd /chaincode/input/src/testdata/src/chaincodes/toolchain
423+ GO111MODULE=on go build -v -mod=vendor -ldflags "-linkmode external -extldflags '-static'" -o /chaincode/output/chaincode .
424+ elif [ -f "/chaincode/input/src/testdata/src/chaincodes/toolchain/go.mod" ]; then
425+ cd /chaincode/input/src/testdata/src/chaincodes/toolchain
426+ GO111MODULE=on go build -v -mod=readonly -ldflags "-linkmode external -extldflags '-static'" -o /chaincode/output/chaincode .
427+ else
428+ GO111MODULE=off GOPATH=/chaincode/input:$GOPATH go build -v -ldflags "-linkmode external -extldflags '-static'" -o /chaincode/output/chaincode testdata/src/chaincodes/toolchain
429+ fi
430+ echo Done!
431+ ` ,
432+ Env : []string {"GOPROXY=https://proxy.golang.org" },
433+ }
434+ require .Equal (t , expectedOpts , opts )
435+ })
398436}
399437
400438func TestDescribeCode (t * testing.T ) {
@@ -456,3 +494,17 @@ func TestMain(m *testing.M) {
456494 }
457495 os .Exit (m .Run ())
458496}
497+
498+ func TestNeedVersionGo (t * testing.T ) {
499+ newGoVer , need := getNeedVersionGo ("testdata/src/chaincodes/noop" , "v1.26.3" )
500+ require .Equal (t , newGoVer , "" )
501+ require .False (t , need )
502+
503+ newGoVer , need = getNeedVersionGo ("testdata/src/chaincodes/noop" , "v1.12.0" )
504+ require .Equal (t , newGoVer , "1.13" )
505+ require .True (t , need )
506+
507+ newGoVer , need = getNeedVersionGo ("testdata/src/chaincodes/toolchain" , "v1.25.0" )
508+ require .Equal (t , newGoVer , "1.26.3" )
509+ require .True (t , need )
510+ }
0 commit comments