2026-08-10 21:32:15 +00:00
package config
import (
"os"
"path/filepath"
"strings"
"testing"
)
func TestLoadersRejectTrailingYAMLDocuments ( t * testing . T ) {
dir := t . TempDir ( )
pipelinePath := filepath . Join ( dir , "pipeline.yml" )
campaignPath := filepath . Join ( dir , "campaign.yml" )
if err := os . WriteFile ( pipelinePath , [ ] byte ( "workspace:\n root: /tmp/narratio\n---\nworkspace:\n root: /other\n" ) , 0 o644 ) ; err != nil {
t . Fatalf ( "write pipeline.yml: %v" , err )
}
if err := os . WriteFile ( campaignPath , [ ] byte ( "campaign_id: sample-campaign\n---\nnull\n" ) , 0 o644 ) ; err != nil {
t . Fatalf ( "write campaign.yml: %v" , err )
}
tests := [ ] struct {
name string
load func ( ) error
} {
{
name : "pipeline" ,
load : func ( ) error {
_ , err := LoadPipeline ( pipelinePath )
return err
} ,
} ,
{
name : "campaign" ,
load : func ( ) error {
_ , err := LoadCampaign ( campaignPath )
return err
} ,
} ,
{
name : "remote session bytes" ,
load : func ( ) error {
_ , err := LoadSessionBytesWithOptions ( "s3://bucket/session.yml" , [ ] byte ( "session_id: 2026-05-03\n---\n# another document\nnull\n" ) , SessionLoadOptions { } )
return err
} ,
} ,
}
for _ , tt := range tests {
t . Run ( tt . name , func ( t * testing . T ) {
err := tt . load ( )
2026-11-20 15:22:57 +00:00
if err == nil || ( ! strings . Contains ( configurationErrorText ( err ) , "exactly one YAML document" ) && ! strings . Contains ( configurationErrorText ( err ) , "yaml.multiple_documents" ) ) {
2026-08-10 21:32:15 +00:00
t . Fatalf ( "load error = %v, want exactly-one-document error" , err )
}
} )
}
}