|
1 | 1 | package modproxy |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "net/http" |
5 | | - "net/http/httptest" |
6 | | - "os" |
7 | 4 | "reflect" |
8 | 5 | "testing" |
9 | 6 |
|
10 | 7 | "github.com/icholy/gomajor/internal/modproxy/testmodproxy" |
11 | 8 | ) |
12 | 9 |
|
13 | | -type testProxy struct { |
14 | | - name string |
15 | | - url string |
16 | | -} |
17 | | - |
18 | | -func loadTestProxies(t *testing.T) []testProxy { |
19 | | - proxyfs, err := testmodproxy.LoadFS("testdata/modules") |
20 | | - if err != nil { |
21 | | - t.Fatal(err) |
22 | | - } |
23 | | - server := httptest.NewServer(http.FileServer(http.FS(proxyfs))) |
24 | | - t.Cleanup(func() { server.Close() }) |
25 | | - proxydir := t.TempDir() |
26 | | - if err := os.CopyFS(proxydir, proxyfs); err != nil { |
27 | | - t.Fatal(err) |
28 | | - } |
29 | | - return []testProxy{ |
30 | | - {name: "http", url: server.URL}, |
31 | | - {name: "file", url: "file://" + proxydir}, |
32 | | - } |
33 | | -} |
34 | | - |
35 | 10 | func TestModule(t *testing.T) { |
36 | 11 | tests := []struct { |
37 | 12 | mod *Module |
@@ -280,10 +255,10 @@ func TestQuery(t *testing.T) { |
280 | 255 | exist: false, |
281 | 256 | }, |
282 | 257 | } |
283 | | - proxies := loadTestProxies(t) |
| 258 | + proxies := testmodproxy.LoadProxies(t, "testdata/modules") |
284 | 259 | for _, proxy := range proxies { |
285 | | - t.Run(proxy.name, func(t *testing.T) { |
286 | | - t.Setenv("GOPROXY", proxy.url) |
| 260 | + t.Run(proxy.Name, func(t *testing.T) { |
| 261 | + t.Setenv("GOPROXY", proxy.URL) |
287 | 262 | for _, tt := range tests { |
288 | 263 | t.Run(tt.name, func(t *testing.T) { |
289 | 264 | mod, ok, err := Query(tt.modpath, false) |
@@ -337,10 +312,10 @@ func TestLatest(t *testing.T) { |
337 | 312 | }, |
338 | 313 | }, |
339 | 314 | } |
340 | | - proxies := loadTestProxies(t) |
| 315 | + proxies := testmodproxy.LoadProxies(t, "testdata/modules") |
341 | 316 | for _, proxy := range proxies { |
342 | | - t.Run(proxy.name, func(t *testing.T) { |
343 | | - t.Setenv("GOPROXY", proxy.url) |
| 317 | + t.Run(proxy.Name, func(t *testing.T) { |
| 318 | + t.Setenv("GOPROXY", proxy.URL) |
344 | 319 | for _, tt := range tests { |
345 | 320 | t.Run(tt.name, func(t *testing.T) { |
346 | 321 | mod, err := Latest(tt.modpath, false, tt.pre) |
@@ -379,10 +354,10 @@ func TestQueryPackage(t *testing.T) { |
379 | 354 | }, |
380 | 355 | }, |
381 | 356 | } |
382 | | - proxies := loadTestProxies(t) |
| 357 | + proxies := testmodproxy.LoadProxies(t, "testdata/modules") |
383 | 358 | for _, proxy := range proxies { |
384 | | - t.Run(proxy.name, func(t *testing.T) { |
385 | | - t.Setenv("GOPROXY", proxy.url) |
| 359 | + t.Run(proxy.Name, func(t *testing.T) { |
| 360 | + t.Setenv("GOPROXY", proxy.URL) |
386 | 361 | for _, tt := range tests { |
387 | 362 | t.Run(tt.name, func(t *testing.T) { |
388 | 363 | mod, err := QueryPackage(tt.pkgpath, false) |
|
0 commit comments