TestWorkspaceFindUp verifies that Workspace.findUp searches up from the start path and stops at the workspace boundary.
(ctx context.Context, t *testctx.T)
| 102 | // TestWorkspaceFindUp verifies that Workspace.findUp searches up from the |
| 103 | // start path and stops at the workspace boundary. |
| 104 | func (WorkspaceSuite) TestFindUp(ctx context.Context, t *testctx.T) { |
| 105 | c := connect(ctx, t) |
| 106 | |
| 107 | base := workspaceBase(t, c). |
| 108 | WithNewFile("root.txt", "at root"). |
| 109 | WithNewFile("a/target.txt", "in a"). |
| 110 | WithNewFile("a/b/other.txt", "in a/b"). |
| 111 | WithExec([]string{"mkdir", "-p", "a/b/c"}). |
| 112 | WithNewFile("a/b/c/leaf.txt", "leaf"). |
| 113 | WithExec([]string{"mkdir", "-p", "a/somedir"}). |
| 114 | WithNewFile("a/somedir/hi.txt", "hi"). |
| 115 | With(initStandaloneDangModule("finder", ` |
| 116 | type Finder { |
| 117 | pub result: String! |
| 118 | |
| 119 | new(ws: Workspace!, name: String!, from: String!) { |
| 120 | self.result = ws.findUp(name: name, from: from) ?? "" |
| 121 | self |
| 122 | } |
| 123 | } |
| 124 | `)) |
| 125 | |
| 126 | t.Run("find file in start directory", func(ctx context.Context, t *testctx.T) { |
| 127 | out, err := base.With(daggerCall("--name=other.txt", "--from=a/b", "result")).Stdout(ctx) |
| 128 | require.NoError(t, err) |
| 129 | require.Equal(t, "/a/b/other.txt", strings.TrimSpace(out)) |
| 130 | }) |
| 131 | |
| 132 | t.Run("find file in parent directory", func(ctx context.Context, t *testctx.T) { |
| 133 | out, err := base.With(daggerCall("--name=target.txt", "--from=a/b", "result")).Stdout(ctx) |
| 134 | require.NoError(t, err) |
| 135 | require.Equal(t, "/a/target.txt", strings.TrimSpace(out)) |
| 136 | }) |
| 137 | |
| 138 | t.Run("find file at workspace root", func(ctx context.Context, t *testctx.T) { |
| 139 | out, err := base.With(daggerCall("--name=root.txt", "--from=a/b", "result")).Stdout(ctx) |
| 140 | require.NoError(t, err) |
| 141 | require.Equal(t, "/root.txt", strings.TrimSpace(out)) |
| 142 | }) |
| 143 | |
| 144 | t.Run("find directory in parent", func(ctx context.Context, t *testctx.T) { |
| 145 | out, err := base.With(daggerCall("--name=somedir", "--from=a/b", "result")).Stdout(ctx) |
| 146 | require.NoError(t, err) |
| 147 | require.Equal(t, "/a/somedir", strings.TrimSpace(out)) |
| 148 | }) |
| 149 | |
| 150 | t.Run("do not find file in child directory", func(ctx context.Context, t *testctx.T) { |
| 151 | out, err := base.With(daggerCall("--name=leaf.txt", "--from=a/b", "result")).Stdout(ctx) |
| 152 | require.NoError(t, err) |
| 153 | require.Equal(t, "", strings.TrimSpace(out)) |
| 154 | }) |
| 155 | |
| 156 | t.Run("do not find non-existent file", func(ctx context.Context, t *testctx.T) { |
| 157 | out, err := base.With(daggerCall("--name=nonexistent.txt", "--from=a/b", "result")).Stdout(ctx) |
| 158 | require.NoError(t, err) |
| 159 | require.Equal(t, "", strings.TrimSpace(out)) |
| 160 | }) |
| 161 | } |
nothing calls this directly
no test coverage detected