-
Notifications
You must be signed in to change notification settings - Fork 22
/
meta_test.go
43 lines (35 loc) · 1.01 KB
/
meta_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
package LibraDB
import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"os"
"testing"
)
func TestMetaSerialize(t *testing.T) {
meta := newEmptyMeta()
meta.root = 3
meta.freelistPage = 4
actual := make([]byte, testPageSize, testPageSize)
meta.serialize(actual)
expected, err := os.ReadFile(getExpectedResultFileName(t.Name()))
require.NoError(t, err)
assert.Equal(t, expected, actual)
}
func TestCreateDalIncorrectMagicNumber(t *testing.T) {
actualMetaBytes, err := os.ReadFile(getExpectedResultFileName(t.Name()))
require.NoError(t, err)
actualMeta := newEmptyMeta()
assert.Panics(t, func() {
actualMeta.deserialize(actualMetaBytes)
})
}
func TestMetaDeserialize(t *testing.T) {
actualMetaBytes, err := os.ReadFile(getExpectedResultFileName(t.Name()))
actualMeta := newEmptyMeta()
actualMeta.deserialize(actualMetaBytes)
require.NoError(t, err)
expectedMeta := newEmptyMeta()
expectedMeta.root = 3
expectedMeta.freelistPage = 4
assert.Equal(t, expectedMeta, actualMeta)
}