TestWorkspaceArg verifies that a module function accepting a Workspace argument can access the host filesystem.
(ctx context.Context, t *testctx.T)
| 213 | // TestWorkspaceArg verifies that a module function accepting a Workspace |
| 214 | // argument can access the host filesystem. |
| 215 | func (WorkspaceSuite) TestWorkspaceArg(ctx context.Context, t *testctx.T) { |
| 216 | c := connect(ctx, t) |
| 217 | |
| 218 | ctr := workspaceBase(t, c). |
| 219 | WithNewFile("hello.txt", "hello from workspace"). |
| 220 | With(initDangModule("greeter", ` |
| 221 | type Greeter { |
| 222 | pub source: Directory! |
| 223 | |
| 224 | new(source: Workspace!) { |
| 225 | self.source = source.directory(".") |
| 226 | self |
| 227 | } |
| 228 | |
| 229 | pub read: String! { |
| 230 | source.file("hello.txt").contents |
| 231 | } |
| 232 | } |
| 233 | `)) |
| 234 | |
| 235 | t.Run("dagger call", func(ctx context.Context, t *testctx.T) { |
| 236 | out, err := ctr.With(daggerCall("greeter", "read")).Stdout(ctx) |
| 237 | require.NoError(t, err) |
| 238 | require.Equal(t, "hello from workspace", strings.TrimSpace(out)) |
| 239 | }) |
| 240 | |
| 241 | t.Run("dagger shell", func(ctx context.Context, t *testctx.T) { |
| 242 | out, err := ctr.With(daggerShell("greeter | read")).Stdout(ctx) |
| 243 | require.NoError(t, err) |
| 244 | require.Equal(t, "hello from workspace", out) |
| 245 | }) |
| 246 | } |
| 247 | |
| 248 | // TestWorkspaceDirectoryEntries verifies that Workspace.directory returns the |
| 249 | // correct entries from the host filesystem. |
nothing calls this directly
no test coverage detected