ea2bcde74b
extract.go replaces the bash script with idiomatic Go: - akaiutil process communication via stdin/stdout pipes - partition enumeration (df output parsing) - volume enumeration (dir output parsing per partition) - sample2wavall per volume with WAV count aggregation runAkaiutil is a package-level var — tests stub it with canned output to verify parsing without a real akaiutil binary or ISO. Removed: findScript(), -tool flag on extract, os/exec from main.go Kept: extract_wavs.sh as a standalone utility (no longer called)
118 lines
2.7 KiB
Go
118 lines
2.7 KiB
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestListPartitions(t *testing.T) {
|
|
orig := runAkaiutil
|
|
defer func() { runAkaiutil = orig }()
|
|
|
|
runAkaiutil = func(isoPath, commands string) (string, error) {
|
|
if commands != "df\nq\n" {
|
|
t.Fatalf("unexpected commands: %q", commands)
|
|
}
|
|
return `
|
|
Disk /disk0
|
|
Total blocks: 12288 (8 KB each) 98304 KB
|
|
Partition table:
|
|
A - S1000 HD (3840 blocks)
|
|
B - S1000 HD (5120 blocks)
|
|
C - S1000 HD (3328 blocks)
|
|
`, nil
|
|
}
|
|
|
|
parts, err := listPartitions("/fake/disk.iso")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(parts) != 3 {
|
|
t.Fatalf("expected 3 partitions, got %d: %v", len(parts), parts)
|
|
}
|
|
if parts[0] != "A" || parts[1] != "B" || parts[2] != "C" {
|
|
t.Fatalf("unexpected partitions: %v", parts)
|
|
}
|
|
}
|
|
|
|
func TestListPartitionsEmpty(t *testing.T) {
|
|
orig := runAkaiutil
|
|
defer func() { runAkaiutil = orig }()
|
|
|
|
runAkaiutil = func(isoPath, commands string) (string, error) {
|
|
return "No partitions found\n", nil
|
|
}
|
|
|
|
parts, err := listPartitions("/fake/disk.iso")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(parts) != 1 || parts[0] != "A" {
|
|
t.Fatalf("expected fallback to [A], got %v", parts)
|
|
}
|
|
}
|
|
|
|
func TestListVolumes(t *testing.T) {
|
|
orig := runAkaiutil
|
|
defer func() { runAkaiutil = orig }()
|
|
|
|
runAkaiutil = func(isoPath, commands string) (string, error) {
|
|
return `
|
|
/disk0/A > cd /disk0/A
|
|
/disk0/A > dir
|
|
1 DRUM KIT 1 - VOLUME (10 files)
|
|
2 BASS SAMPLES - VOLUME (5 files)
|
|
/disk0/A > cd /disk0/B
|
|
/disk0/B > dir
|
|
3 SYNTH PADS - VOLUME (20 files)
|
|
/disk0/B >
|
|
`, nil
|
|
}
|
|
|
|
vols, err := listVolumes("/fake/disk.iso", []string{"A", "B"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(vols) != 3 {
|
|
t.Fatalf("expected 3 volumes, got %d: %v", len(vols), vols)
|
|
}
|
|
if vols[0].Part != "A" || vols[0].Name != "DRUM KIT 1" {
|
|
t.Fatalf("unexpected vol 0: %+v", vols[0])
|
|
}
|
|
if vols[1].Part != "A" || vols[1].Name != "BASS SAMPLES" {
|
|
t.Fatalf("unexpected vol 1: %+v", vols[1])
|
|
}
|
|
if vols[2].Part != "B" || vols[2].Name != "SYNTH PADS" {
|
|
t.Fatalf("unexpected vol 2: %+v", vols[2])
|
|
}
|
|
}
|
|
|
|
func TestRunExtractionCount(t *testing.T) {
|
|
orig := runAkaiutil
|
|
defer func() { runAkaiutil = orig }()
|
|
|
|
calls := 0
|
|
runAkaiutil = func(isoPath, commands string) (string, error) {
|
|
calls++
|
|
return `
|
|
exported 10 file(s)
|
|
exported 5 file(s)
|
|
exported 0 file(s)
|
|
`, nil
|
|
}
|
|
|
|
vols := []volInfo{
|
|
{Part: "A", Name: "DRUMS"},
|
|
{Part: "A", Name: "BASS"},
|
|
}
|
|
total, err := runExtraction("/fake/disk.iso", "/tmp/out", vols)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if total != 15 {
|
|
t.Fatalf("expected 15 total WAVs, got %d", total)
|
|
}
|
|
if calls != 1 {
|
|
t.Fatalf("expected 1 akaiutil call, got %d", calls)
|
|
}
|
|
}
|