0% found this document useful (0 votes)
8 views4 pages

Go Module Download Command Guide

Uploaded by

sksiam12190
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

Go Module Download Command Guide

Uploaded by

sksiam12190
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

env GO111MODULE=on

# download with version should print nothing.


# It should not load retractions from the .mod file from the latest version.
go mod download [Link]/quote@v1.5.0
! stdout .
! stderr .
exists $GOPATH/pkg/mod/cache/download/[Link]/quote/@v/[Link]
exists $GOPATH/pkg/mod/cache/download/[Link]/quote/@v/[Link]
exists $GOPATH/pkg/mod/cache/download/[Link]/quote/@v/[Link]
! exists $GOPATH/pkg/mod/cache/download/[Link]/quote/@v/[Link]
! exists $GOPATH/pkg/mod/cache/download/[Link]/quote/@v/[Link]

# download of an invalid path should report the error


[short] skip
! go mod download [Link]/somemodule@v1.0.0
stderr '[Link]'
! go mod download -json [Link]/somemodule@v1.0.0
stdout '"Error": ".*[Link].*"'

# download -json with version should print JSON


go mod download -json '[Link]/quote@<=v1.5.0'
stdout '^\t"Path": "[Link]/quote"'
stdout '^\t"Version": "v1.5.0"'
stdout '^\t"Info":
".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)cache(\\\\|/)download(\\\\|/)[Link](\\\\|/)quote(\
\\\|/)@v(\\\\|/)[Link]"'
stdout '^\t"GoMod":
".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)cache(\\\\|/)download(\\\\|/)[Link](\\\\|/)quote(\
\\\|/)@v(\\\\|/)[Link]"'
stdout '^\t"Zip":
".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)cache(\\\\|/)download(\\\\|/)[Link](\\\\|/)quote(\
\\\|/)@v(\\\\|/)[Link]"'
stdout '^\t"Sum": "h1:6fJa6E\+wGadANKkUMlZ0DhXFpoKlslOQDCo259XtdIE="' # hash of
testdata/mod version, not real version!
stdout '^\t"GoModSum": "h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe\+TKr0="'
! stdout '"Error"'

# download queries above should not have added to [Link].


go list -m all
! stdout [Link]

# download query should have downloaded [Link] for the highest release version
# in order to find retractions when resolving the query '@<=v1.5.0'.
exists $GOPATH/pkg/mod/cache/download/[Link]/quote/@v/[Link]
exists $GOPATH/pkg/mod/cache/download/[Link]/quote/@v/[Link]
! exists $GOPATH/pkg/mod/cache/download/[Link]/quote/@v/[Link]

# add to [Link] so we can test non-query downloads


go mod edit -require [Link]/quote@v1.5.3-pre1
! exists $GOPATH/pkg/mod/cache/download/[Link]/quote/@v/[Link]
! exists $GOPATH/pkg/mod/cache/download/[Link]/quote/@v/[Link]
! exists $GOPATH/pkg/mod/cache/download/[Link]/quote/@v/[Link]

# module loading will page in the info and mod files


go list -m -mod=mod all
exists $GOPATH/pkg/mod/cache/download/[Link]/quote/@v/[Link]
exists $GOPATH/pkg/mod/cache/download/[Link]/quote/@v/[Link]
! exists $GOPATH/pkg/mod/cache/download/[Link]/quote/@v/[Link]
# download will fetch and unpack the zip file
go mod download
exists $GOPATH/pkg/mod/cache/download/[Link]/quote/@v/[Link]
exists $GOPATH/pkg/mod/cache/download/[Link]/quote/@v/[Link]
exists $GOPATH/pkg/mod/cache/download/[Link]/quote/@v/[Link]
exists $GOPATH/pkg/mod/[Link]/quote@v1.5.3-pre1

# download repopulates deleted files and directories independently.


rm $GOPATH/pkg/mod/cache/download/[Link]/quote/@v/[Link]
go mod download
exists $GOPATH/pkg/mod/cache/download/[Link]/quote/@v/[Link]
rm $GOPATH/pkg/mod/cache/download/[Link]/quote/@v/[Link]
go mod download
exists $GOPATH/pkg/mod/cache/download/[Link]/quote/@v/[Link]
rm $GOPATH/pkg/mod/cache/download/[Link]/quote/@v/[Link]
go mod download
exists $GOPATH/pkg/mod/cache/download/[Link]/quote/@v/[Link]
rm -r $GOPATH/pkg/mod/[Link]/quote@v1.5.3-pre1
go mod download
exists $GOPATH/pkg/mod/[Link]/quote@v1.5.3-pre1

# download reports the locations of downloaded files


go mod download -json
stdout '^\t"Path": "[Link]/quote"'
stdout '^\t"Version": "v1.5.3-pre1"'
stdout '^\t"Info":
".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)cache(\\\\|/)download(\\\\|/)[Link](\\\\|/)quote(\
\\\|/)@v(\\\\|/)[Link]"'
stdout '^\t"GoMod":
".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)cache(\\\\|/)download(\\\\|/)[Link](\\\\|/)quote(\
\\\|/)@v(\\\\|/)[Link]"'
stdout '^\t"Zip":
".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)cache(\\\\|/)download(\\\\|/)[Link](\\\\|/)quote(\
\\\|/)@v(\\\\|/)[Link]"'
stdout '^\t"Dir": ".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)[Link](\\\\|/)quote@v1.5.3-
pre1"'

