(ctx context.Context, t *testctx.T)
| 547 | } |
| 548 | |
| 549 | func (ModuleSuite) TestCodegenOptionals(ctx context.Context, t *testctx.T) { |
| 550 | // Same code as TestOptionalDefaults since it guarantees this is being |
| 551 | // registered correctly and equally by all SDKs. |
| 552 | src := `package main |
| 553 | |
| 554 | import "fmt" |
| 555 | |
| 556 | type Dep struct {} |
| 557 | |
| 558 | func (m *Dep) Ctl( |
| 559 | a string, |
| 560 | // +optional |
| 561 | b *string, |
| 562 | // +default="foo" |
| 563 | c string, |
| 564 | // +default=null |
| 565 | d *string, |
| 566 | // +default="bar" |
| 567 | e *string, |
| 568 | ) string { |
| 569 | return fmt.Sprintf("%+v, %+v, %+v, %+v, %+v", a, b, c, d, *e) |
| 570 | } |
| 571 | ` |
| 572 | expected := "foo, <nil>, foo, <nil>, bar" |
| 573 | |
| 574 | for _, tc := range []struct { |
| 575 | sdk string |
| 576 | source string |
| 577 | }{ |
| 578 | { |
| 579 | sdk: "go", |
| 580 | source: `package main |
| 581 | |
| 582 | import "context" |
| 583 | |
| 584 | type Test struct {} |
| 585 | |
| 586 | func (m *Test) Test(ctx context.Context) (string, error) { |
| 587 | return dag.Dep().Ctl(ctx, "foo") |
| 588 | } |
| 589 | `, |
| 590 | }, |
| 591 | { |
| 592 | sdk: "python", |
| 593 | source: `import dagger |
| 594 | from dagger import dag |
| 595 | |
| 596 | |
| 597 | @dagger.object_type |
| 598 | class Test: |
| 599 | @dagger.function |
| 600 | async def test(self) -> str: |
| 601 | return await dag.dep().ctl("foo") |
| 602 | `, |
| 603 | }, |
| 604 | { |
| 605 | sdk: "typescript", |
| 606 | source: `import { dag, object, func } from "@dagger.io/dagger" |
nothing calls this directly
no test coverage detected