1 env GO111MODULE=on
2
3 # download with version should print nothing.
4 # It should not load retractions from the .mod file from the latest version.
5 go mod download rsc.io/quote@v1.5.0
6 ! stdout .
7 ! stderr .
8 exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.info
9 exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.mod
10 exists $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
17 stderr 'this.domain.is.invalid'
18 ! go mod download -json this.domain.is.invalid/somemodule@v1.0.0
19 stdout '"Error": ".*this.domain.is.invalid.*"'
20
21 # download -json with version should print JSON
22 go mod download -json 'rsc.io/quote@<=v1.5.0'
23 stdout '^\t"Path": "rsc.io/quote"'
24 stdout '^\t"Version": "v1.5.0"'
25 stdout '^\t"Info": ".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)cache(\\\\|/)download(\\\\|/)rsc.io(\\\\|/)quote(\\\\|/)@v(\\\\|/)v1.5.0.info"'
26 stdout '^\t"GoMod": ".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)cache(\\\\|/)download(\\\\|/)rsc.io(\\\\|/)quote(\\\\|/)@v(\\\\|/)v1.5.0.mod"'
27 stdout '^\t"Zip": ".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)cache(\\\\|/)download(\\\\|/)rsc.io(\\\\|/)quote(\\\\|/)@v(\\\\|/)v1.5.0.zip"'
28 stdout '^\t"Sum": "h1:6fJa6E\+wGadANKkUMlZ0DhXFpoKlslOQDCo259XtdIE="' # hash of testdata/mod version, not real version!
29 stdout '^\t"GoModSum": "h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe\+TKr0="'
30 ! stdout '"Error"'
31
32 # download queries above should not have added to go.mod.
33 go 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'.
38 exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.info
39 exists $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
43 go 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
49 go list -m -mod=mod all
50 exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.info
51 exists $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
55 go mod download
56 exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.info
57 exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.mod
58 exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.zip
59 exists $GOPATH/pkg/mod/rsc.io/quote@v1.5.3-pre1
60
61 # download repopulates deleted files and directories independently.
62 rm $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.info
63 go mod download
64 exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.info
65 rm $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.mod
66 go mod download
67 exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.mod
68 rm $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.zip
69 go mod download
70 exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.zip
71 rm -r $GOPATH/pkg/mod/rsc.io/quote@v1.5.3-pre1
72 go mod download
73 exists $GOPATH/pkg/mod/rsc.io/quote@v1.5.3-pre1
74
75 # download reports the locations of downloaded files
76 go mod download -json
77 stdout '^\t"Path": "rsc.io/quote"'
78 stdout '^\t"Version": "v1.5.3-pre1"'
79 stdout '^\t"Info": ".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)cache(\\\\|/)download(\\\\|/)rsc.io(\\\\|/)quote(\\\\|/)@v(\\\\|/)v1.5.3-pre1.info"'
80 stdout '^\t"GoMod": ".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)cache(\\\\|/)download(\\\\|/)rsc.io(\\\\|/)quote(\\\\|/)@v(\\\\|/)v1.5.3-pre1.mod"'
81 stdout '^\t"Zip": ".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)cache(\\\\|/)download(\\\\|/)rsc.io(\\\\|/)quote(\\\\|/)@v(\\\\|/)v1.5.3-pre1.zip"'
82 stdout '^\t"Dir": ".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)rsc.io(\\\\|/)quote@v1.5.3-pre1"'
83
84 # download will follow replacements
85 go mod edit -require rsc.io/quote@v1.5.1 -replace rsc.io/quote@v1.5.1=rsc.io/quote@v1.5.2
86 go mod download
87 ! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.1.zip
88 exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.zip
89
90 # download will not follow replacements for explicit module queries
91 go mod download -json rsc.io/quote@v1.5.1
92 exists $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
96 stderr '^go mod download: module bad/path: not a known dependency$'
97 ! go mod download bad/path@latest
98 stderr '^go mod download: bad/path@latest: malformed module path "bad/path": missing dot in first path element$'
99 ! go mod download rsc.io/quote@v1.999.999
100 stderr '^go mod download: rsc.io/quote@v1.999.999: reading .*/v1.999.999.info: 404 Not Found$'
101 ! go mod download -json bad/path
102 stdout '^\t"Error": "module bad/path: not a known dependency"'
103
104 # download main module produces a warning or error
105 go mod download m
106 stderr '^go mod download: skipping argument m that resolves to the main module\n'
107 ! go mod download m@latest
108 stderr '^go mod download: 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.
112 cd update
113 cp go.mod.orig go.mod
114 ! exists go.sum
115 go mod download
116 cmp go.mod.update go.mod
117 cmp go.sum.update go.sum
118 cp go.mod.orig go.mod
119 rm go.sum
120
121 # download with arguments (even "all") does update go.mod and go.sum.
122 go mod download rsc.io/sampler
123 cmp go.mod.update go.mod
124 grep '^rsc.io/sampler v1.3.0 ' go.sum
125 cp go.mod.orig go.mod
126 rm go.sum
127
128 go mod download all
129 cmp go.mod.update go.mod
130 grep '^rsc.io/sampler v1.3.0 ' go.sum
131 cd ..
132
133 # allow go mod download without go.mod
134 env GO111MODULE=auto
135 rm go.mod
136 rm $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.2.1.zip
137 go mod download rsc.io/quote@v1.2.1
138 exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.2.1.zip
139
140 # download -x with version should print
141 # the underlying commands such as contacting GOPROXY.
142 go mod download -x rsc.io/quote@v1.0.0
143 ! stdout .
144 stderr 'get '$GOPROXY
145
146 -- go.mod --
147 module m
148
149 -- update/go.mod.orig --
150 module m
151
152 go 1.16
153
154 require (
155 rsc.io/quote v1.5.2
156 rsc.io/sampler v1.2.1 // older version than in build list
157 )
158 -- update/go.mod.update --
159 module m
160
161 go 1.16
162
163 require (
164 rsc.io/quote v1.5.2
165 rsc.io/sampler v1.3.0 // older version than in build list
166 )
167 -- update/go.sum.update --
168 golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
169 rsc.io/quote v1.5.2/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0=
170 rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
171
View as plain text