138 lines
4.0 KiB
Go
138 lines
4.0 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestOmittingNormalizeSpeakersDoesNotRequireSpeakers(t *testing.T) {
|
|
dir := t.TempDir()
|
|
input := writeTempFile(t, dir, "input.json")
|
|
output := filepath.Join(dir, "merged.json")
|
|
|
|
_, err := NewMergeConfig(MergeOptions{
|
|
InputFiles: []string{input},
|
|
OutputFile: output,
|
|
InputReader: DefaultInputReader,
|
|
OutputModules: DefaultOutputModules,
|
|
PreprocessingModules: "validate-raw",
|
|
PostprocessingModules: DefaultPostprocessingModules,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("expected speakers file to be optional when normalize-speakers is omitted, got %v", err)
|
|
}
|
|
}
|
|
|
|
func TestDuplicateInputFilesFailValidation(t *testing.T) {
|
|
dir := t.TempDir()
|
|
input := writeTempFile(t, dir, "input.json")
|
|
output := filepath.Join(dir, "merged.json")
|
|
|
|
_, err := NewMergeConfig(MergeOptions{
|
|
InputFiles: []string{input, input},
|
|
OutputFile: output,
|
|
InputReader: DefaultInputReader,
|
|
OutputModules: DefaultOutputModules,
|
|
PreprocessingModules: DefaultPreprocessingModules,
|
|
PostprocessingModules: DefaultPostprocessingModules,
|
|
})
|
|
if err == nil {
|
|
t.Fatal("expected duplicate input error")
|
|
}
|
|
if !strings.Contains(err.Error(), "duplicate --input-file") {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestOverlapWordRunGapDefaultsTo075(t *testing.T) {
|
|
t.Setenv(OverlapWordRunGapEnv, "")
|
|
dir := t.TempDir()
|
|
input := writeTempFile(t, dir, "input.json")
|
|
output := filepath.Join(dir, "merged.json")
|
|
|
|
cfg, err := NewMergeConfig(MergeOptions{
|
|
InputFiles: []string{input},
|
|
OutputFile: output,
|
|
InputReader: DefaultInputReader,
|
|
OutputModules: DefaultOutputModules,
|
|
PreprocessingModules: DefaultPreprocessingModules,
|
|
PostprocessingModules: DefaultPostprocessingModules,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("config failed: %v", err)
|
|
}
|
|
if cfg.OverlapWordRunGap != DefaultOverlapWordRunGap {
|
|
t.Fatalf("gap = %f, want %f", cfg.OverlapWordRunGap, DefaultOverlapWordRunGap)
|
|
}
|
|
}
|
|
|
|
func TestOverlapWordRunGapUsesValidEnvOverride(t *testing.T) {
|
|
t.Setenv(OverlapWordRunGapEnv, "1.25")
|
|
dir := t.TempDir()
|
|
input := writeTempFile(t, dir, "input.json")
|
|
output := filepath.Join(dir, "merged.json")
|
|
|
|
cfg, err := NewMergeConfig(MergeOptions{
|
|
InputFiles: []string{input},
|
|
OutputFile: output,
|
|
InputReader: DefaultInputReader,
|
|
OutputModules: DefaultOutputModules,
|
|
PreprocessingModules: DefaultPreprocessingModules,
|
|
PostprocessingModules: DefaultPostprocessingModules,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("config failed: %v", err)
|
|
}
|
|
if cfg.OverlapWordRunGap != 1.25 {
|
|
t.Fatalf("gap = %f, want 1.25", cfg.OverlapWordRunGap)
|
|
}
|
|
}
|
|
|
|
func TestOverlapWordRunGapRejectsInvalidEnvOverride(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
value string
|
|
want string
|
|
}{
|
|
{name: "non-numeric", value: "fast", want: "must be a positive number"},
|
|
{name: "zero", value: "0", want: "must be positive"},
|
|
{name: "negative", value: "-0.1", want: "must be positive"},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
t.Setenv(OverlapWordRunGapEnv, test.value)
|
|
dir := t.TempDir()
|
|
input := writeTempFile(t, dir, "input.json")
|
|
output := filepath.Join(dir, "merged.json")
|
|
|
|
_, err := NewMergeConfig(MergeOptions{
|
|
InputFiles: []string{input},
|
|
OutputFile: output,
|
|
InputReader: DefaultInputReader,
|
|
OutputModules: DefaultOutputModules,
|
|
PreprocessingModules: DefaultPreprocessingModules,
|
|
PostprocessingModules: DefaultPostprocessingModules,
|
|
})
|
|
if err == nil {
|
|
t.Fatal("expected error")
|
|
}
|
|
if !strings.Contains(err.Error(), test.want) {
|
|
t.Fatalf("expected error to contain %q, got %v", test.want, err)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func writeTempFile(t *testing.T, dir string, name string) string {
|
|
t.Helper()
|
|
|
|
path := filepath.Join(dir, name)
|
|
if err := os.WriteFile(path, []byte("{}\n"), 0o600); err != nil {
|
|
t.Fatalf("write temp file: %v", err)
|
|
}
|
|
return path
|
|
}
|