-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathriff_test.go
51 lines (46 loc) · 912 Bytes
/
riff_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package riff
import (
"fmt"
"os"
"path/filepath"
"testing"
"time"
)
func TestDuration(t *testing.T) {
expectations := []struct {
input string
dur time.Duration
}{
{"fixtures/sample.wav", time.Duration(612176870)},
}
for _, exp := range expectations {
path, _ := filepath.Abs(exp.input)
f, err := os.Open(path)
if err != nil {
t.Fatal(err)
}
defer f.Close()
d, err := Duration(f)
if err != nil {
t.Fatal(err)
}
if d != exp.dur {
t.Fatalf("%s of %s didn't match %f, got %f", "Duration", exp.input, exp.dur.Seconds(), d.Seconds())
}
}
}
func ExampleDuration() {
path, _ := filepath.Abs("fixtures/sample.wav")
f, err := os.Open(path)
if err != nil {
panic(err)
}
defer f.Close()
d, err := Duration(f)
if err != nil {
panic(err)
}
fmt.Printf("File with a duration of %f seconds", d.Seconds())
// Output:
// File with a duration of 0.612177 seconds
}