codectest

package
v1.11.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2024 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package codectest provides a test suite for testing codec implementations.

Index

Constants

This section is empty.

Variables

View Source
var (
	Tests = []NamedTest{
		{"Struct", TestStruct},
		{"Register Struct Twice", TestRegisterStructTwice},
		{"UInt32", TestUInt32},
		{"UIntPtr", TestUIntPtr},
		{"Slice", TestSlice},
		{"Max-Size Slice", TestMaxSizeSlice},
		{"Bool", TestBool},
		{"Array", TestArray},
		{"Big Array", TestBigArray},
		{"Pointer To Struct", TestPointerToStruct},
		{"Slice Of Struct", TestSliceOfStruct},
		{"Interface", TestInterface},
		{"Slice Of Interface", TestSliceOfInterface},
		{"Array Of Interface", TestArrayOfInterface},
		{"Pointer To Interface", TestPointerToInterface},
		{"String", TestString},
		{"Nil Slice", TestNilSlice},
		{"Serialize Unexported Field", TestSerializeUnexportedField},
		{"Serialize Of NoSerialize Field", TestSerializeOfNoSerializeField},
		{"Nil Slice Serialization", TestNilSliceSerialization},
		{"Empty Slice Serialization", TestEmptySliceSerialization},
		{"Slice With Empty Serialization", TestSliceWithEmptySerialization},
		{"Slice With Empty Serialization Error", TestSliceWithEmptySerializationError},
		{"Map With Empty Serialization", TestMapWithEmptySerialization},
		{"Map With Empty Serialization Error", TestMapWithEmptySerializationError},
		{"Slice Too Large", TestSliceTooLarge},
		{"Negative Numbers", TestNegativeNumbers},
		{"Too Large Unmarshal", TestTooLargeUnmarshal},
		{"Unmarshal Invalid Interface", TestUnmarshalInvalidInterface},
		{"Extra Space", TestExtraSpace},
		{"Slice Length Overflow", TestSliceLengthOverflow},
		{"Map", TestMap},
		{"Can Marshal Large Slices", TestCanMarshalLargeSlices},
	}

	MultipleTagsTests = []NamedTest{
		{"Multiple Tags", TestMultipleTags},
	}
)

Functions

func FuzzStructUnmarshal

func FuzzStructUnmarshal(codec codecpkg.GeneralCodec, f *testing.F)

func RunAll

func RunAll(t *testing.T, ctor func() codecpkg.GeneralCodec)

RunAll runs all Tests, constructing a new GeneralCodec for each.

func RunAllMultipleTags

func RunAllMultipleTags(t *testing.T, ctor func() codecpkg.GeneralCodec)

RunAll runs all MultipleTagsTests, constructing a new GeneralCodec for each.

func TestArray

func TestArray(t testing.TB, codec codecpkg.GeneralCodec)

Test marshalling an array

func TestArrayOfInterface

func TestArrayOfInterface(t testing.TB, codec codecpkg.GeneralCodec)

Test marshalling an array of interfaces

func TestBigArray

func TestBigArray(t testing.TB, codec codecpkg.GeneralCodec)

Test marshalling a really big array

func TestBool

func TestBool(t testing.TB, codec codecpkg.GeneralCodec)

Test marshalling a bool

func TestCanMarshalLargeSlices

func TestCanMarshalLargeSlices(t testing.TB, codec codecpkg.GeneralCodec)

func TestEmptySliceSerialization

func TestEmptySliceSerialization(t testing.TB, codec codecpkg.GeneralCodec)

