testutil

package
v0.0.0-...-095f669 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GenA = rapid.Custom(func(t *rapid.T) *testpb.ExampleTable {
	a := &testpb.ExampleTable{}
	ref := a.ProtoReflect()
	for _, spec := range TestFieldSpecs {
		field := GetTestField(spec.FieldName)
		value := spec.Gen.Draw(t, string(spec.FieldName))
		if value != nil {
			ref.Set(field, protoreflect.ValueOf(value))
		}
	}
	return a
})
View Source
var TestFieldSpecs = []TestFieldSpec{
	{
		"u32",
		rapid.Uint32().AsAny(),
	},
	{
		"u64",
		rapid.Uint64().AsAny(),
	},
	{
		"str",
		rapid.String().Filter(func(x string) bool {

			return strings.IndexByte(x, 0) < 0
		}).AsAny(),
	},
	{
		"bz",
		rapid.SliceOfN(rapid.Byte(), 0, math.MaxUint32).AsAny(),
	},
	{
		"i32",
		rapid.Int32().AsAny(),
	},
	{
		"f32",
		rapid.Uint32().AsAny(),
	},
	{
		"s32",
		rapid.Int32().AsAny(),
	},
	{
		"sf32",
		rapid.Int32().AsAny(),
	},
	{
		"i64",
		rapid.Int64().AsAny(),
	},
	{
		"f64",
		rapid.Uint64().AsAny(),
	},
	{
		"s64",
		rapid.Int64().AsAny(),
	},
	{
		"sf64",
		rapid.Int64().AsAny(),
	},
	{
		"b",
		rapid.Bool().AsAny(),
	},
	{
		"ts",
		rapid.Custom(func(t *rapid.T) protoreflect.Message {
			isNil := rapid.Float32().Draw(t, "isNil")
			if isNil >= 0.95 {
				return nil
			}
			seconds := rapid.Int64Range(-9999999999, 9999999999).Draw(t, "seconds")
			nanos := rapid.Int32Range(0, 999999999).Draw(t, "nanos")
			return (&timestamppb.Timestamp{
				Seconds: seconds,
				Nanos:   nanos,
			}).ProtoReflect()
		}).AsAny(),
	},
	{
		"dur",
		rapid.Custom(func(t *rapid.T) protoreflect.Message {
			seconds := rapid.Int64Range(0, 315576000000).Draw(t, "seconds")
			nanos := rapid.Int32Range(0, 999999999).Draw(t, "nanos")
			return (&durationpb.Duration{
				Seconds: seconds,
				Nanos:   nanos,
			}).ProtoReflect()
		}).AsAny(),
	},
	{
		"e",
		rapid.Map(rapid.Int32(), func(x int32) protoreflect.EnumNumber {
			return protoreflect.EnumNumber(x)
		}).AsAny(),
	},
}

Functions

func MakeTestCodec

func MakeTestCodec(fname protoreflect.Name, nonTerminal bool) (ormfield.Codec, error)

func TestFieldSpecsGen

func TestFieldSpecsGen(minLen, maxLen int) *rapid.Generator[[]TestFieldSpec]

func TestKeyCodecGen

func TestKeyCodecGen(minLen, maxLen int) *rapid.Generator[TestKeyCodec]

Types

type TestFieldSpec

type TestFieldSpec struct {
	FieldName protoreflect.Name
	Gen       *rapid.Generator[any]
}

TestFieldSpec defines a test field against the testpb.ExampleTable message.

type TestKeyCodec

type TestKeyCodec struct {
	KeySpecs []TestFieldSpec
	Codec    *ormkv.KeyCodec
}

func (TestKeyCodec) Draw

func (k TestKeyCodec) Draw(t *rapid.T, id string) []protoreflect.Value

Jump to

Keyboard shortcuts

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