-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathinfodumper_test.go
More file actions
46 lines (40 loc) · 980 Bytes
/
infodumper_test.go
File metadata and controls
46 lines (40 loc) · 980 Bytes
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
package mp4_test
import (
"bytes"
"fmt"
"os"
"strings"
"testing"
"github.com/Eyevinn/mp4ff/mp4"
"github.com/go-test/deep"
)
// compareOrUpdateInfo - compare box with golden dump or update it with -update flag set
func compareOrUpdateInfo(t *testing.T, b mp4.Informer, path string) error {
t.Helper()
var dumpBuf bytes.Buffer
err := b.Info(&dumpBuf, "all:1", "", " ")
if err != nil {
t.Error(err)
}
if *update { // Generate golden dump file
err = writeGolden(t, path, dumpBuf.Bytes())
if err != nil {
t.Error(err)
}
return nil
}
// Compare with golden dump file
golden, err := os.ReadFile(path)
if err != nil {
t.Error(err)
}
if strings.HasSuffix(path, ".txt") {
// Replace \r\n with \n to handle accidental Windows line endings
golden = bytes.ReplaceAll(golden, []byte{13, 10}, []byte{10})
}
diff := deep.Equal(golden, dumpBuf.Bytes())
if diff != nil {
return fmt.Errorf("Generated dump different from %s", path)
}
return nil
}