Test exclusive tone-test output creation
This commit is contained in:
committed by
Brandon McGinty
parent
e9ba7f580a
commit
fab4fd50d2
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"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 }
|
type testDetacher struct{ detached bool }
|
||||||
|
|
||||||
func (d *testDetacher) Detach() { d.detached = true }
|
func (d *testDetacher) Detach() { d.detached = true }
|
||||||
|
|||||||
Reference in New Issue
Block a user