MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / TestConfig_MergeWithEncryptedFile

Function TestConfig_MergeWithEncryptedFile

internal/config/config_test.go:626–662  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

624}
625
626func TestConfig_MergeWithEncryptedFile(t *testing.T) {
627 if _, err := exec.LookPath("sops"); err != nil {
628 t.Skip("sops binary not available")
629 }
630
631 if os.Getenv("CI") != "" {
632 t.Skip("Skipping encrypted file test in CI environment")
633 }
634
635 tempDir := t.TempDir()
636
637 id, err := age.GenerateX25519Identity()
638 require.NoError(t, err)
639
640 keyPath := filepath.Join(tempDir, "key.txt")
641 require.NoError(t, os.WriteFile(keyPath, []byte(id.String()), 0o600))
642
643 plainPath := filepath.Join(tempDir, "plain.yaml")
644 require.NoError(t, os.WriteFile(plainPath, []byte("addr: https://enc.example.com\nuser: encuser\n"), 0o600))
645
646 // nolint:gosec // This is test code with controlled input
647 cmd := exec.Command("sops", "--encrypt", "--input-type", "yaml", "--output-type", "yaml", "--age", id.Recipient().String(), plainPath)
648
649 out, err := cmd.CombinedOutput()
650 if err != nil {
651 t.Skipf("sops encryption failed: %v\nstderr: %s", err, string(out))
652 }
653
654 encPath := filepath.Join(tempDir, "config.enc.yaml")
655 require.NoError(t, os.WriteFile(encPath, out, 0o600))
656
657 cfg := &Config{}
658 err = cfg.MergeWithFile(encPath)
659 require.NoError(t, err)
660 assert.Equal(t, "https://enc.example.com", cfg.Addr)
661 assert.Equal(t, "encuser", cfg.User)
662}
663
664func TestConfig_SetDefaults(t *testing.T) {
665 config := &Config{}

Callers

nothing calls this directly

Calls 2

MergeWithFileMethod · 0.95
StringMethod · 0.45

Tested by

no test coverage detected