Skip to main content

structs_test.go

structs_test.go - Overview

This file contains tests for the header struct within the badger package, focusing on encoding and structure size.

Detailed Documentation

TestLargeEncode

Purpose: Regression test to ensure that encoding a header with maximum values does not panic. This test addresses issue github.com/hypermodeinc/badger/pull/1800.

Parameters:

  • t: *testing.T - Testing object provided by the testing package.

Returns: None

func TestLargeEncode(t *testing.T) {
var headerEnc [maxHeaderSize]byte
h := header{math.MaxUint32, math.MaxUint32, math.MaxUint64, math.MaxUint8, math.MaxUint8}
require.NotPanics(t, func() { _ = h.Encode(headerEnc[:]) })
}

TestNumFieldsHeader

Purpose: Tests that the maxHeaderSize constant is consistent with the number of fields in the header struct. Ensures that any changes to the header struct are reflected in the size calculation.

Parameters:

  • t: *testing.T - Testing object provided by the testing package.

Returns: None

func TestNumFieldsHeader(t *testing.T) {
// maxHeaderSize must correspond with any changes made to header
require.Equal(t, 5, reflect.TypeOf(header{}).NumField())
}