-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemory_vault_binary_test.go
52 lines (42 loc) · 1.13 KB
/
memory_vault_binary_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
52
package goblin
import (
"bytes"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestMemoryVaultBinaryMarshalling(t *testing.T) {
t.Run("marshal and unmarshal are idempotent", func(t *testing.T) {
mv := NewMemoryVault()
file1 := "test/path.txt"
file2 := "different/path.txt"
err := mv.WriteFile(
file1, bytes.NewReader([]byte{0x01}),
FileModTime(time.Unix(1, 0)),
)
require.NoError(t, err)
err = mv.WriteFile(
file2, bytes.NewReader([]byte{0x02}),
FileModTime(time.Unix(2, 0)),
)
require.NoError(t, err)
data, err := mv.MarshalBinary()
require.NoError(t, err)
mv = NewMemoryVault()
err = mv.UnmarshalBinary(data)
require.NoError(t, err)
data, err = mv.ReadFile(file1)
require.NoError(t, err)
fInfo, err := mv.Stat(file1)
require.NoError(t, err)
assert.Equal(t, time.Unix(1, 0), fInfo.ModTime())
assert.Equal(t, []byte{0x01}, data)
data, err = mv.ReadFile(file2)
require.NoError(t, err)
fInfo, err = mv.Stat(file2)
require.NoError(t, err)
assert.Equal(t, time.Unix(2, 0), fInfo.ModTime())
assert.Equal(t, []byte{0x02}, data)
})
}