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

Method TestStateInterpolation

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

Source from the content-addressed store, hash-verified

819}
820
821func (ShellSuite) TestStateInterpolation(ctx context.Context, t *testctx.T) {
822 c := connect(ctx, t)
823 modGen := daggerCliBase(t, c)
824
825 for _, tc := range []struct {
826 name string
827 prompt string
828 expected string
829 }{
830 {
831 name: "single state result",
832 prompt: `$($FOO | name)`,
833 expected: "foo",
834 },
835 {
836 name: "interpolated command",
837 prompt: `.$($FOO | contents) hello`,
838 expected: "hello\n",
839 },
840 {
841 name: "single state argument",
842 prompt: `directory | with-new-file test $($FOO | name) | file test | contents`,
843 expected: "foo",
844 },
845 {
846 name: "multiple state argument",
847 prompt: `directory | with-new-file ./$($FOO | name)_$($BAR | name).txt foobar | entries`,
848 expected: "foo_bar.txt\n",
849 },
850 {
851 name: "command argument",
852 prompt: `.ls ./$($FOO | name)/$($BAR | name)`,
853 expected: "foobar.txt\n",
854 },
855 } {
856 t.Run(tc.name, func(ctx context.Context, t *testctx.T) {
857 script := []string{
858 "FOO=$(directory | with-new-file foo echo | file foo)",
859 "BAR=$(directory | with-new-file bar directory | file bar)",
860 }
861 out, err := modGen.
862 WithNewFile("foo/bar/foobar.txt", "foobar").
863 With(daggerShellNoMod(strings.Join(append(script, tc.prompt), "\n"))).
864 Stdout(ctx)
865 require.NoError(t, err)
866 require.Equal(t, tc.expected, out)
867 })
868 }
869
870 // Don't use `_echo` because it'll just spit out whatever we give it
871 // to stdout, which will be picked up by the state resolution at
872 // the end of the run.
873 for _, prefix := range []string{"_", "."} {
874 t.Run("builtin argument with "+prefix, func(ctx context.Context, t *testctx.T) {
875 script := prefix + "exit $(directory | with-new-file exit_code 5 | file exit_code | contents)"
876 _, err := modGen.With(daggerShellNoMod(script)).Sync(ctx)
877 var execErr *dagger.ExecError
878 require.ErrorAs(t, err, &execErr)

Callers

nothing calls this directly

Calls 9

daggerCliBaseFunction · 0.85
daggerShellNoModFunction · 0.85
connectFunction · 0.70
RunMethod · 0.65
EqualMethod · 0.65
SyncMethod · 0.65
StdoutMethod · 0.45
WithMethod · 0.45
WithNewFileMethod · 0.45

Tested by

no test coverage detected