51 lines
1.8 KiB
Go
51 lines
1.8 KiB
Go
package config
|
|
|
|
import (
|
|
"reflect"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestAuthoredPublishOutputCollectionOperations(t *testing.T) {
|
|
dir := t.TempDir()
|
|
root := writePipelineFixture(t, dir, "pipeline.yml", `config:
|
|
sequences:
|
|
- destination: [publish, outputs]
|
|
key: source
|
|
publish:
|
|
outputs:
|
|
- {source: narratio.transcript.final_markdown, dest: transcripts/base.md, required: true}
|
|
`)
|
|
for _, tc := range []struct {
|
|
name string
|
|
mode string
|
|
body string
|
|
want []string
|
|
}{
|
|
{"append", "append", "[{source: narratio.transcript.final_trimmed, dest: transcripts/extra.json, required: false}]", []string{"transcripts/base.md", "transcripts/extra.json"}},
|
|
{"upsert", "upsert", "[{source: narratio.transcript.final_markdown, dest: transcripts/replaced.md, required: false}]", []string{"transcripts/replaced.md"}},
|
|
{"replace", "replace", "[]", []string{}},
|
|
{"empty append", "append", "[]", []string{"transcripts/base.md"}},
|
|
{"empty upsert", "upsert", "[]", []string{"transcripts/base.md"}},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
selection := strings.ReplaceAll(tc.name, " ", "_")
|
|
writePipelineFixture(t, dir, "overlays/"+selection+".yml", "config:\n sequences:\n - destination: [publish, outputs]\n key: source\n mode: "+tc.mode+"\npublish:\n outputs: "+tc.body+"\n")
|
|
cfg, err := LoadPipelineWithOptions(root, PipelineLoadOptions{Overlay: &selection})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got := make([]string, 0, len(cfg.Publish.Outputs))
|
|
for _, output := range cfg.Publish.Outputs {
|
|
got = append(got, output.Dest)
|
|
}
|
|
if !reflect.DeepEqual(got, tc.want) {
|
|
t.Fatalf("output destinations = %v, want %v", got, tc.want)
|
|
}
|
|
if tc.name == "upsert" && (cfg.Publish.Outputs[0].Required == nil || *cfg.Publish.Outputs[0].Required) {
|
|
t.Fatal("upsert did not replace the whole matching output")
|
|
}
|
|
})
|
|
}
|
|
}
|