1 # Test that go.sum does not get updated when -mod=readonly flag is set
2 env GO111MODULE=on
3
4 # When a sum is needed to load the build list, we get an error for the
5 # specific module. The .mod file is not downloaded, and go.sum is not written.
6 ! go list -m all
7 stderr '^go: rsc.io/quote@v1.5.2: missing go.sum entry for go.mod file; to add it:\n\tgo mod download rsc.io/quote$'
8 ! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.mod
9 ! exists go.sum
10
11 # If go.sum exists but contains hashes from an algorithm we don't know about,
12 # we should see the same error.
13 cp go.sum.h2only go.sum
14 ! go list -m all
15 stderr '^go: rsc.io/quote@v1.5.2: missing go.sum entry for go.mod file; to add it:\n\tgo mod download rsc.io/quote$'
16 ! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.mod
17 cmp go.sum go.sum.h2only
18 rm go.sum
19
20 # If we replace a module, we should see a missing sum error for the replacement.
21 cp go.mod go.mod.orig
22 go mod edit -replace rsc.io/quote@v1.5.2=rsc.io/quote@v1.5.1
23 ! go list -m all
24 stderr '^go: rsc.io/quote@v1.5.2 \(replaced by rsc.io/quote@v1.5.1\): missing go.sum entry for go.mod file; to add it:\n\tgo mod download rsc.io/quote$'
25 ! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.1.mod
26 ! exists go.sum
27 cp go.mod.orig go.mod
28
29 # Control: when sums are present, loading the build list downloads .mod files.
30 cp go.sum.buildlistonly go.sum
31 go list -m all
32 exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.mod
33
34
35 # When a sum is needed to load a .mod file for a package outside the build list,
36 # we get a generic missing import error.
37 ! go list example.com/doesnotexist
38 stderr '^no required module provides package example.com/doesnotexist; to add it:\n\tgo get example.com/doesnotexist$'
39
40 # When a sum is needed to load a .zip file, we get a more specific error.
41 # The .zip file is not downloaded.
42 ! go list rsc.io/quote
43 stderr '^missing go.sum entry for module providing package rsc.io/quote; to add:\n\tgo mod download rsc.io/quote$'
44 ! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.zip
45
46 # The error is attached to the package from the missing module. We can load
47 # a package that imports it without that error.
48 go list -e -deps -f '{{.ImportPath}}{{with .Error}} {{.Err}}{{end}}' .
49 stdout '^m$'
50 stdout '^rsc.io/quote missing go.sum entry for module providing package rsc.io/quote \(imported by m\); to add:\n\tgo get m$'
51 ! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.zip
52
53 # go.sum should not have been written.
54 cmp go.sum go.sum.buildlistonly
55
56 # Control: when sums are present, 'go list' downloads .zip files.
57 cp go.sum.tidy go.sum
58 go list .
59 exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.zip
60
61 -- go.mod --
62 module m
63
64 go 1.15
65
66 require rsc.io/quote v1.5.2
67 -- use.go --
68 package use
69
70 import _ "rsc.io/quote"
71 -- go.sum.h2only --
72 golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h2:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
73 rsc.io/quote v1.5.2/go.mod h2:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0=
74 rsc.io/sampler v1.3.0/go.mod h2:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
75 -- go.sum.buildlistonly --
76 golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
77 rsc.io/quote v1.5.2/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0=
78 rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
79 -- go.sum.tidy --
80 golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c h1:pvCbr/wm8HzDD3fVywevekufpn6tCGPY3spdHeZJEsw=
81 golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
82 rsc.io/quote v1.5.2 h1:3fEykkD9k7lYzXqCYrwGAf7iNhbk4yCjHmKBN9td4L0=
83 rsc.io/quote v1.5.2/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0=
84 rsc.io/sampler v1.3.0 h1:HLGR/BgEtI3r0uymSP/nl2uPLsUnNJX8toRyhfpBTII=
85 rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
86 rsc.io/testonly v1.0.0 h1:K/VWHdO+Jv7woUXG0GzVNx1czBXUt3Ib1deaMn+xk64=
87 rsc.io/testonly v1.0.0/go.mod h1:OqmGbIFOcF+XrFReLOGZ6BhMM7uMBiQwZsyNmh74SzY=
88
View as plain text