make the test more clear

This commit is contained in:
zutto 2022-04-17 13:38:45 +03:00
parent 094afdb15a
commit fde64662ce

View file

@ -2,14 +2,13 @@ package headers
import ( import (
"crypto/rand" "crypto/rand"
"fmt"
"reflect" "reflect"
"testing" "testing"
) )
func TestHeaders_Generate(t *testing.T) { func TestHeaders_Generate(t *testing.T) {
h := Headers{ initialHeaders := Headers{
HeaderString: []byte(HeaderString), HeaderString: []byte(HeaderString),
PageSize: uint64(256 ^ 2), PageSize: uint64(256 ^ 2),
DBVersion: uint16(1), DBVersion: uint16(1),
@ -18,17 +17,17 @@ func TestHeaders_Generate(t *testing.T) {
Commit: make([]byte, CommitDataLength), Commit: make([]byte, CommitDataLength),
} }
_, err := rand.Read(h.Commit[:CommitDataLength]) _, err := rand.Read(initialHeaders.Commit[:CommitDataLength])
if err != nil { if err != nil {
t.Error("Failed to generate random string") t.Error("Failed to generate random string")
} }
output := h.Generate() output := initialHeaders.Generate()
fmt.Printf("%c", output)
h2 := Headers{}
h2.Parse(output, 0)
if !reflect.DeepEqual(h, h2) { parsedHeaders := Headers{}
t.Error("deepequal failed") parsedHeaders.Parse(output, 0)
if !reflect.DeepEqual(initialHeaders, parsedHeaders) {
t.Error("deepequal failed, headers are not identical.")
} }
} }