# download will follow replacements


go mod edit -require [Link]/quote@v1.5.1 -replace
[Link]/quote@v1.5.1=[Link]/quote@v1.5.2
go mod download
! exists $GOPATH/pkg/mod/cache/download/[Link]/quote/@v/[Link]
exists $GOPATH/pkg/mod/cache/download/[Link]/quote/@v/[Link]

# download will not follow replacements for explicit module queries


go mod download -json [Link]/quote@v1.5.1
exists $GOPATH/pkg/mod/cache/download/[Link]/quote/@v/[Link]

# download reports errors encountered when locating modules


! go mod download bad/path
stderr '^go: module bad/path: not a known dependency$'
! go mod download bad/path@latest
stderr '^go: bad/path@latest: malformed module path "bad/path": missing dot in
first path element$'
! go mod download [Link]/quote@v1.999.999
stderr '^go: [Link]/quote@v1.999.999: reading .*/[Link]: 404 Not Found$'
! go mod download -json bad/path
stdout '^\t"Error": "module bad/path: not a known dependency"'
# download main module produces a warning or error
go mod download m
stderr '^go: skipping download of m that resolves to the main module\n'
! go mod download m@latest
stderr '^go: m@latest: malformed module path "m": missing dot in first path
element$'

# download without arguments updates [Link] and [Link] after loading the
# build list, but does not save sums for downloaded zips.
cd update
cp [Link] [Link]
! exists [Link]
go mod download
cmp [Link] [Link]
cmp [Link] [Link]
cp [Link] [Link]
rm [Link]

# download with arguments (even "all") does update [Link] and [Link].
go mod download [Link]/sampler
cmp [Link] [Link]
grep '^[Link]/sampler v1.3.0 ' [Link]
cp [Link] [Link]
rm [Link]

go mod download all


cmp [Link] [Link]
grep '^[Link]/sampler v1.3.0 ' [Link]

# [Link] At go 1.17 or higher, 'go mod download'


# (without arguments) should only download the modules explicitly required in
# the [Link] file, not (presumed-irrelevant) transitive dependencies.
#
# (If the [Link] file is inconsistent, the version downloaded should be the
# selected version from the broader graph, but the [Link] file will also be
# updated to list the correct versions. If at some point we change 'go mod
# download' to stop updating for consistency, then it should fail if the
# requirements are inconsistent.)

rm [Link]
cp [Link] [Link]
go mod edit -go=1.17
cp [Link] [Link].go117
go mod edit -go=1.17 [Link].go117

go clean -modcache
go mod download
cmp [Link] [Link].go117

go list -e -m all
stdout '^[Link]/quote v1.5.2$'
exists $GOPATH/pkg/mod/cache/download/[Link]/quote/@v/[Link]
stdout '^[Link]/sampler v1.3.0$'
! exists $GOPATH/pkg/mod/cache/download/[Link]/sampler/@v/[Link]
exists $GOPATH/pkg/mod/cache/download/[Link]/sampler/@v/[Link]
stdout '^golang\.org/x/text v0.0.0-20170915032832-14c0d48ead0c$'
! exists $GOPATH/pkg/mod/cache/download/[Link]/x/text/@v/v0.0.0-20170915032832-
[Link]
cmp [Link] [Link].go117

# However, 'go mod download all' continues to download the selected version
# of every module reported by 'go list -m all'.

cp [Link] [Link]
go mod edit -go=1.17
go clean -modcache
go mod download all
exists $GOPATH/pkg/mod/cache/download/[Link]/quote/@v/[Link]
! exists $GOPATH/pkg/mod/cache/download/[Link]/sampler/@v/[Link]
exists $GOPATH/pkg/mod/cache/download/[Link]/sampler/@v/[Link]
exists $GOPATH/pkg/mod/cache/download/[Link]/x/text/@v/v0.0.0-20170915032832-
[Link]
cmp [Link] [Link].go117

cd ..

# allow go mod download without [Link]


env GO111MODULE=auto
rm [Link]
rm $GOPATH/pkg/mod/cache/download/[Link]/quote/@v/[Link]
go mod download [Link]/quote@v1.2.1
exists $GOPATH/pkg/mod/cache/download/[Link]/quote/@v/[Link]

# download -x with version should print


# the underlying commands such as contacting GOPROXY.
go mod download -x [Link]/quote@v1.0.0
! stdout .
stderr 'get '$GOPROXY

-- [Link] --
module m

-- update/[Link] --
module m

go 1.16

require (
[Link]/quote v1.5.2
[Link]/sampler v1.2.1 // older version than in build list
)
-- update/[Link] --
module m

go 1.16

require (
[Link]/quote v1.5.2
[Link]/sampler v1.3.0 // older version than in build list
)
-- update/[Link] --
[Link]/x/text v0.0.0-20170915032832-14c0d48ead0c/[Link]
h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
[Link]/quote v1.5.2/[Link] h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0=
[Link]/sampler v1.3.0/[Link] h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=

You might also like