@@ -358,12 +358,13 @@ func TestDockerBuildOptions(t *testing.T) {
358358 platform := & Platform {}
359359
360360 t .Run ("GOPROXY and GOSUMDB not set" , func (t * testing.T ) {
361- opts , err := platform .DockerBuildOptions ("the-path" )
361+ opts , err := platform .DockerBuildOptions ("the-path" , "" , "" , "" )
362362 require .NoError (t , err , "unexpected error from DockerBuildOptions" )
363363
364364 expectedOpts := util.DockerBuildOptions {
365365 Cmd : `
366366set -e
367+
367368if [ -f "/chaincode/input/src/go.mod" ] && [ -d "/chaincode/input/src/vendor" ]; then
368369 cd /chaincode/input/src
369370 GO111MODULE=on go build -v -mod=vendor -ldflags "-linkmode external -extldflags '-static'" -o /chaincode/output/chaincode the-path
@@ -387,24 +388,16 @@ echo Done!
387388 })
388389
389390 t .Run ("GOPROXY and GOSUMDB set" , func (t * testing.T ) {
390- oldGoproxy , set := os .LookupEnv ("GOPROXY" )
391- if set {
392- defer os .Setenv ("GOPROXY" , oldGoproxy )
393- }
394- os .Setenv ("GOPROXY" , "the-goproxy" )
395-
396- oldGosumdb , set := os .LookupEnv ("GOSUMDB" )
397- if set {
398- defer os .Setenv ("GOSUMDB" , oldGosumdb )
399- }
400- os .Setenv ("GOSUMDB" , "the-gosumdb" )
391+ t .Setenv ("GOPROXY" , "the-goproxy" )
392+ t .Setenv ("GOSUMDB" , "the-gosumdb" )
401393
402- opts , err := platform .DockerBuildOptions ("the-path" )
394+ opts , err := platform .DockerBuildOptions ("the-path" , "" , "" , "" )
403395 require .NoError (t , err , "unexpected error from DockerBuildOptions" )
404396
405397 expectedOpts := util.DockerBuildOptions {
406398 Cmd : `
407399set -e
400+
408401if [ -f "/chaincode/input/src/go.mod" ] && [ -d "/chaincode/input/src/vendor" ]; then
409402 cd /chaincode/input/src
410403 GO111MODULE=on go build -v -mod=vendor -ldflags "-linkmode external -extldflags '-static'" -o /chaincode/output/chaincode the-path
@@ -426,6 +419,42 @@ echo Done!
426419 }
427420 require .Equal (t , expectedOpts , opts )
428421 })
422+
423+ t .Run ("Upsate version go" , func (t * testing.T ) {
424+ opts , err := platform .DockerBuildOptions ("testdata/src/chaincodes/toolchain" , "v1.25.0" , "linux" , "arm64" )
425+ require .NoError (t , err , "unexpected error from DockerBuildOptions" )
426+
427+ expectedOpts := util.DockerBuildOptions {
428+ Cmd : `
429+ set -e
430+
431+ curl -sLO https://go.dev/dl/go1.26.3.linux-arm64.tar.gz
432+ rm -rf /usr/local/go
433+ tar -C /usr/local -xzfv "go1.26.3.linux-arm64.tar.gz"
434+ rm "go1.26.3.linux-arm64.tar.gz"
435+ go version
436+
437+ if [ -f "/chaincode/input/src/go.mod" ] && [ -d "/chaincode/input/src/vendor" ]; then
438+ cd /chaincode/input/src
439+ GO111MODULE=on go build -v -mod=vendor -ldflags "-linkmode external -extldflags '-static'" -o /chaincode/output/chaincode testdata/src/chaincodes/toolchain
440+ elif [ -f "/chaincode/input/src/go.mod" ]; then
441+ cd /chaincode/input/src
442+ GO111MODULE=on go build -v -mod=readonly -ldflags "-linkmode external -extldflags '-static'" -o /chaincode/output/chaincode testdata/src/chaincodes/toolchain
443+ elif [ -f "/chaincode/input/src/testdata/src/chaincodes/toolchain/go.mod" ] && [ -d "/chaincode/input/src/testdata/src/chaincodes/toolchain/vendor" ]; then
444+ cd /chaincode/input/src/testdata/src/chaincodes/toolchain
445+ GO111MODULE=on go build -v -mod=vendor -ldflags "-linkmode external -extldflags '-static'" -o /chaincode/output/chaincode .
446+ elif [ -f "/chaincode/input/src/testdata/src/chaincodes/toolchain/go.mod" ]; then
447+ cd /chaincode/input/src/testdata/src/chaincodes/toolchain
448+ GO111MODULE=on go build -v -mod=readonly -ldflags "-linkmode external -extldflags '-static'" -o /chaincode/output/chaincode .
449+ else
450+ GO111MODULE=off GOPATH=/chaincode/input:$GOPATH go build -v -ldflags "-linkmode external -extldflags '-static'" -o /chaincode/output/chaincode testdata/src/chaincodes/toolchain
451+ fi
452+ echo Done!
453+ ` ,
454+ Env : []string {"GOPROXY=https://proxy.golang.org" },
455+ }
456+ require .Equal (t , expectedOpts , opts )
457+ })
429458}
430459
431460func TestDescribeCode (t * testing.T ) {
@@ -457,6 +486,20 @@ func TestDescribeCode(t *testing.T) {
457486 })
458487}
459488
489+ func TestNeedVersionGo (t * testing.T ) {
490+ newGoVer , need := getNeedVersionGo ("testdata/src/chaincodes/noop" , "v1.26.3" )
491+ require .Equal (t , newGoVer , "" )
492+ require .False (t , need )
493+
494+ newGoVer , need = getNeedVersionGo ("testdata/src/chaincodes/noop" , "v1.12.0" )
495+ require .Equal (t , newGoVer , "1.13" )
496+ require .True (t , need )
497+
498+ newGoVer , need = getNeedVersionGo ("testdata/src/chaincodes/toolchain" , "v1.25.0" )
499+ require .Equal (t , newGoVer , "1.26.3" )
500+ require .True (t , need )
501+ }
502+
460503func TestRegularFileExists (t * testing.T ) {
461504 t .Run ("RegularFile" , func (t * testing.T ) {
462505 ok , err := regularFileExists ("testdata/ccmodule/go.mod" )
0 commit comments