TestUnbundleSDK verifies that you can implement a SDK without having to implements the full interface but only the ones you want. cc: https://github.com/dagger/dagger/issues/7707
(ctx context.Context, t *testctx.T)
| 2327 | // having to implements the full interface but only the ones you want. |
| 2328 | // cc: https://github.com/dagger/dagger/issues/7707 |
| 2329 | func (ModuleSuite) TestUnbundleSDK(ctx context.Context, t *testctx.T) { |
| 2330 | t.Run("only codegen", func(ctx context.Context, t *testctx.T) { |
| 2331 | c := connect(ctx, t) |
| 2332 | |
| 2333 | ctr := c.Container().From(golangImage). |
| 2334 | WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). |
| 2335 | WithDirectory("/work/sdk", c.Host().Directory("./testdata/sdks/only-codegen")). |
| 2336 | WithWorkdir("/work"). |
| 2337 | With(daggerExec("init", "--name=test", "--sdk=./sdk", "--source=.")) |
| 2338 | |
| 2339 | t.Run("can run dagger develop", func(ctx context.Context, t *testctx.T) { |
| 2340 | generatedFile, err := ctr.With(daggerExec("develop")).File("/work/hello.txt").Contents(ctx) |
| 2341 | |
| 2342 | require.NoError(t, err) |
| 2343 | require.Equal(t, "Hello, world!", generatedFile) |
| 2344 | }) |
| 2345 | |
| 2346 | t.Run("explicit error on dagger call", func(ctx context.Context, t *testctx.T) { |
| 2347 | _, err := ctr.With(daggerExec("call", "foo")).Sync(ctx) |
| 2348 | |
| 2349 | requireErrOut(t, err, `"./sdk" SDK does not support defining and executing functions`) |
| 2350 | }) |
| 2351 | |
| 2352 | t.Run("explicit error on dagger functions", func(ctx context.Context, t *testctx.T) { |
| 2353 | _, err := ctr.With(daggerFunctions()).Sync(ctx) |
| 2354 | |
| 2355 | requireErrOut(t, err, `"./sdk" SDK does not support defining and executing functions`) |
| 2356 | }) |
| 2357 | }) |
| 2358 | |
| 2359 | t.Run("only runtime", func(ctx context.Context, t *testctx.T) { |
| 2360 | c := connect(ctx, t) |
| 2361 | |
| 2362 | ctr := c.Container().From(golangImage). |
| 2363 | WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). |
| 2364 | WithDirectory("/work/sdk", c.Host().Directory("./testdata/sdks/only-runtime")). |
| 2365 | WithWorkdir("/work"). |
| 2366 | With(daggerExec("init", "--name=test", "--sdk=./sdk", "--source=.")) |
| 2367 | |
| 2368 | t.Run("can run dagger develop without failing", func(ctx context.Context, t *testctx.T) { |
| 2369 | _, err := ctr.With(daggerExec("develop")).Sync(ctx) |
| 2370 | |
| 2371 | require.NoError(t, err) |
| 2372 | }) |
| 2373 | |
| 2374 | t.Run("can run dagger functions", func(ctx context.Context, t *testctx.T) { |
| 2375 | out, err := ctr.With(daggerFunctions()).Stdout(ctx) |
| 2376 | |
| 2377 | require.NoError(t, err) |
| 2378 | require.Contains(t, out, "hello-world") |
| 2379 | }) |
| 2380 | |
| 2381 | t.Run("can run dagger call", func(ctx context.Context, t *testctx.T) { |
| 2382 | out, err := ctr.With(daggerCall("hello-world")).Stdout(ctx) |
| 2383 | |
| 2384 | require.NoError(t, err) |
| 2385 | require.Contains(t, out, "Hello world") |
| 2386 | }) |
nothing calls this directly
no test coverage detected