Documentation
¶
Index ¶
- Variables
- func Bool(fd protoreflect.FieldDescriptor, opts GenOptions) bool
- func Bytes(fd protoreflect.FieldDescriptor, opts GenOptions) []byte
- func Enum(fd protoreflect.FieldDescriptor, opts GenOptions) protoreflect.EnumNumber
- func FieldValue(fd protoreflect.FieldDescriptor, opts GenOptions) *protoreflect.Value
- func Fixed32(fd protoreflect.FieldDescriptor, opts GenOptions) uint32
- func Fixed64(fd protoreflect.FieldDescriptor, opts GenOptions) uint64
- func Float32(fd protoreflect.FieldDescriptor, opts GenOptions) float32
- func Float64(fd protoreflect.FieldDescriptor, opts GenOptions) float64
- func GoogleDuration(fd protoreflect.FieldDescriptor, opts GenOptions) *durationpb.Duration
- func GoogleFieldMask(fd protoreflect.FieldDescriptor, opts GenOptions) *fieldmaskpb.FieldMask
- func GoogleTimestamp(fd protoreflect.FieldDescriptor, opts GenOptions) *timestamppb.Timestamp
- func GoogleValue(fd protoreflect.FieldDescriptor, opts GenOptions) *structpb.Value
- func Int32(fd protoreflect.FieldDescriptor, opts GenOptions) int32
- func Int64(fd protoreflect.FieldDescriptor, opts GenOptions) int64
- func Map(msg protoreflect.Message, fd protoreflect.FieldDescriptor, opts GenOptions) *protoreflect.Value
- func NewFauxFaker() *fauxFaker
- func NewMessage(md protoreflect.MessageDescriptor, opts GenOptions) (protoreflect.ProtoMessage, error)
- func NewMultiFaker(fakers []ProtoFaker) multiFaker
- func Repeated(msg protoreflect.Message, fd protoreflect.FieldDescriptor, opts GenOptions) *protoreflect.Value
- func SFixed32(fd protoreflect.FieldDescriptor, opts GenOptions) int32
- func SFixed64(fd protoreflect.FieldDescriptor, opts GenOptions) int64
- func SInt32(fd protoreflect.FieldDescriptor, opts GenOptions) int32
- func SInt64(fd protoreflect.FieldDescriptor, opts GenOptions) int64
- func SetDataOnMessage(msg protoreflect.ProtoMessage, opts GenOptions) error
- func String(fd protoreflect.FieldDescriptor, opts GenOptions) string
- func UInt32(fd protoreflect.FieldDescriptor, opts GenOptions) uint32
- func UInt64(fd protoreflect.FieldDescriptor, opts GenOptions) uint64
- func UninterpretedOption(opts GenOptions) *descriptorpb.UninterpretedOption
- type ExtensionResolver
- type FieldGenOptions
- type GenOptions
- type ProtoFaker
- type StubEntry
- type StubFinder
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var (
ErrNotFaked = errors.New("no data was faked either because there was no relevant data or the faker was just out of faker juice")
)
Functions ¶
func Bool ¶ added in v0.0.9
func Bool(fd protoreflect.FieldDescriptor, opts GenOptions) bool
Bool returns a fake boolean value given a field descriptor.
func Bytes ¶ added in v0.0.9
func Bytes(fd protoreflect.FieldDescriptor, opts GenOptions) []byte
Bytes returns a fake []byte value given a field descriptor.
func Enum ¶ added in v0.0.9
func Enum(fd protoreflect.FieldDescriptor, opts GenOptions) protoreflect.EnumNumber
func FieldValue ¶ added in v0.3.0
func FieldValue(fd protoreflect.FieldDescriptor, opts GenOptions) *protoreflect.Value
func Fixed32 ¶ added in v0.0.9
func Fixed32(fd protoreflect.FieldDescriptor, opts GenOptions) uint32
Fixed32 returns a fake fixed32 value given a field descriptor.
func Fixed64 ¶ added in v0.0.9
func Fixed64(fd protoreflect.FieldDescriptor, opts GenOptions) uint64
Fixed64 returns a fake fixed64 value given a field descriptor.
func Float32 ¶ added in v0.0.9
func Float32(fd protoreflect.FieldDescriptor, opts GenOptions) float32
Float32 returns a fake float32 value given a field descriptor.
func Float64 ¶ added in v0.0.9
func Float64(fd protoreflect.FieldDescriptor, opts GenOptions) float64
Float64 returns a fake float64 value given a field descriptor.
func GoogleDuration ¶ added in v0.0.9
func GoogleDuration(fd protoreflect.FieldDescriptor, opts GenOptions) *durationpb.Duration
GoogleDuration generates a random google.protobuf.Duration value.
func GoogleFieldMask ¶ added in v0.28.0
func GoogleFieldMask(fd protoreflect.FieldDescriptor, opts GenOptions) *fieldmaskpb.FieldMask
GoogleFieldMask generates a random google.protobuf.FieldMask value.
A field mask is only meaningful relative to some other message: its paths have to name fields that actually exist, or the mask is useless to whatever reads it. So the message the mask most likely applies to is guessed from the mask's surroundings (see fieldMaskTarget) and paths are drawn from that message's fields.
func GoogleTimestamp ¶ added in v0.0.9
func GoogleTimestamp(fd protoreflect.FieldDescriptor, opts GenOptions) *timestamppb.Timestamp
GoogleTimestamp generates a random google.protobuf.Timestamp value.
func GoogleValue ¶ added in v0.0.9
func GoogleValue(fd protoreflect.FieldDescriptor, opts GenOptions) *structpb.Value
func Int32 ¶ added in v0.0.9
func Int32(fd protoreflect.FieldDescriptor, opts GenOptions) int32
Int32 returns a fake int32 value given a field descriptor.
func Int64 ¶ added in v0.0.9
func Int64(fd protoreflect.FieldDescriptor, opts GenOptions) int64
Int64 returns a fake int64 value given a field descriptor.
func Map ¶ added in v0.0.16
func Map(msg protoreflect.Message, fd protoreflect.FieldDescriptor, opts GenOptions) *protoreflect.Value
Map returns a fake repeated value given a field descriptor.
func NewFauxFaker ¶ added in v0.3.0
func NewFauxFaker() *fauxFaker
func NewMessage ¶ added in v0.0.10
func NewMessage(md protoreflect.MessageDescriptor, opts GenOptions) (protoreflect.ProtoMessage, error)
NewMessage creates a new message populated with fake data given a protoreflect.MessageDescriptor
Example ¶
package main
import (
"fmt"
elizav1 "buf.build/gen/go/connectrpc/eliza/protocolbuffers/go/connectrpc/eliza/v1"
"github.com/sudorandom/fauxrpc"
"google.golang.org/protobuf/encoding/protojson"
)
func main() {
msg, _ := fauxrpc.NewMessage(elizav1.File_connectrpc_eliza_v1_eliza_proto.Messages().ByName("SayResponse"), fauxrpc.GenOptions{})
b, _ := protojson.MarshalOptions{Indent: " "}.Marshal(msg)
fmt.Println(string(b))
}
Output:
func NewMultiFaker ¶ added in v0.3.0
func NewMultiFaker(fakers []ProtoFaker) multiFaker
func Repeated ¶ added in v0.0.16
func Repeated(msg protoreflect.Message, fd protoreflect.FieldDescriptor, opts GenOptions) *protoreflect.Value
Repeated returns a fake repeated value given a field descriptor.
func SFixed32 ¶ added in v0.0.9
func SFixed32(fd protoreflect.FieldDescriptor, opts GenOptions) int32
SFixed32 returns a fake sfixedint32 value given a field descriptor.
func SFixed64 ¶ added in v0.0.9
func SFixed64(fd protoreflect.FieldDescriptor, opts GenOptions) int64
SFixed64 returns a fake sfixed64 value given a field descriptor.
func SInt32 ¶ added in v0.0.9
func SInt32(fd protoreflect.FieldDescriptor, opts GenOptions) int32
SInt32 returns a fake sint32 value given a field descriptor.
func SInt64 ¶ added in v0.0.9
func SInt64(fd protoreflect.FieldDescriptor, opts GenOptions) int64
SInt64 returns a fake sint64 value given a field descriptor.
func SetDataOnMessage ¶ added in v0.0.4
func SetDataOnMessage(msg protoreflect.ProtoMessage, opts GenOptions) error
SetDataOnMessage generates fake data given a protoreflect.ProtoMessage and sets the field values.
Example ¶
package main
import (
"fmt"
"log"
elizav1 "buf.build/gen/go/connectrpc/eliza/protocolbuffers/go/connectrpc/eliza/v1"
"github.com/sudorandom/fauxrpc"
"google.golang.org/protobuf/encoding/protojson"
)
func main() {
msg := &elizav1.SayResponse{}
if err := fauxrpc.SetDataOnMessage(msg, fauxrpc.GenOptions{}); err != nil {
log.Fatalf("error: %s", err) // handle error
}
b, _ := protojson.MarshalOptions{Indent: " "}.Marshal(msg)
fmt.Println(string(b))
}
Output:
func String ¶ added in v0.0.9
func String(fd protoreflect.FieldDescriptor, opts GenOptions) string
String returns a fake string value given a field descriptor.
func UInt32 ¶ added in v0.0.9
func UInt32(fd protoreflect.FieldDescriptor, opts GenOptions) uint32
UInt32 returns a fake uint32 value given a field descriptor.
func UInt64 ¶ added in v0.0.9
func UInt64(fd protoreflect.FieldDescriptor, opts GenOptions) uint64
UInt64 returns a fake uint64 value given a field descriptor.
func UninterpretedOption ¶ added in v0.6.0
func UninterpretedOption(opts GenOptions) *descriptorpb.UninterpretedOption
UninterpretedOption generates a random google.protobuf.UninterpretedOption value.
Types ¶
type ExtensionResolver ¶ added in v0.28.0
type ExtensionResolver interface {
RangeExtensionsByMessage(message protoreflect.FullName, f func(protoreflect.ExtensionType) bool)
}
ExtensionResolver hands back the extensions declared for a message. It is the part of *protoregistry.Types that generation needs, and both protoregistry.GlobalTypes and a registry built from a loaded schema satisfy it.
type FieldGenOptions ¶ added in v0.6.0
type FieldGenOptions struct {
Message *validate.FieldRules
}
type GenOptions ¶ added in v0.0.14
type GenOptions struct {
MaxDepth int
Faker *gofakeit.Faker
Context context.Context
StubRecorder func(StubEntry)
StubFinder StubFinder
// ViolateRules is the probability, from 0.0 to 1.0, that any single
// protovalidate rule is broken rather than satisfied. Every rule on every
// field is rolled independently, so a field carrying five rules is far more
// likely to end up invalid than a field carrying one. 0 (the default) never
// violates and 1 breaks every rule it can.
//
// A field can only hold one value, so when several of its rules come up at
// once, one of them is picked at random to be the one that breaks.
//
// Rules that no value can violate on its own (message-level rules and CEL
// expressions) are always satisfied, so a message is not guaranteed to fail
// validation even at 1.0.
ViolateRules float64
// Extensions is where generation looks for the extensions of each message
// it fills in. It has no default: a message descriptor cannot name the
// extensions declared against it, so without a resolver to ask, extension
// fields are left unset.
//
// A registry that loaded the schema is the resolver to pass; for types
// compiled into the binary, protoregistry.GlobalTypes works.
Extensions ExtensionResolver
// contains filtered or unexported fields
}
func (GenOptions) GetContext ¶ added in v0.3.0
func (st GenOptions) GetContext() context.Context
func (GenOptions) WithExtraFieldConstraints ¶ added in v0.6.0
func (st GenOptions) WithExtraFieldConstraints(rules *validate.FieldRules) GenOptions
type ProtoFaker ¶ added in v0.3.0
type ProtoFaker interface {
SetDataOnMessage(msg protoreflect.ProtoMessage, opts GenOptions) error
}
type StubEntry ¶ added in v0.5.0
type StubEntry interface {
GetName() protoreflect.FullName
GetID() string
}
type StubFinder ¶ added in v0.17.0
type StubFinder interface {
FindStub(name protoreflect.FullName, faker *gofakeit.Faker) protoreflect.ProtoMessage
}
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
fauxrpc
command
|
|
|
example
|
|
|
generated-faux-server
module
|
|
|
generated-mocks
module
|
|
|
private
|
|
|
frontend/templates
templ: version: v0.3.1020
|
templ: version: v0.3.1020 |
|
frontend/templates/browser
templ: version: v0.3.1020
|
templ: version: v0.3.1020 |
|
frontend/templates/browser/partials
templ: version: v0.3.1020
|
templ: version: v0.3.1020 |
|
frontend/templates/partials
templ: version: v0.3.1020
|
templ: version: v0.3.1020 |
|
frontend/templates/stubs
templ: version: v0.3.1020
|
templ: version: v0.3.1020 |
|
testcontainers
module
|


