TestRenamedToolchainModule verifies that a toolchain module renamed via the workspace config "name" field still has its constructor correctly synthesized on Query. The SDK type keeps its original name (e.g. "HelloWorld") but the module is installed under the alias (e.g. "greeter"). The namespaceObje
(ctx context.Context, t *testctx.T)
| 1242 | // The namespaceObject function rewrites the main object's Name to match the |
| 1243 | // alias, so this has always worked, but this test makes the coverage explicit. |
| 1244 | func (WorkspaceSuite) TestRenamedToolchainModule(ctx context.Context, t *testctx.T) { |
| 1245 | c := connect(ctx, t) |
| 1246 | |
| 1247 | // Create a module named "hello-world" but install it as "greeter". |
| 1248 | base := workspaceBase(t, c). |
| 1249 | WithWorkdir("toolchains/hello-world"). |
| 1250 | With(daggerExec("init", "--sdk=dang", "--name=hello-world")). |
| 1251 | WithNewFile("main.dang", ` |
| 1252 | type HelloWorld { |
| 1253 | pub greet(name: String! = "world"): String! { |
| 1254 | "hello, " + name + "!" |
| 1255 | } |
| 1256 | } |
| 1257 | `). |
| 1258 | WithWorkdir("../../"). |
| 1259 | With(daggerExec("init")). |
| 1260 | WithNewFile("dagger.json", ` |
| 1261 | { |
| 1262 | "name": "app", |
| 1263 | "engineVersion": "v0.19.4", |
| 1264 | "toolchains": [ |
| 1265 | { |
| 1266 | "name": "greeter", |
| 1267 | "source": "./toolchains/hello-world" |
| 1268 | } |
| 1269 | ] |
| 1270 | } |
| 1271 | `) |
| 1272 | |
| 1273 | t.Run("constructor appears under renamed alias", func(ctx context.Context, t *testctx.T) { |
| 1274 | out, err := base.With(daggerCall("greeter", "greet")).Stdout(ctx) |
| 1275 | require.NoError(t, err) |
| 1276 | require.Equal(t, "hello, world!", strings.TrimSpace(out)) |
| 1277 | }) |
| 1278 | |
| 1279 | t.Run("constructor accepts args", func(ctx context.Context, t *testctx.T) { |
| 1280 | out, err := base.With(daggerCall("greeter", "greet", "--name", "dagger")).Stdout(ctx) |
| 1281 | require.NoError(t, err) |
| 1282 | require.Equal(t, "hello, dagger!", strings.TrimSpace(out)) |
| 1283 | }) |
| 1284 | |
| 1285 | t.Run("functions list shows renamed alias", func(ctx context.Context, t *testctx.T) { |
| 1286 | out, err := base.With(daggerFunctions()).Stdout(ctx) |
| 1287 | require.NoError(t, err) |
| 1288 | require.Contains(t, out, "greeter") |
| 1289 | }) |
| 1290 | |
| 1291 | t.Run("dagger shell renamed alias", func(ctx context.Context, t *testctx.T) { |
| 1292 | out, err := base.With(daggerShell("greeter | greet")).Stdout(ctx) |
| 1293 | require.NoError(t, err) |
| 1294 | require.Equal(t, "hello, world!", out) |
| 1295 | }) |
| 1296 | |
| 1297 | t.Run("dagger shell renamed alias with args", func(ctx context.Context, t *testctx.T) { |
| 1298 | out, err := base.With(daggerShell("greeter | greet --name dagger")).Stdout(ctx) |
| 1299 | require.NoError(t, err) |
| 1300 | require.Equal(t, "hello, dagger!", out) |
| 1301 | }) |
nothing calls this directly
no test coverage detected