2022-04-16 20:10:49 +00:00
|
|
|
package headers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/rand"
|
2022-04-16 22:33:34 +00:00
|
|
|
"fmt"
|
2022-04-16 20:10:49 +00:00
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestHeaders_Generate(t *testing.T) {
|
|
|
|
|
|
|
|
h := Headers{
|
|
|
|
HeaderString: []byte(HeaderString),
|
|
|
|
PageSize: uint64(256 ^ 2),
|
|
|
|
DBVersion: uint16(1),
|
|
|
|
|
|
|
|
WAL: true,
|
|
|
|
Commit: make([]byte, CommitDataLength),
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := rand.Read(h.Commit[:CommitDataLength])
|
|
|
|
if err != nil {
|
|
|
|
t.Error("Failed to generate random string")
|
|
|
|
}
|
|
|
|
|
|
|
|
output := h.Generate()
|
2022-04-16 22:33:34 +00:00
|
|
|
fmt.Printf("%c", output)
|
2022-04-16 20:10:49 +00:00
|
|
|
h2 := Headers{}
|
|
|
|
h2.Parse(output, 0)
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(h, h2) {
|
|
|
|
t.Error("deepequal failed")
|
|
|
|
}
|
|
|
|
}
|