-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathefile_test.go
48 lines (40 loc) · 1017 Bytes
/
efile_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
package extremofile
import (
"math/rand"
"testing"
"testing/quick"
"time"
"github.com/stretchr/testify/assert"
)
func TestParseChecksum(t *testing.T) {
t.Parallel()
f := func(data []byte) bool {
b := append(data, checksum(data)...)
back, err := parse(b)
return assert.NoError(t, err) && assert.Equal(t, data, back)
}
assert.NoError(t, quick.Check(f, nil))
}
func TestParseShort(t *testing.T) {
t.Parallel()
f := func(b []byte) bool {
if len(b) >= checkSize {
b = b[:checkSize-1]
}
back, err := parse(b)
return assert.Nil(t, back) && assert.Equal(t, errMetaParse, err)
}
assert.NoError(t, quick.Check(f, nil))
}
func TestParseCorrupt(t *testing.T) {
t.Parallel()
rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
f := func(data []byte) bool {
b := append(data, checksum(data)...)
offset := rnd.Uint32() % uint32(len(b))
b[offset]++
back, err := parse(b)
return assert.Nil(t, back) && assert.Equal(t, errCorrupt, err)
}
assert.NoError(t, quick.Check(f, nil))
}