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

Method TestLoadAnotherModule

core/integration/module_shell_test.go:460–522  ·  view source on GitHub ↗
(ctx context.Context, t *testctx.T)

Source from the content-addressed store, hash-verified

458}
459
460func (ShellSuite) TestLoadAnotherModule(ctx context.Context, t *testctx.T) {
461 test := `package main
462
463type Test struct{}
464
465func (m *Test) Bar() string {
466 return "testbar"
467}
468`
469
470 foo := `package main
471
472func New() *Foo {
473 return &Foo{
474 Bar: "foobar",
475 }
476}
477
478type Foo struct{
479 Bar string
480}
481`
482 t.Run("main object", func(ctx context.Context, t *testctx.T) {
483 c := connect(ctx, t)
484 out, err := modInit(t, c, "go", test).
485 With(daggerExec("init", "--sdk=go", "--source=foo", "foo")).
486 With(sdkSourceAt("foo", "go", foo)).
487 With(daggerShell("foo")).
488 Stdout(ctx)
489 require.NoError(t, err)
490 require.Regexp(t, `Foo@xxh3:[a-f0-9]{16}`, out)
491 })
492
493 t.Run("stateful", func(ctx context.Context, t *testctx.T) {
494 c := connect(ctx, t)
495 out, err := modInit(t, c, "go", test).
496 With(daggerExec("init", "--sdk=go", "--source=foo", "foo")).
497 With(sdkSourceAt("foo", "go", foo)).
498 With(daggerShell(".cd foo; bar")).
499 Stdout(ctx)
500 require.NoError(t, err)
501 require.Contains(t, out, "foobar")
502 })
503
504 t.Run("stateless", func(ctx context.Context, t *testctx.T) {
505 c := connect(ctx, t)
506 modGen := modInit(t, c, "go", test).
507 With(daggerExec("init", "--sdk=go", "--source=foo", "foo")).
508 With(sdkSourceAt("foo", "go", foo))
509
510 out, err := modGen.
511 With(daggerShell("foo | bar")).
512 Stdout(ctx)
513 require.NoError(t, err)
514 require.Equal(t, "foobar", out)
515
516 out, err = modGen.
517 With(daggerShell("bar")).

Callers

nothing calls this directly

Calls 10

modInitFunction · 0.85
daggerExecFunction · 0.85
sdkSourceAtFunction · 0.85
daggerShellFunction · 0.85
connectFunction · 0.70
RunMethod · 0.65
ContainsMethod · 0.65
EqualMethod · 0.65
StdoutMethod · 0.45
WithMethod · 0.45

Tested by

no test coverage detected