TestNestedWorkspacePaths verifies that relative paths use the workspace directory while absolute paths and upward search use the workspace boundary.
(ctx context.Context, t *testctx.T)
| 163 | // TestNestedWorkspacePaths verifies that relative paths use the workspace |
| 164 | // directory while absolute paths and upward search use the workspace boundary. |
| 165 | func (WorkspaceSuite) TestNestedWorkspacePaths(ctx context.Context, t *testctx.T) { |
| 166 | c := connect(ctx, t) |
| 167 | |
| 168 | ctr := workspaceBase(t, c). |
| 169 | WithExec([]string{"mkdir", "-p", "app"}). |
| 170 | WithNewFile("repo.txt", "hello from boundary"). |
| 171 | WithNewFile("app/app.txt", "hello from workspace"). |
| 172 | WithWorkdir("/work/app"). |
| 173 | With(initStandaloneDangModule("paths", ` |
| 174 | type Paths { |
| 175 | pub workspaceValue: String! |
| 176 | pub boundaryValue: String! |
| 177 | pub foundValue: String! |
| 178 | pub workspacePath: String! |
| 179 | pub workspaceAddress: String! |
| 180 | |
| 181 | new(ws: Workspace!) { |
| 182 | self.workspaceValue = ws.file("app.txt").contents |
| 183 | self.boundaryValue = ws.file("/repo.txt").contents |
| 184 | self.foundValue = ws.findUp(name: "repo.txt", from: ".") ?? "" |
| 185 | self.workspacePath = ws.path |
| 186 | self.workspaceAddress = ws.address |
| 187 | self |
| 188 | } |
| 189 | } |
| 190 | `)) |
| 191 | |
| 192 | out, err := ctr.With(daggerCall("workspace-value")).Stdout(ctx) |
| 193 | require.NoError(t, err) |
| 194 | require.Equal(t, "hello from workspace", strings.TrimSpace(out)) |
| 195 | |
| 196 | out, err = ctr.With(daggerCall("boundary-value")).Stdout(ctx) |
| 197 | require.NoError(t, err) |
| 198 | require.Equal(t, "hello from boundary", strings.TrimSpace(out)) |
| 199 | |
| 200 | out, err = ctr.With(daggerCall("found-value")).Stdout(ctx) |
| 201 | require.NoError(t, err) |
| 202 | require.Equal(t, "/repo.txt", strings.TrimSpace(out)) |
| 203 | |
| 204 | out, err = ctr.With(daggerCall("workspace-path")).Stdout(ctx) |
| 205 | require.NoError(t, err) |
| 206 | require.Equal(t, "app", strings.TrimSpace(out)) |
| 207 | |
| 208 | out, err = ctr.With(daggerCall("workspace-address")).Stdout(ctx) |
| 209 | require.NoError(t, err) |
| 210 | require.Equal(t, "file:///work/app", strings.TrimSpace(out)) |
| 211 | } |
| 212 | |
| 213 | // TestWorkspaceArg verifies that a module function accepting a Workspace |
| 214 | // argument can access the host filesystem. |
nothing calls this directly
no test coverage detected