github.com/driusan/dgit@v0.0.0-20221118233547-f39f0c15edbb/go-get-modules-tests.sh (about) 1 #!/usr/bin/env bash 2 set -e 3 4 echo "Running go get tests with Go modules enabled" 5 6 # Keep existing state 7 export ORIG_PATH=$PATH 8 export ORIG_GIT=$(which git) 9 export ORIG_GOPATH=$GOPATH 10 11 echo "Adding dgit to the path" 12 go build 13 mkdir -p bin 14 cp dgit bin/git 15 export PATH=$(pwd)/bin:$PATH 16 17 export DGIT_TRACE=/tmp/go-get-dgit-log.$$.txt 18 19 # Use a fresh GOPATH 20 mkdir /tmp/gopath.$$ 21 export GOPATH=/tmp/gopath.$$ 22 export GO111MODULE=on # Force Go 1.11 to use the go modules 23 24 # Force Go master (>=1.14) to use git instead of a proxy. 25 export GOPROXY="direct" 26 27 mkdir -p /tmp/foo.$$ 28 cd /tmp/foo.$$ 29 go mod init somesite.com/foo || exit 0 30 31 echo "Go get a package without semver" 32 go get "github.com/shurcooL/vfsgen" || (echo "Go get failed"; exit 1) 33 test -d $GOPATH/pkg/mod/github.com/shurcoo\!l || (echo "ERROR: Go get didn't work"; exit 1) 34 35 test -f $DGIT_TRACE || (echo "ERROR: Dgit wasn't called for the go get test"; exit 1) 36 rm -f $DGIT_TRACE 37 38 echo "Go get a package with semver" 39 go get "golang.org/x/text" || (echo "Go get failed"; exit 1) 40 # Only test the parent directory, because the exact package directory includes @version 41 test -d $GOPATH/pkg/mod/golang.org/x || (echo "ERROR: Go get didn't work"; exit 1) 42 43 test -f $DGIT_TRACE 44 rm -f $DGIT_TRACE 45 46 export PATH=$ORIG_PATH 47 unset GO111MODULE 48 export GOPATH=$ORIG_GOPATH