58 lines
1.6 KiB
Go
58 lines
1.6 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 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
|
|
}
|