Test exclusive tone-test output creation

This commit is contained in:
Brandon McGinty (chatgpt)
2026-08-10 11:25:52 -04:00
committed by Brandon McGinty
parent e9ba7f580a
commit fab4fd50d2
+18
View File
@@ -1,6 +1,7 @@
package main
import (
"os"
"path/filepath"
"testing"
)
@@ -25,6 +26,23 @@ func TestNewAudioFileSaverReportsUnavailableOutputPath(t *testing.T) {
}
}
func TestNewAudioFileSaverDoesNotOverwriteExistingOutput(t *testing.T) {
path := filepath.Join(t.TempDir(), "tone.pcm")
if err := os.WriteFile(path, []byte("existing"), 0600); err != nil {
t.Fatal(err)
}
if saver, err := NewAudioFileSaver(path); err == nil || saver != nil {
t.Fatalf("got saver=%v err=%v", saver, err)
}
contents, err := os.ReadFile(path)
if err != nil {
t.Fatal(err)
}
if string(contents) != "existing" {
t.Fatalf("output was overwritten: %q", contents)
}
}
type testDetacher struct{ detached bool }
func (d *testDetacher) Detach() { d.detached = true }