MCPcopy Index your code
hub / github.com/dagger/dagger / TestWorkdirExcludeInclude

Method TestWorkdirExcludeInclude

core/integration/host_test.go:70–151  ·  view source on GitHub ↗
(ctx context.Context, t *testctx.T)

Source from the content-addressed store, hash-verified

68}
69
70func (HostSuite) TestWorkdirExcludeInclude(ctx context.Context, t *testctx.T) {
71 dir := t.TempDir()
72 require.NoError(t, os.WriteFile(filepath.Join(dir, "a.txt"), []byte("1"), 0o600))
73 require.NoError(t, os.WriteFile(filepath.Join(dir, "b.txt"), []byte("2"), 0o600))
74 require.NoError(t, os.WriteFile(filepath.Join(dir, "c.txt.rar"), []byte("3"), 0o600))
75 require.NoError(t, os.MkdirAll(filepath.Join(dir, "subdir"), 0o755))
76 require.NoError(t, os.WriteFile(filepath.Join(dir, "subdir", "sub-file"), []byte("goodbye"), 0o600))
77
78 c := connect(ctx, t, dagger.WithWorkdir(dir))
79
80 t.Run("exclude", func(ctx context.Context, t *testctx.T) {
81 wd := c.Host().Directory(".", dagger.HostDirectoryOpts{
82 Exclude: []string{"*.rar"},
83 })
84
85 contents, err := c.Container().
86 From(alpineImage).
87 WithMountedDirectory("/host", wd).
88 WithExec([]string{"ls", "/host"}).
89 Stdout(ctx)
90 require.NoError(t, err)
91 require.Equal(t, "a.txt\nb.txt\nsubdir\n", contents)
92 })
93
94 t.Run("exclude directory", func(ctx context.Context, t *testctx.T) {
95 wd := c.Host().Directory(".", dagger.HostDirectoryOpts{
96 Exclude: []string{"subdir"},
97 })
98
99 contents, err := c.Container().
100 From(alpineImage).
101 WithMountedDirectory("/host", wd).
102 WithExec([]string{"ls", "/host"}).
103 Stdout(ctx)
104 require.NoError(t, err)
105 require.Equal(t, "a.txt\nb.txt\nc.txt.rar\n", contents)
106 })
107
108 t.Run("include", func(ctx context.Context, t *testctx.T) {
109 wd := c.Host().Directory(".", dagger.HostDirectoryOpts{
110 Include: []string{"*.rar"},
111 })
112
113 contents, err := c.Container().
114 From(alpineImage).
115 WithMountedDirectory("/host", wd).
116 WithExec([]string{"ls", "/host"}).
117 Stdout(ctx)
118 require.NoError(t, err)
119 require.Equal(t, "c.txt.rar\n", contents)
120 })
121
122 t.Run("exclude overrides include", func(ctx context.Context, t *testctx.T) {
123 wd := c.Host().Directory(".", dagger.HostDirectoryOpts{
124 Include: []string{"*.txt"},
125 Exclude: []string{"b.txt"},
126 })
127

Callers

nothing calls this directly

Calls 13

MkdirAllMethod · 0.80
connectFunction · 0.70
RunMethod · 0.65
DirectoryMethod · 0.65
HostMethod · 0.65
EqualMethod · 0.65
WriteFileMethod · 0.45
WithWorkdirMethod · 0.45
StdoutMethod · 0.45
WithExecMethod · 0.45
WithMountedDirectoryMethod · 0.45
FromMethod · 0.45

Tested by

no test coverage detected