(ctx context.Context, t *testctx.T)
| 483 | } |
| 484 | |
| 485 | func (EnvFileSuite) TestSecretFile(ctx context.Context, t *testctx.T) { |
| 486 | modDir := t.TempDir() |
| 487 | |
| 488 | initCmd := hostDaggerCommand(ctx, t, modDir, "init", "--source=.", "--name=test", "--sdk=go") |
| 489 | initOutput, err := initCmd.CombinedOutput() |
| 490 | require.NoError(t, err, string(initOutput)) |
| 491 | |
| 492 | err = os.WriteFile(filepath.Join(modDir, "main.go"), []byte(`package main |
| 493 | import ( |
| 494 | "context" |
| 495 | ) |
| 496 | |
| 497 | type Test struct {} |
| 498 | |
| 499 | func (m *Test) Foo(ctx context.Context) (string, error) { |
| 500 | return dag.Dep().Bar(ctx) |
| 501 | } |
| 502 | `), 0644) |
| 503 | require.NoError(t, err) |
| 504 | |
| 505 | depDir := filepath.Join(modDir, "dep") |
| 506 | require.NoError(t, os.Mkdir(depDir, 0755)) |
| 507 | |
| 508 | initDepCmd := hostDaggerCommand(ctx, t, depDir, "init", "--source=.", "--name=dep", "--sdk=go") |
| 509 | initDepOutput, err := initDepCmd.CombinedOutput() |
| 510 | require.NoError(t, err, string(initDepOutput)) |
| 511 | |
| 512 | err = os.WriteFile(filepath.Join(depDir, "main.go"), []byte(`package main |
| 513 | import ( |
| 514 | "context" |
| 515 | "encoding/base64" |
| 516 | |
| 517 | "dagger/dep/internal/dagger" |
| 518 | ) |
| 519 | |
| 520 | type Dep struct {} |
| 521 | |
| 522 | func (m *Dep) Bar( |
| 523 | ctx context.Context, |
| 524 | // +optional |
| 525 | s *dagger.Secret, |
| 526 | ) (string, error) { |
| 527 | pt, err := s.Plaintext(ctx) |
| 528 | if err != nil { |
| 529 | return "", err |
| 530 | } |
| 531 | return base64.StdEncoding.EncodeToString([]byte(pt)), nil |
| 532 | } |
| 533 | `), 0644) |
| 534 | require.NoError(t, err) |
| 535 | |
| 536 | installCmd := hostDaggerCommand(ctx, t, modDir, "install", depDir) |
| 537 | installOutput, err := installCmd.CombinedOutput() |
| 538 | require.NoError(t, err, string(installOutput)) |
| 539 | |
| 540 | secretFile := filepath.Join(depDir, "topsecret.txt") |
| 541 | err = os.WriteFile(secretFile, []byte(`doodoo`), 0644) |
| 542 | require.NoError(t, err) |
nothing calls this directly
no test coverage detected