MCPcopy Create free account
hub / github.com/dagger/dagger / TestSystemGoProxy

Method TestSystemGoProxy

core/integration/proxy_test.go:470–595  ·  view source on GitHub ↗
(ctx context.Context, t *testctx.T)

Source from the content-addressed store, hash-verified

468}
469
470func (ContainerSuite) TestSystemGoProxy(ctx context.Context, t *testctx.T) {
471 c := connect(ctx, t)
472
473 // Just a subset of modules we expect to be downloaded since trying to go one to one would
474 // be too fragile whenever the SDK changes.
475 // NOTE: this is also impacted by engine pre-caching of SDK deps, so what shows up here are
476 // deps in testGitModuleRef that aren't pre-cached.
477 // If updating this test becomes a nuisance, we might want to use a custom test git module ref
478 // that specifically has some extra deps not in the Go SDK.
479 expectedGoModDownloads := []string{
480 "github.com/andreyvit/diff",
481 "github.com/davecgh/go-spew",
482 "github.com/go-logr/logr",
483 }
484
485 executeTestEnvName := fmt.Sprintf("DAGGER_TEST_%s", strings.ToUpper(t.Name()))
486 if os.Getenv(executeTestEnvName) == "" {
487 const goProxyAlias = "goproxy"
488 const goProxyPort = 8080
489 goProxySetting := fmt.Sprintf("http://%s:%d", goProxyAlias, goProxyPort)
490
491 fetcher := &goProxyFetcher{dlPaths: make(map[string]struct{})}
492 proxy := &goproxy.Goproxy{Fetcher: fetcher}
493
494 l, err := net.Listen("tcp", "127.0.0.1:0")
495 require.NoError(t, err)
496 t.Cleanup(func() {
497 l.Close()
498 })
499 port := l.Addr().(*net.TCPAddr).Port
500
501 goProxyCtx, cancelGoProxy := context.WithCancel(ctx)
502 t.Cleanup(cancelGoProxy)
503 srv := http.Server{
504 Handler: proxy,
505 ReadHeaderTimeout: 30 * time.Second,
506 BaseContext: func(net.Listener) context.Context {
507 return goProxyCtx
508 },
509 }
510 t.Cleanup(func() {
511 srv.Shutdown(context.Background())
512 })
513
514 goProxyDone := make(chan error, 1)
515 go func() {
516 goProxyDone <- srv.Serve(l)
517 }()
518
519 goProxySvc := c.Host().Service([]dagger.PortForward{{
520 Backend: port,
521 Frontend: goProxyPort,
522 }})
523
524 devEngine := devEngineContainer(c, func(ctr *dagger.Container) *dagger.Container {
525 return ctr.
526 WithServiceBinding(goProxyAlias, goProxySvc).
527 WithEnvVariable("_DAGGER_ENGINE_SYSTEMENV_GOPROXY", goProxySetting)

Callers

nothing calls this directly

Calls 15

devEngineContainerFunction · 0.85
goCacheFunction · 0.85
daggerCliFileFunction · 0.85
goGitBaseFunction · 0.85
testOnMultipleVCSFunction · 0.85
daggerCallAtFunction · 0.85
testGitModuleRefFunction · 0.85
CleanupMethod · 0.80
AddrMethod · 0.80
connectFunction · 0.70
NameMethod · 0.65

Tested by

no test coverage detected