package transcode import ( "os" "path/filepath" "runtime" "testing" ) func TestSniffOggCodec_opus(t *testing.T) { path := pionTinyOggPath(t) if got := sniffOggCodec(path); got != "opus" { t.Fatalf("sniffOggCodec() = %q want opus", got) } } func TestDecodeOggOpus_pionTiny(t *testing.T) { path := pionTinyOggPath(t) streamer, format, closer, err := decodeOggOpus(path) if err != nil { t.Fatal(err) } defer closer.Close() if format.SampleRate == 0 { t.Fatal("zero sample rate") } buf := make([][2]float64, 4096) n, ok := streamer.Stream(buf) if !ok || n == 0 { t.Fatal("expected pcm samples") } } func pionTinyOggPath(t *testing.T) string { t.Helper() _, file, _, ok := runtime.Caller(0) if !ok { t.Fatal("runtime.Caller failed") } modRoot := filepath.Clean(filepath.Join(filepath.Dir(file), "..")) cache := os.Getenv("GOMODCACHE") if cache == "" { home, _ := os.UserHomeDir() cache = filepath.Join(home, "go", "pkg", "mod") } path := filepath.Join(cache, "github.com/pion/opus@v0.0.0-20260601214817-71d58474cec8/testdata/tiny.ogg") if _, err := os.Stat(path); err != nil { _ = modRoot t.Skipf("pion testdata not in module cache: %v", err) } return path }