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

Method TestWorkspaceSubdirectory

core/integration/workspace_test.go:379–407  ·  view source on GitHub ↗

TestWorkspaceSubdirectory verifies that Workspace.directory can access a subdirectory of the workspace.

(ctx context.Context, t *testctx.T)

Source from the content-addressed store, hash-verified

377// TestWorkspaceSubdirectory verifies that Workspace.directory can access
378// a subdirectory of the workspace.
379func (WorkspaceSuite) TestWorkspaceSubdirectory(ctx context.Context, t *testctx.T) {
380 c := connect(ctx, t)
381
382 ctr := workspaceBase(t, c).
383 WithNewFile("sub/foo.txt", "foo").
384 WithNewFile("sub/bar.txt", "bar").
385 With(initDangModule("subdir", `
386type Subdir {
387 pub source: Directory!
388
389 new(source: Workspace!) {
390 self.source = source.directory("sub")
391 self
392 }
393
394 pub ls: [String!] {
395 source.entries
396 }
397}
398`))
399
400 out, err := ctr.With(daggerCall("subdir", "ls")).Stdout(ctx)
401 require.NoError(t, err)
402 entries := strings.TrimSpace(out)
403 require.Contains(t, entries, "foo.txt")
404 require.Contains(t, entries, "bar.txt")
405 // Should NOT contain top-level workspace files.
406 require.NotContains(t, entries, "sub/")
407}
408
409// TestWorkspacePathTraversal verifies that a module cannot use Workspace to
410// escape the workspace root and access arbitrary host paths.

Callers

nothing calls this directly

Calls 8

workspaceBaseFunction · 0.85
daggerCallFunction · 0.85
connectFunction · 0.70
initDangModuleFunction · 0.70
ContainsMethod · 0.65
WithMethod · 0.45
WithNewFileMethod · 0.45
StdoutMethod · 0.45

Tested by

no test coverage detected