testutil

package
v1.0.0-alpha.12 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2022 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))
		ref.Set(field, protoreflect.ValueOf(value))
	}
	return a
})
View Source
var TestFieldSpecs = []TestFieldSpec{
	{
		"u32",
		rapid.Uint32(),
	},
	{
		"u64",
		rapid.Uint64(),
	},
	{
		"str",
		rapid.String().Filter(func(x string) bool {

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

Functions

func MakeTestCodec

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

func TestFieldSpecsGen

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

func TestKeyCodecGen

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

Types

type TestFieldSpec

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

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