MCPcopy Create free account
hub / github.com/dagger/dagger / TestSecretFile

Method TestSecretFile

core/integration/envfile_test.go:485–567  ·  view source on GitHub ↗
(ctx context.Context, t *testctx.T)

Source from the content-addressed store, hash-verified

483}
484
485func (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
493import (
494 "context"
495)
496
497type Test struct {}
498
499func (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
513import (
514 "context"
515 "encoding/base64"
516
517 "dagger/dep/internal/dagger"
518)
519
520type Dep struct {}
521
522func (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)

Callers

nothing calls this directly

Calls 5

hostDaggerCommandFunction · 0.85
EqualMethod · 0.65
CombinedOutputMethod · 0.45
WriteFileMethod · 0.45
MkdirMethod · 0.45

Tested by

no test coverage detected