61 lines
1.8 KiB
Go
61 lines
1.8 KiB
Go
package builtin
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
|
|
"gitea.maximumdirect.net/eric/seriatim/internal/config"
|
|
"gitea.maximumdirect.net/eric/seriatim/internal/model"
|
|
)
|
|
|
|
func TestValidateOutputSucceedsAfterAssignIDs(t *testing.T) {
|
|
merged := model.MergedTranscript{
|
|
Segments: []model.Segment{
|
|
{Source: "input.json", Speaker: "Alice", Start: 1, End: 2, Text: "hello"},
|
|
{Source: "input.json", Speaker: "Alice", Start: 3, End: 4, Text: "again"},
|
|
},
|
|
}
|
|
|
|
withIDs, _, err := assignIDs{}.Process(context.Background(), merged, testConfig())
|
|
if err != nil {
|
|
t.Fatalf("assign IDs: %v", err)
|
|
}
|
|
got, events, err := validateOutput{}.Process(context.Background(), withIDs, testConfig())
|
|
if err != nil {
|
|
t.Fatalf("validate output: %v", err)
|
|
}
|
|
if len(got.Segments) != 2 {
|
|
t.Fatalf("segment count = %d, want 2", len(got.Segments))
|
|
}
|
|
if len(events) != 1 || !strings.Contains(events[0].Message, "validated 2 output segment(s)") {
|
|
t.Fatalf("events = %#v", events)
|
|
}
|
|
}
|
|
|
|
func TestValidateOutputFailsBeforeAssignIDs(t *testing.T) {
|
|
merged := model.MergedTranscript{
|
|
Segments: []model.Segment{
|
|
{Source: "input.json", Speaker: "Alice", Start: 1, End: 2, Text: "hello"},
|
|
},
|
|
}
|
|
|
|
_, _, err := validateOutput{}.Process(context.Background(), merged, testConfig())
|
|
if err == nil {
|
|
t.Fatal("expected validation error")
|
|
}
|
|
if !strings.Contains(err.Error(), "segment 0 has id 0; want 1") {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
}
|
|
|
|
func testConfig() config.Config {
|
|
return config.Config{
|
|
InputReader: config.DefaultInputReader,
|
|
InputFiles: []string{"input.json"},
|
|
PreprocessingModules: []string{"validate-raw", "normalize-speakers", "trim-text"},
|
|
PostprocessingModules: []string{"assign-ids", "validate-output"},
|
|
OutputModules: []string{"json"},
|
|
}
|
|
}
|