Remove the secrets directory flag and update fixtures

This commit is contained in:
2026-11-23 14:23:53 +00:00
parent a4491a8517
commit 6175945230
30 changed files with 146 additions and 334 deletions

View File

@@ -4,23 +4,13 @@ import (
"context"
"os"
"path/filepath"
"strings"
"testing"
"gitea.maximumdirect.net/eric/narratio/internal/config"
configkit "go.maximumdirect.net/configkit"
)
func TestMain(m *testing.M) {
dir, err := os.MkdirTemp("", "narratio-app-test-*")
if err != nil {
panic(err)
}
conventionalSecretsDirectory = filepath.Join(dir, "secrets")
code := m.Run()
_ = os.RemoveAll(dir)
os.Exit(code)
}
// restoreEnvAfterTest clears names for a test and restores both their prior
// values and their set/unset state during cleanup.
func restoreEnvAfterTest(t *testing.T, names ...string) {
@@ -76,3 +66,38 @@ func guardedMissingPipelineDiscovery(t *testing.T) (commandDependencies, string,
}
return deps, candidate, executor
}
func configureTestSecrets(t *testing.T, pipeline, directory string) {
t.Helper()
destination := filepath.Join(filepath.Dir(pipeline), "test-secrets")
entries, err := os.ReadDir(directory)
if err == nil {
if err := os.MkdirAll(destination, 0700); err != nil {
t.Fatal(err)
}
for _, entry := range entries {
data, err := os.ReadFile(filepath.Join(directory, entry.Name()))
if err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(destination, entry.Name()), data, 0600); err != nil {
t.Fatal(err)
}
}
} else if !os.IsNotExist(err) {
t.Fatal(err)
}
data, err := os.ReadFile(pipeline)
if err != nil {
t.Fatal(err)
}
body := string(data)
if strings.Contains(body, "\nconfig:\n") || strings.HasPrefix(body, "config:\n") {
body = strings.Replace(body, "config:\n", "config:\n secrets_dir: test-secrets\n", 1)
} else {
body = "config: {secrets_dir: test-secrets}\n" + body
}
if err := os.WriteFile(pipeline, []byte(body), 0600); err != nil {
t.Fatal(err)
}
}