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