...

Text file src/cmd/go/testdata/script/mod_gomodcache.txt

Documentation: cmd/go/testdata/script

     1# Test GOMODCACHE
     2env GO111MODULE=on
     3
     4# Explicitly set GOMODCACHE
     5env GOMODCACHE=$WORK/modcache
     6go env GOMODCACHE
     7stdout $WORK[/\\]modcache
     8go get rsc.io/quote@v1.0.0
     9exists $WORK/modcache/cache/download/rsc.io/quote/@v/v1.0.0.info
    10grep '{"Version":"v1.0.0","Time":"2018-02-14T00:45:20Z"}' $WORK/modcache/cache/download/rsc.io/quote/@v/v1.0.0.info
    11
    12# Ensure GOMODCACHE doesn't affect location of sumdb, but $GOMODCACHE/cache/download/sumdb is still written
    13exists $GOPATH/pkg/sumdb
    14! exists $WORK/modcache/sumdb
    15exists $WORK/modcache/cache/download/sumdb
    16
    17# Test that the default GOMODCACHE is $GOPATH[0]/pkg/mod
    18env GOMODCACHE=
    19go env GOMODCACHE
    20stdout $GOPATH[/\\]pkg[/\\]mod
    21go get rsc.io/quote@v1.0.0
    22exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.0.0.info
    23grep '{"Version":"v1.0.0","Time":"2018-02-14T00:45:20Z"}' $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.0.0.info
    24
    25# If neither GOMODCACHE or GOPATH are set, GOPATH defaults to the user's $HOME/go, so GOMODCACHE becomes $HOME/go/pkg/mod
    26[GOOS:windows] env USERPROFILE=$WORK/home # Ensure USERPROFILE is a valid path (rather than /no-home/ so we don't run into the logic that "uninfers" GOPATH in cmd/go/main.go
    27[GOOS:plan9] env home=$WORK/home
    28[!GOOS:windows] [!GOOS:plan9] env HOME=$WORK/home
    29env GOMODCACHE=
    30env GOPATH=
    31go env GOMODCACHE
    32stdout $HOME[/\\]go[/\\]pkg[/\\]mod
    33
    34# If GOMODCACHE isn't set and GOPATH starts with the path list separator,
    35# GOMODCACHE is empty and any command that needs it errors out.
    36env GOMODCACHE=
    37env GOPATH=${:}$WORK/this/is/ignored
    38
    39go env GOMODCACHE
    40stdout '^$'
    41! stdout .
    42! stderr .
    43
    44! go mod download rsc.io/quote@v1.0.0
    45stderr '^go: module cache not found: neither GOMODCACHE nor GOPATH is set$'
    46
    47# If GOMODCACHE isn't set and GOPATH has multiple elements only the first is used.
    48env GOMODCACHE=
    49env GOPATH=$WORK/first/path${:}$WORK/this/is/ignored
    50go env GOMODCACHE
    51stdout $WORK[/\\]first[/\\]path[/\\]pkg[/\\]mod
    52
    53env GOMODCACHE=$WORK/modcache
    54go mod download rsc.io/quote@v1.0.0
    55exists $WORK/modcache/cache/download/rsc.io/quote/@v/v1.0.0.info
    56
    57# Test error when cannot create GOMODCACHE directory
    58env GOMODCACHE=$WORK/modcachefile
    59! go install example.com/cmd/a@v1.0.0
    60stderr 'go: could not create module cache'
    61
    62# Test that the following work even with GO111MODULE=off
    63env GO111MODULE=off
    64
    65# Cleaning modcache
    66exists $WORK/modcache
    67env GOMODCACHE=$WORK/modcache
    68go clean -modcache
    69! exists $WORK/modcache
    70
    71-- go.mod --
    72module m
    73
    74-- $WORK/modcachefile --

View as plain text