...
1env GO111MODULE=on
2
3# download with version should print nothing.
4# It should not load retractions from the .mod file from the latest version.
5go mod download rsc.io/quote@v1.5.0
6! stdout .
7! stderr .
8exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.info
9exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.mod
10exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.zip
11! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.info
12! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.mod
13
14# download of an invalid path should report the error
15[short] skip
16! go mod download this.domain.is.invalid/somemodule@v1.0.0
17stderr 'this.domain.is.invalid'
18! go mod download -json this.domain.is.invalid/somemodule@v1.0.0
19stdout '"Error": ".*this.domain.is.invalid.*"'
20
21# download -json with version should print JSON
22go mod download -json 'rsc.io/quote@<=v1.5.0'
23stdout '^\t"Path": "rsc.io/quote"'
24stdout '^\t"Version": "v1.5.0"'
25stdout '^\t"Info": ".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)cache(\\\\|/)download(\\\\|/)rsc.io(\\\\|/)quote(\\\\|/)@v(\\\\|/)v1.5.0.info"'
26stdout '^\t"GoMod": ".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)cache(\\\\|/)download(\\\\|/)rsc.io(\\\\|/)quote(\\\\|/)@v(\\\\|/)v1.5.0.mod"'
27stdout '^\t"Zip": ".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)cache(\\\\|/)download(\\\\|/)rsc.io(\\\\|/)quote(\\\\|/)@v(\\\\|/)v1.5.0.zip"'
28stdout '^\t"Sum": "h1:6fJa6E\+wGadANKkUMlZ0DhXFpoKlslOQDCo259XtdIE="' # hash of testdata/mod version, not real version!
29stdout '^\t"GoModSum": "h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe\+TKr0="'
30! stdout '"Error"'
31
32# download queries above should not have added to go.mod.
33go list -m all
34! stdout rsc.io
35
36# download query should have downloaded go.mod for the highest release version
37# in order to find retractions when resolving the query '@<=v1.5.0'.
38exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.info
39exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.mod
40! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.zip
41
42# add to go.mod so we can test non-query downloads
43go mod edit -require rsc.io/quote@v1.5.3-pre1
44! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.info
45! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.mod
46! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.zip
47
48# module loading will page in the info and mod files
49go list -m -mod=mod all
50exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.info
51exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.mod
52! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.zip
53
54# download will fetch and unpack the zip file
55go mod download
56exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.info
57exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.mod
58exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.zip
59exists $GOPATH/pkg/mod/rsc.io/quote@v1.5.3-pre1
60
61# download repopulates deleted files and directories independently.
62rm $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.info
63go mod download
64exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.info
65rm $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.mod
66go mod download
67exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.mod
68rm $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.zip
69go mod download
70exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.zip
71rm -r $GOPATH/pkg/mod/rsc.io/quote@v1.5.3-pre1
72go mod download
73exists $GOPATH/pkg/mod/rsc.io/quote@v1.5.3-pre1
74
75# download reports the locations of downloaded files
76go mod download -json
77stdout '^\t"Path": "rsc.io/quote"'
78stdout '^\t"Version": "v1.5.3-pre1"'
79stdout '^\t"Info": ".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)cache(\\\\|/)download(\\\\|/)rsc.io(\\\\|/)quote(\\\\|/)@v(\\\\|/)v1.5.3-pre1.info"'
80stdout '^\t"GoMod": ".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)cache(\\\\|/)download(\\\\|/)rsc.io(\\\\|/)quote(\\\\|/)@v(\\\\|/)v1.5.3-pre1.mod"'
81stdout '^\t"Zip": ".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)cache(\\\\|/)download(\\\\|/)rsc.io(\\\\|/)quote(\\\\|/)@v(\\\\|/)v1.5.3-pre1.zip"'
82stdout '^\t"Dir": ".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)rsc.io(\\\\|/)quote@v1.5.3-pre1"'
83
84# download will follow replacements
85go mod edit -require rsc.io/quote@v1.5.1 -replace rsc.io/quote@v1.5.1=rsc.io/quote@v1.5.2
86go mod download
87! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.1.zip
88exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.zip
89
90# download will not follow replacements for explicit module queries
91go mod download -json rsc.io/quote@v1.5.1
92exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.1.zip
93
94# download reports errors encountered when locating modules
95! go mod download bad/path
96stderr '^go: module bad/path: not a known dependency$'
97! go mod download bad/path@latest
98stderr '^go: bad/path@latest: malformed module path "bad/path": missing dot in first path element$'
99! go mod download rsc.io/quote@v1.999.999
100stderr '^go: rsc.io/quote@v1.999.999: reading .*/v1.999.999.info: 404 Not Found$'
101! go mod download -json bad/path
102stdout '^\t"Error": "module bad/path: not a known dependency"'
103
104# download main module produces a warning or error
105go mod download m
106stderr '^go: skipping download of m that resolves to the main module\n'
107! go mod download m@latest
108stderr '^go: m@latest: malformed module path "m": missing dot in first path element$'
109
110# download without arguments updates go.mod and go.sum after loading the
111# build list, but does not save sums for downloaded zips.
112cd update
113cp go.mod.orig go.mod
114! exists go.sum
115go mod download
116cmp go.mod.update go.mod
117cmp go.sum.update go.sum
118cp go.mod.orig go.mod
119rm go.sum
120
121# download with arguments (even "all") does update go.mod and go.sum.
122go mod download rsc.io/sampler
123cmp go.mod.update go.mod
124grep '^rsc.io/sampler v1.3.0 ' go.sum
125cp go.mod.orig go.mod
126rm go.sum
127
128go mod download all
129cmp go.mod.update go.mod
130grep '^rsc.io/sampler v1.3.0 ' go.sum
131
132# https://golang.org/issue/44435: At go 1.17 or higher, 'go mod download'
133# (without arguments) should only download the modules explicitly required in
134# the go.mod file, not (presumed-irrelevant) transitive dependencies.
135#
136# (If the go.mod file is inconsistent, the version downloaded should be the
137# selected version from the broader graph, but the go.mod file will also be
138# updated to list the correct versions. If at some point we change 'go mod
139# download' to stop updating for consistency, then it should fail if the
140# requirements are inconsistent.)
141
142rm go.sum
143cp go.mod.orig go.mod
144go mod edit -go=1.17
145cp go.mod.update go.mod.go117
146go mod edit -go=1.17 go.mod.go117
147
148go clean -modcache
149go mod download
150cmp go.mod go.mod.go117
151
152go list -e -m all
153stdout '^rsc.io/quote v1.5.2$'
154exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.zip
155stdout '^rsc.io/sampler v1.3.0$'
156! exists $GOPATH/pkg/mod/cache/download/rsc.io/sampler/@v/v1.2.1.zip
157exists $GOPATH/pkg/mod/cache/download/rsc.io/sampler/@v/v1.3.0.zip
158stdout '^golang\.org/x/text v0.0.0-20170915032832-14c0d48ead0c$'
159! exists $GOPATH/pkg/mod/cache/download/golang.org/x/text/@v/v0.0.0-20170915032832-14c0d48ead0c.zip
160cmp go.mod go.mod.go117
161
162# However, 'go mod download all' continues to download the selected version
163# of every module reported by 'go list -m all'.
164
165cp go.mod.orig go.mod
166go mod edit -go=1.17
167go clean -modcache
168go mod download all
169exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.zip
170! exists $GOPATH/pkg/mod/cache/download/rsc.io/sampler/@v/v1.2.1.zip
171exists $GOPATH/pkg/mod/cache/download/rsc.io/sampler/@v/v1.3.0.zip
172exists $GOPATH/pkg/mod/cache/download/golang.org/x/text/@v/v0.0.0-20170915032832-14c0d48ead0c.zip
173cmp go.mod go.mod.go117
174
175cd ..
176
177# allow go mod download without go.mod
178env GO111MODULE=auto
179rm go.mod
180rm $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.2.1.zip
181go mod download rsc.io/quote@v1.2.1
182exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.2.1.zip
183
184# download -x with version should print
185# the underlying commands such as contacting GOPROXY.
186go mod download -x rsc.io/quote@v1.0.0
187! stdout .
188stderr 'get '$GOPROXY
189
190-- go.mod --
191module m
192
193-- update/go.mod.orig --
194module m
195
196go 1.16
197
198require (
199 rsc.io/quote v1.5.2
200 rsc.io/sampler v1.2.1 // older version than in build list
201)
202-- update/go.mod.update --
203module m
204
205go 1.16
206
207require (
208 rsc.io/quote v1.5.2
209 rsc.io/sampler v1.3.0 // older version than in build list
210)
211-- update/go.sum.update --
212golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
213rsc.io/quote v1.5.2/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0=
214rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
View as plain text