Add normalize configuration contract
This commit is contained in:
129
internal/config/normalize_test.go
Normal file
129
internal/config/normalize_test.go
Normal file
@@ -0,0 +1,129 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNormalizeLoadAndValidate(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
normalizeYAML string
|
||||
wantLoadErr string
|
||||
wantValidateErr string
|
||||
assert func(t *testing.T, cfg *Config)
|
||||
}{
|
||||
{
|
||||
name: "normalize defaults when omitted",
|
||||
normalizeYAML: "",
|
||||
assert: func(t *testing.T, cfg *Config) {
|
||||
t.Helper()
|
||||
if cfg.Pipeline.Normalize == nil {
|
||||
t.Fatal("normalize config should be present via defaults")
|
||||
}
|
||||
if cfg.Pipeline.Normalize.OutputPath != "transcripts/normalized.json" {
|
||||
t.Fatalf("normalize.output_path = %q, want %q", cfg.Pipeline.Normalize.OutputPath, "transcripts/normalized.json")
|
||||
}
|
||||
if cfg.Pipeline.Normalize.OutputSchema != "seriatim-intermediate" {
|
||||
t.Fatalf("normalize.output_schema = %q, want %q", cfg.Pipeline.Normalize.OutputSchema, "seriatim-intermediate")
|
||||
}
|
||||
if cfg.Pipeline.Normalize.Report == nil || *cfg.Pipeline.Normalize.Report != true {
|
||||
t.Fatalf("normalize.report = %v, want true", cfg.Pipeline.Normalize.Report)
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "valid explicit normalize config",
|
||||
normalizeYAML: `normalize:
|
||||
output_path: transcripts/custom-normalized.json
|
||||
output_schema: seriatim-full
|
||||
report: false
|
||||
`,
|
||||
assert: func(t *testing.T, cfg *Config) {
|
||||
t.Helper()
|
||||
if cfg.Pipeline.Normalize == nil {
|
||||
t.Fatal("normalize config should be present")
|
||||
}
|
||||
if cfg.Pipeline.Normalize.OutputPath != "transcripts/custom-normalized.json" {
|
||||
t.Fatalf("normalize.output_path = %q, want %q", cfg.Pipeline.Normalize.OutputPath, "transcripts/custom-normalized.json")
|
||||
}
|
||||
if cfg.Pipeline.Normalize.OutputSchema != "seriatim-full" {
|
||||
t.Fatalf("normalize.output_schema = %q, want %q", cfg.Pipeline.Normalize.OutputSchema, "seriatim-full")
|
||||
}
|
||||
if cfg.Pipeline.Normalize.Report == nil || *cfg.Pipeline.Normalize.Report != false {
|
||||
t.Fatalf("normalize.report = %v, want false", cfg.Pipeline.Normalize.Report)
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "invalid normalize output schema fails",
|
||||
normalizeYAML: `normalize:
|
||||
output_path: transcripts/normalized.json
|
||||
output_schema: not-a-schema
|
||||
report: true
|
||||
`,
|
||||
wantValidateErr: "pipeline.normalize.output_schema must be one of: seriatim-minimal, seriatim-intermediate, seriatim-full",
|
||||
},
|
||||
{
|
||||
name: "empty normalize output path fails",
|
||||
normalizeYAML: `normalize:
|
||||
output_path: ""
|
||||
output_schema: seriatim-intermediate
|
||||
report: true
|
||||
`,
|
||||
wantValidateErr: "pipeline.normalize.output_path must be non-empty",
|
||||
},
|
||||
{
|
||||
name: "unknown normalize field fails strict decoding",
|
||||
normalizeYAML: `normalize:
|
||||
output_path: transcripts/normalized.json
|
||||
output_schema: seriatim-intermediate
|
||||
report: true
|
||||
bogus: true
|
||||
`,
|
||||
wantLoadErr: "strict decode failed",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
pipelineYAML := testPipelineBaseYAML
|
||||
if tt.normalizeYAML != "" {
|
||||
pipelineYAML += "\n" + tt.normalizeYAML
|
||||
}
|
||||
pipelinePath, sessionPath := writeConfigFiles(t, pipelineYAML, testSessionBaseYAML)
|
||||
|
||||
cfg, err := Load(pipelinePath, sessionPath)
|
||||
if tt.wantLoadErr != "" {
|
||||
if err == nil {
|
||||
t.Fatalf("expected load error containing %q, got nil", tt.wantLoadErr)
|
||||
}
|
||||
if !strings.Contains(err.Error(), tt.wantLoadErr) {
|
||||
t.Fatalf("load error = %q, want to contain %q", err.Error(), tt.wantLoadErr)
|
||||
}
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("Load() error = %v", err)
|
||||
}
|
||||
|
||||
if tt.assert != nil {
|
||||
tt.assert(t, cfg)
|
||||
}
|
||||
|
||||
err = Validate(cfg)
|
||||
if tt.wantValidateErr != "" {
|
||||
if err == nil {
|
||||
t.Fatalf("expected validation error containing %q, got nil", tt.wantValidateErr)
|
||||
}
|
||||
if !strings.Contains(err.Error(), tt.wantValidateErr) {
|
||||
t.Fatalf("validation error = %q, want to contain %q", err.Error(), tt.wantValidateErr)
|
||||
}
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("Validate() error = %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user