Test marshaling a slice that has 0 elements (but isn't nil)

func TestExtraSpace

func TestExtraSpace(t testing.TB, codec codecpkg.GeneralCodec)

Test unmarshaling something with extra data

func TestInterface

func TestInterface(t testing.TB, codec codecpkg.GeneralCodec)

Test marshalling an interface

func TestMap

func TestMap(t testing.TB, codec codecpkg.GeneralCodec)

func TestMapWithEmptySerialization

func TestMapWithEmptySerialization(t testing.TB, codec codecpkg.GeneralCodec)

Test marshaling empty map of zero length structs

func TestMapWithEmptySerializationError

func TestMapWithEmptySerializationError(t testing.TB, codec codecpkg.GeneralCodec)

func TestMaxSizeSlice

func TestMaxSizeSlice(t testing.TB, codec codecpkg.GeneralCodec)

Test marshalling/unmarshalling largest possible slice

func TestMultipleTags

func TestMultipleTags(t testing.TB, codec codecpkg.GeneralCodec)

func TestNegativeNumbers

func TestNegativeNumbers(t testing.TB, codec codecpkg.GeneralCodec)

Ensure serializing structs with negative number members works

func TestNilSlice

func TestNilSlice(t testing.TB, codec codecpkg.GeneralCodec)

Ensure a nil slice is unmarshaled to slice with length 0

func TestNilSliceSerialization

func TestNilSliceSerialization(t testing.TB, codec codecpkg.GeneralCodec)

Test marshalling of nil slice

func TestPointerToInterface

func TestPointerToInterface(t testing.TB, codec codecpkg.GeneralCodec)

Test marshalling a pointer to an interface

func TestPointerToStruct

func TestPointerToStruct(t testing.TB, codec codecpkg.GeneralCodec)

Test marshalling a pointer to a struct

func TestRegisterStructTwice

func TestRegisterStructTwice(t testing.TB, codec codecpkg.GeneralCodec)

func TestSerializeOfNoSerializeField

func TestSerializeOfNoSerializeField(t testing.TB, codec codecpkg.GeneralCodec)

func TestSerializeUnexportedField

func TestSerializeUnexportedField(t testing.TB, codec codecpkg.GeneralCodec)

Ensure that trying to serialize a struct with an unexported member that has `serialize:"true"` returns error

func TestSlice

func TestSlice(t testing.TB, codec codecpkg.GeneralCodec)

func TestSliceLengthOverflow

func TestSliceLengthOverflow(t testing.TB, codec codecpkg.GeneralCodec)

Ensure deserializing slices whose lengths exceed MaxInt32 error correctly

func TestSliceOfInterface

func TestSliceOfInterface(t testing.TB, codec codecpkg.GeneralCodec)

Test marshalling a slice of interfaces

func TestSliceOfStruct

func TestSliceOfStruct(t testing.TB, codec codecpkg.GeneralCodec)

Test marshalling a slice of structs

func TestSliceTooLarge

func TestSliceTooLarge(t testing.TB, codec codecpkg.GeneralCodec)

func TestSliceWithEmptySerialization

func TestSliceWithEmptySerialization(t testing.TB, codec codecpkg.GeneralCodec)

Test marshaling empty slice of zero length structs

func TestSliceWithEmptySerializationError

func TestSliceWithEmptySerializationError(t testing.TB, codec codecpkg.GeneralCodec)

func TestString

func TestString(t testing.TB, codec codecpkg.GeneralCodec)

Test marshalling a string

func TestStruct

func TestStruct(t testing.TB, codec codecpkg.GeneralCodec)

Test marshaling/unmarshaling a complicated struct

func TestTooLargeUnmarshal

func TestTooLargeUnmarshal(t testing.TB, codec codecpkg.GeneralCodec)

Ensure deserializing structs with too many bytes errors correctly

func TestUInt32

func TestUInt32(t testing.TB, codec codecpkg.GeneralCodec)

func TestUIntPtr

func TestUIntPtr(t testing.TB, codec codecpkg.GeneralCodec)

func TestUnmarshalInvalidInterface

func TestUnmarshalInvalidInterface(t testing.TB, codec codecpkg.GeneralCodec)

Ensure deserializing structs into the wrong interface errors gracefully

Types

type Foo

type Foo interface {
	Foo() int
}

type MultipleVersionsStruct

type MultipleVersionsStruct struct {
	BothTags    string `tag1:"true"  tag2:"true"`
	SingleTag1  string `tag1:"true"`
	SingleTag2  string `             tag2:"true"`
	EitherTags1 string `tag1:"false" tag2:"true"`
	EitherTags2 string `tag1:"true"  tag2:"false"`
	NoTags      string `tag1:"false" tag2:"false"`
}

type MyInnerStruct

type MyInnerStruct struct {
	Str string `serialize:"true"`
}

func (*MyInnerStruct) Foo

func (*MyInnerStruct) Foo() int

type MyInnerStruct2

type MyInnerStruct2 struct {
	Bool bool `serialize:"true"`
}

func (*MyInnerStruct2) Foo

func (*MyInnerStruct2) Foo() int

type MyInnerStruct3

type MyInnerStruct3 struct {
	Str string        `serialize:"true"`
	M1  MyInnerStruct `serialize:"true"`
	F   Foo           `serialize:"true"`
}

MyInnerStruct3 embeds Foo, an interface, so it has to implement TypeID and ConcreteInstance

type NamedTest

type NamedTest struct {
	Name string
	Test func(testing.TB, codecpkg.GeneralCodec)
}

A NamedTest couples a test in the suite with a human-readable name.

func (*NamedTest) Run

func (tt *NamedTest) Run(t *testing.T, c codecpkg.GeneralCodec)

Run runs the test on the GeneralCodec.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL