@@ -73,13 +73,7 @@ const (
73
73
}
74
74
}
75
75
76
- // This test confirms the full functionality of the code lenses for updating
77
- // dependencies in a go.mod file. It checks for the code lens that suggests
78
- // an update and then executes the command associated with that code lens. A
79
- // regression test for golang/go#39446. It also checks that these code lenses
80
- // only affect the diagnostics and contents of the containing go.mod file.
81
- func TestUpgradeCodelens (t * testing.T ) {
82
- const proxyWithLatest = `
76
+ const proxyWithLatest = `
83
77
-- golang.org/x/[email protected] /go.mod --
84
78
module golang.org/x/hello
85
79
@@ -98,6 +92,13 @@ package hi
98
92
var Goodbye error
99
93
`
100
94
95
+ // This test confirms the full functionality of the code lenses for updating
96
+ // dependencies in a go.mod file, when using a go.work file. It checks for the
97
+ // code lens that suggests an update and then executes the command associated
98
+ // with that code lens. A regression test for golang/go#39446. It also checks
99
+ // that these code lenses only affect the diagnostics and contents of the
100
+ // containing go.mod file.
101
+ func TestUpgradeCodelens_Workspace (t * testing.T ) {
101
102
const shouldUpdateDep = `
102
103
-- go.work --
103
104
go 1.18
@@ -246,6 +247,62 @@ require golang.org/x/hello v1.2.3
246
247
}
247
248
}
248
249
250
+ func TestUpgradeCodelens_ModVendor (t * testing.T ) {
251
+ // This test checks the regression of golang/go#66055. The upgrade codelens
252
+ // should work in a mod vendor context (the test above using a go.work file
253
+ // was not broken).
254
+ testenv .NeedsGo1Point (t , 22 )
255
+ const shouldUpdateDep = `
256
+ -- go.mod --
257
+ module mod.com/a
258
+
259
+ go 1.22
260
+
261
+ require golang.org/x/hello v1.2.3
262
+ -- go.sum --
263
+ golang.org/x/hello v1.2.3 h1:7Wesfkx/uBd+eFgPrq0irYj/1XfmbvLV8jZ/W7C2Dwg=
264
+ golang.org/x/hello v1.2.3/go.mod h1:OgtlzsxVMUUdsdQCIDYgaauCTH47B8T8vofouNJfzgY=
265
+ -- main.go --
266
+ package main
267
+
268
+ import "golang.org/x/hello/hi"
269
+
270
+ func main() {
271
+ _ = hi.Goodbye
272
+ }
273
+ `
274
+
275
+ const wantGoModA = `module mod.com/a
276
+
277
+ go 1.22
278
+
279
+ require golang.org/x/hello v1.3.3
280
+ `
281
+
282
+ WithOptions (
283
+ ProxyFiles (proxyWithLatest ),
284
+ ).Run (t , shouldUpdateDep , func (t * testing.T , env * Env ) {
285
+ env .RunGoCommand ("mod" , "vendor" )
286
+ env .AfterChange ()
287
+ env .OpenFile ("go.mod" )
288
+
289
+ env .ExecuteCodeLensCommand ("go.mod" , command .CheckUpgrades , nil )
290
+ d := & protocol.PublishDiagnosticsParams {}
291
+ env .OnceMet (
292
+ CompletedWork (server .DiagnosticWorkTitle (server .FromCheckUpgrades ), 1 , true ),
293
+ Diagnostics (env .AtRegexp ("go.mod" , `require` ), WithMessage ("can be upgraded" )),
294
+ ReadDiagnostics ("go.mod" , d ),
295
+ )
296
+
297
+ // Apply the diagnostics to a/go.mod.
298
+ env .ApplyQuickFixes ("go.mod" , d .Diagnostics )
299
+ env .AfterChange ()
300
+ if got := env .BufferText ("go.mod" ); got != wantGoModA {
301
+ t .Fatalf ("go.mod upgrade failed:\n %s" , compare .Text (wantGoModA , got ))
302
+ }
303
+ })
304
+ }
305
+
249
306
func TestUnusedDependenciesCodelens (t * testing.T ) {
250
307
const proxy = `
251
308
-- golang.org/x/[email protected] /go.mod --
0 commit comments