Use native pipeline discovery and independent secrets bootstrap
This commit is contained in:
@@ -9,8 +9,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
func TestPipelineLoadSkipsAbsentConventionalSecretsDirectory(t *testing.T) {
|
||||
@@ -39,6 +39,27 @@ func TestPipelineLoadSkipsAbsentConventionalSecretsDirectory(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPipelineLoadUsesIndependentConventionalSecretsDirectory(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
previous := conventionalSecretsDirectory
|
||||
conventionalSecretsDirectory = dir
|
||||
t.Cleanup(func() { conventionalSecretsDirectory = previous })
|
||||
const name = "NARRATIO_TEST_CONVENTIONAL_SECRET"
|
||||
restoreEnvAfterTest(t, name)
|
||||
mustWriteSecretFile(t, filepath.Join(dir, name), "synthetic-value\n")
|
||||
pipelinePath := filepath.Join(t.TempDir(), "pipeline.yml")
|
||||
if err := os.WriteFile(pipelinePath, []byte("notarius:\n enabled: false\n credentials: ["+name+"]\n"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, pipeline, err := loadPipelineConfigWithDependencies(pipelinePath, config.PipelineLoadOptions{}, nil, commandDependencies{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := pipeline.Notarius.Credentials[0].Value(); got != "synthetic-value" {
|
||||
t.Fatal("conventional directory credential was not resolved")
|
||||
}
|
||||
}
|
||||
|
||||
func TestExplicitSecretsDirectoryIsResolvedFromCallerWorkingDirectory(t *testing.T) {
|
||||
callerDir := t.TempDir()
|
||||
selected := filepath.Join(callerDir, "credentials")
|
||||
@@ -54,7 +75,7 @@ func TestExplicitSecretsDirectoryIsResolvedFromCallerWorkingDirectory(t *testing
|
||||
}
|
||||
t.Cleanup(func() { _ = os.Chdir(original) })
|
||||
|
||||
got, required, err := selectedSecretsDirectory(filepath.Join(t.TempDir(), "pipeline.yml"), stringPointer("credentials"))
|
||||
got, required, err := selectedSecretsDirectory(stringPointer("credentials"))
|
||||
if err != nil {
|
||||
t.Fatalf("select secrets: %v", err)
|
||||
}
|
||||
@@ -103,7 +124,7 @@ func TestSecretsBootstrapPreservesExistingEnvironmentValues(t *testing.T) {
|
||||
|
||||
bootstrap := &secretsBootstrap{selection: &directory, selectionSet: true}
|
||||
var diagnostics bytes.Buffer
|
||||
if err := bootstrap.load(filepath.Join(t.TempDir(), "pipeline.yml"), configkit.LoadSecretsIntoEnvironment, &diagnostics); err != nil {
|
||||
if err := bootstrap.load(configkit.LoadSecretsIntoEnvironment, &diagnostics); err != nil {
|
||||
t.Fatalf("bootstrap: %v", err)
|
||||
}
|
||||
if got := diagnostics.String(); !strings.Contains(got, `status="skipped_existing"`) || !strings.Contains(got, `existing_empty=true`) {
|
||||
@@ -128,7 +149,6 @@ func TestNotariusCredentialLoadsFromCommandSecretBootstrap(t *testing.T) {
|
||||
fileValue string
|
||||
wantValue string
|
||||
}{
|
||||
{name: "conventional", fileValue: "conventional-value", wantValue: "conventional-value"},
|
||||
{name: "explicit", explicit: true, fileValue: "explicit-value", wantValue: "explicit-value"},
|
||||
{name: "environment precedence", explicit: true, environment: "environment-value", fileValue: "file-value", wantValue: "environment-value"},
|
||||
}
|
||||
@@ -170,7 +190,7 @@ func TestSecretsBootstrapPreservesSafePartialReportOnFailure(t *testing.T) {
|
||||
directory := t.TempDir()
|
||||
mustWriteSecretFile(t, filepath.Join(directory, "INVALID-NAME"), "must-not-appear\n")
|
||||
bootstrap := &secretsBootstrap{selection: &directory, selectionSet: true}
|
||||
err := bootstrap.load(filepath.Join(t.TempDir(), "pipeline.yml"), configkit.LoadSecretsIntoEnvironment, io.Discard)
|
||||
err := bootstrap.load(configkit.LoadSecretsIntoEnvironment, io.Discard)
|
||||
if err == nil {
|
||||
t.Fatal("bootstrap succeeded, want error")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user