(ctx context.Context, t *testctx.T)
| 393 | } |
| 394 | |
| 395 | func (ModuleSuite) TestOptionalDefaults(ctx context.Context, t *testctx.T) { |
| 396 | // Test expressiveness for following schema: |
| 397 | // a: String! |
| 398 | // b: String |
| 399 | // c: String! = "foo" |
| 400 | // d: String = null |
| 401 | // e: String = "bar" |
| 402 | |
| 403 | for _, tc := range []struct { |
| 404 | sdk string |
| 405 | source string |
| 406 | expected string |
| 407 | }{ |
| 408 | { |
| 409 | sdk: "go", |
| 410 | source: `package main |
| 411 | |
| 412 | import "fmt" |
| 413 | |
| 414 | type Test struct{ } |
| 415 | |
| 416 | func (m *Test) Foo( |
| 417 | a string, |
| 418 | // +optional |
| 419 | b *string, |
| 420 | // +default="foo" |
| 421 | c string, |
| 422 | // +default=null |
| 423 | d *string, |
| 424 | // +default="bar" |
| 425 | e *string, |
| 426 | ) string { |
| 427 | return fmt.Sprintf("%+v, %+v, %+v, %+v, %+v", a, b, c, d, *e) |
| 428 | } |
| 429 | `, |
| 430 | expected: "test, <nil>, foo, <nil>, bar", |
| 431 | }, |
| 432 | { |
| 433 | sdk: "python", |
| 434 | source: `from dagger import field, function, object_type |
| 435 | |
| 436 | @object_type |
| 437 | class Test: |
| 438 | @function |
| 439 | def foo( |
| 440 | self, |
| 441 | a: str, |
| 442 | b: str | None, |
| 443 | c: str = "foo", |
| 444 | d: str | None = None, |
| 445 | e: str | None = "bar", |
| 446 | ) -> str: |
| 447 | return ", ".join(repr(x) for x in (a, b, c, d, e)) |
| 448 | `, |
| 449 | expected: "'test', None, 'foo', None, 'bar'", |
| 450 | }, |
| 451 | { |
| 452 | sdk: "typescript", |
nothing calls this directly
no test coverage detected