(ctx context.Context, t *testctx.T)
| 7406 | } |
| 7407 | |
| 7408 | func (ModuleSuite) TestFunctionCacheControl(ctx context.Context, t *testctx.T) { |
| 7409 | for _, tc := range []struct { |
| 7410 | sdk string |
| 7411 | source string |
| 7412 | }{ |
| 7413 | { |
| 7414 | // TODO: add test that function doc strings still get parsed correctly, don't include //+ etc. |
| 7415 | sdk: "go", |
| 7416 | source: `package main |
| 7417 | |
| 7418 | import ( |
| 7419 | "crypto/rand" |
| 7420 | ) |
| 7421 | |
| 7422 | type Test struct{} |
| 7423 | |
| 7424 | // My cool doc on TestTtl |
| 7425 | // +cache="40s" |
| 7426 | func (m *Test) TestTtl() string { |
| 7427 | return rand.Text() |
| 7428 | } |
| 7429 | |
| 7430 | // My dope doc on TestCachePerSession |
| 7431 | // +cache="session" |
| 7432 | func (m *Test) TestCachePerSession() string { |
| 7433 | return rand.Text() |
| 7434 | } |
| 7435 | |
| 7436 | // My darling doc on TestNeverCache |
| 7437 | // +cache="never" |
| 7438 | func (m *Test) TestNeverCache() string { |
| 7439 | return rand.Text() |
| 7440 | } |
| 7441 | |
| 7442 | // My rad doc on TestAlwaysCache |
| 7443 | func (m *Test) TestAlwaysCache() string { |
| 7444 | return rand.Text() |
| 7445 | } |
| 7446 | `, |
| 7447 | }, |
| 7448 | { |
| 7449 | sdk: "python", |
| 7450 | source: `import dagger |
| 7451 | import random |
| 7452 | import string |
| 7453 | |
| 7454 | @dagger.object_type |
| 7455 | class Test: |
| 7456 | @dagger.function(cache="40s") |
| 7457 | def test_ttl(self) -> str: |
| 7458 | return ''.join(random.choices(string.ascii_lowercase + string.digits, k=10)) |
| 7459 | |
| 7460 | @dagger.function(cache="session") |
| 7461 | def test_cache_per_session(self) -> str: |
| 7462 | return ''.join(random.choices(string.ascii_lowercase + string.digits, k=10)) |
| 7463 | |
| 7464 | @dagger.function(cache="never") |
| 7465 | def test_never_cache(self) -> str: |
nothing calls this directly
no test coverage detected