Some checks failed
CodeQL / Analyze (go) (push) Successful in 6m28s
Docker Image / build-docker (push) Failing after 13m26s
Lint and Testing / lint (push) Successful in 11m17s
Lint and Testing / test (push) Successful in 11m17s
Lint and Testing / golangci (push) Successful in 2m40s
66 lines
1.7 KiB
Go
66 lines
1.7 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestVAD_Validate_disabled(t *testing.T) {
|
|
if err := (VAD{}).Validate(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestVAD_Validate_requiresModel(t *testing.T) {
|
|
err := (VAD{Enabled: true}).Validate()
|
|
if err == nil {
|
|
t.Fatal("expected error")
|
|
}
|
|
}
|
|
|
|
func TestVAD_Validate_modelExists(t *testing.T) {
|
|
dir := t.TempDir()
|
|
model := filepath.Join(dir, "ggml-silero.bin")
|
|
if err := os.WriteFile(model, []byte("x"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
v := VAD{Enabled: true, Model: model, Threshold: 0.5}
|
|
if err := v.Validate(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestVAD_ResolveModelPath(t *testing.T) {
|
|
v := VAD{Model: "ggml-silero-v6.2.0.bin"}
|
|
got := v.ResolveModelPath("/data/models")
|
|
want := filepath.Join("/data/models", "ggml-silero-v6.2.0.bin")
|
|
if got != want {
|
|
t.Fatalf("got %q want %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestVAD_ResolveModelPath_vadSubdir(t *testing.T) {
|
|
dir := t.TempDir()
|
|
vadDir := filepath.Join(dir, "vad")
|
|
if err := os.MkdirAll(vadDir, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(vadDir, "vad.bin"), []byte("x"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
v := VAD{Model: "vad.bin"}
|
|
got := v.ResolveModelPath(dir)
|
|
want := filepath.Join(dir, "vad", "vad.bin")
|
|
if got != want {
|
|
t.Fatalf("got %q want %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestVAD_WithDefaults(t *testing.T) {
|
|
v := VAD{Enabled: true}.WithDefaults()
|
|
if v.Threshold != 0.5 || v.MinSpeechMs != 250 || v.MinSilenceMs != 100 {
|
|
t.Fatalf("unexpected defaults: %+v", v)
|
|
}
|
|
}
|