...
1# This test illustrates the interaction between lazy loading and downgrading in
2# 'go get'.
3
4# The package import graph used in this test looks like:
5#
6# lazy ---- a
7# |
8# a_test ---- b
9# b_test ---- c
10#
11# The module dependency graph initially looks like:
12#
13# lazy ---- a.1 ---- b.1 ---- c.1
14# \ /
15# b.3 ---- c.2 b.2
16#
17# (Note that lazy loading will prune out the dependency from b.1 on c.1.)
18
19cp go.mod go.mod.orig
20go mod tidy
21cmp go.mod.orig go.mod
22
23go list -m all
24stdout '^example.com/a v0.1.0 '
25stdout '^example.com/b v0.3.0 '
26stdout '^example.com/c v0.2.0 '
27
28# Downgrading c should also downgrade the b that requires it.
29
30go get example.com/c@v0.1.0
31go list -m all
32stdout '^example.com/a v0.1.0 '
33stdout '^example.com/b v0.2.0 '
34stdout '^example.com/c v0.1.0 '
35
36# Removing c entirely should also remove the a and b that require it.
37
38go get example.com/c@none
39go list -m all
40! stdout '^example.com/a '
41! stdout '^example.com/b '
42! stdout '^example.com/c '
43
44
45# With lazy loading, downgrading c should work the same way, but dependencies
46# outside of the deepening scan should not affect the downgrade.
47
48cp go.mod.orig go.mod
49go mod edit -go=1.17
50
51go list -m all
52stdout '^example.com/a v0.1.0 '
53stdout '^example.com/b v0.3.0 '
54stdout '^example.com/c v0.2.0 '
55
56go get example.com/c@v0.1.0
57go list -m all
58stdout '^example.com/a v0.1.0 '
59stdout '^example.com/b v0.2.0 '
60stdout '^example.com/c v0.1.0 '
61
62# At this point, b.2 is still an explicit root, so its dependency on c
63# is still tracked, and it will still be downgraded away if we remove c.
64# ('go get' never makes a root into a non-root. Only 'go mod tidy' does that.)
65
66go get example.com/c@none
67go list -m all
68! stdout '^example.com/a '
69! stdout '^example.com/b '
70! stdout '^example.com/c '
71
72
73# This time, we drop the explicit 'b' root by downgrading it to v0.1.0
74# (the version required by a.1) and running 'go mod tidy'.
75# It is still selected at v0.1.0 (as a dependency of a),
76# but its dependency on c is now pruned from the module graph, so it doesn't
77# result in any downgrades to b or a if we run 'go get c@none'.
78
79cp go.mod.orig go.mod
80go mod edit -go=1.17
81
82go list -m all
83stdout '^example.com/a v0.1.0 '
84stdout '^example.com/b v0.3.0 '
85stdout '^example.com/c v0.2.0 '
86
87go get example.com/c@v0.1.0 example.com/b@v0.1.0
88go list -m all
89stdout '^example.com/a v0.1.0 '
90stdout '^example.com/b v0.1.0 '
91stdout '^example.com/c v0.1.0 '
92
93go mod tidy
94go list -m all
95stdout '^example.com/a v0.1.0 '
96stdout '^example.com/b v0.1.0 '
97! stdout '^example.com/c '
98
99go get example.com/c@none
100go list -m all
101stdout '^example.com/a v0.1.0'
102stdout '^example.com/b v0.1.0'
103! stdout '^example.com/c '
104
105
106-- go.mod --
107module example.com/lazy
108
109go 1.15
110
111require (
112 example.com/a v0.1.0
113 example.com/b v0.3.0 // indirect
114)
115
116replace (
117 example.com/a v0.1.0 => ./a
118 example.com/b v0.1.0 => ./b1
119 example.com/b v0.2.0 => ./b2
120 example.com/b v0.3.0 => ./b3
121 example.com/c v0.1.0 => ./c
122 example.com/c v0.2.0 => ./c
123)
124-- lazy.go --
125package lazy
126
127import _ "example.com/a"
128
129-- a/go.mod --
130module example.com/a
131
132go 1.17
133
134require example.com/b v0.1.0
135-- a/a.go --
136package a
137-- a/a_test.go --
138package a_test
139
140import _ "example.com/b"
141
142-- b1/go.mod --
143module example.com/b
144
145go 1.17
146
147require example.com/c v0.1.0
148-- b1/b.go --
149package b
150-- b1/b_test.go --
151package b_test
152import _ "example.com/c"
153
154-- b2/go.mod --
155module example.com/b
156
157go 1.17
158
159require example.com/c v0.1.0
160-- b2/b.go --
161package b
162-- b2/b_test.go --
163package b_test
164import _ "example.com/c"
165
166-- b3/go.mod --
167module example.com/b
168
169go 1.17
170
171require example.com/c v0.2.0
172-- b3/b.go --
173package b
174-- b3/b_test.go --
175package b_test
176import _ "example.com/c"
177
178-- c/go.mod --
179module example.com/c
180
181go 1.17
182-- c/c.go --
183package c
View as plain text