66 lines
1.9 KiB
Go
66 lines
1.9 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestPipelineMaterializationPreservesFinalValuesWithoutResolvingCredentialsAgain(t *testing.T) {
|
|
const name = "NARRATIO_SNAPSHOT_TEST_KEY"
|
|
const secret = "synthetic-snapshot-secret"
|
|
t.Setenv(name, secret)
|
|
path := writePipelineFixture(t, t.TempDir(), "pipeline.yml", testTranscriptionConfig+`audita:
|
|
credentials: [NARRATIO_SNAPSHOT_TEST_KEY]
|
|
scriptorium:
|
|
artifact_families:
|
|
character_notes:
|
|
enabled: false
|
|
for_each: party.characters
|
|
output_path_pattern: artifacts/{character_id}.md
|
|
artifacts:
|
|
recap:
|
|
vars:
|
|
title: synthetic-title
|
|
`)
|
|
cfg, err := LoadPipeline(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.Unsetenv(name); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := recomputePipelineEffectiveDigest(cfg); err != nil {
|
|
t.Fatalf("snapshot resolved credentials again: %v", err)
|
|
}
|
|
data, err := MarshalEffectivePipeline(cfg)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, expected := range []string{name, "synthetic-title", "character_notes:", "artifact_families:"} {
|
|
if !strings.Contains(string(data), expected) {
|
|
t.Fatalf("snapshot missing %q: %s", expected, data)
|
|
}
|
|
}
|
|
if strings.Contains(string(data), secret) {
|
|
t.Fatal("snapshot exposed resolved credential")
|
|
}
|
|
}
|
|
|
|
func TestPipelineMaterializationKeepsEmptyCredentialListDistinctFromNull(t *testing.T) {
|
|
dir := t.TempDir()
|
|
nullPath := writePipelineFixture(t, dir, "null.yml", testTranscriptionConfig+"audita: {credentials: null}\n")
|
|
emptyPath := writePipelineFixture(t, dir, "empty.yml", testTranscriptionConfig+"audita: {credentials: []}\n")
|
|
nullConfig, err := LoadPipeline(nullPath)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
emptyConfig, err := LoadPipeline(emptyPath)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if EffectivePipelineDigest(nullConfig) == EffectivePipelineDigest(emptyConfig) {
|
|
t.Fatal("null and empty credentials have the same digest")
|
|
}
|
|
}
|