fauxrpc

package module
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2024 License: MIT Imports: 17 Imported by: 0

README

FauxRPC

Go Go Report Card Go Reference

FauxRPC is a powerful tool that empowers you to accelerate development and testing by effortlessly generating fake implementations of gRPC, gRPC-Web, Connect, and REST services. If you have a protobuf-based workflow, this tool could help.

Why FauxRPC?

  • Faster Development & Testing: Work independently without relying on fully functional backend services.
  • Isolation & Control: Test frontend components in isolation with controlled fake data.
  • Multi-Protocol Support: Supports multiple protocols (gRPC, gRPC-Web, Connect, and REST).
  • Prototyping & Demos: Create prototypes and demos quickly without building the full backend. Fake it till you make it.
  • Improved Collaboration: Bridge the gap between frontend and backend teams.
  • Plays well with others: Test data from FauxRPC will try to automatically follow any protovalidate constraints that are defined.

See the the documentation website for more!

Get Started

Install via source
go install github.com/sudorandom/fauxrpc/cmd/fauxrpc@latest
Pre-built binaries

Binaries are built for several platforms for each release. See the latest ones on the releases page.

Quick Start

Pass protobuf descriptors to FauxRPC and a test server will be created, returning random fake data!

$ fauxrpc run --schema=service.binpb

That's... it. Now you can call it with your gRPC/gRPC-Web/Connect clients:

$ buf curl --http2-prior-knowledge http://127.0.0.1:6660/my.own.v1.service/HelloWorld
{
  "text": "Thundercats."
}

Go to the documentation website for more!

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool added in v0.0.9

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

Enum returns a fake enum value given a field descriptor.

func Fixed32 added in v0.0.9

Fixed32 returns a fake fixed32 value given a field descriptor.

func Fixed64 added in v0.0.9

Fixed64 returns a fake fixed64 value given a field descriptor.

func Float32 added in v0.0.9

Float32 returns a fake float32 value given a field descriptor.

func Float64 added in v0.0.9

Float64 returns a fake float64 value given a field descriptor.

func GoogleDuration added in v0.0.9

func GoogleDuration(fd protoreflect.FieldDescriptor) *durationpb.Duration

GoogleDuration generates a random google.protobuf.Duration value.

func GoogleTimestamp added in v0.0.9

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

Int32 returns a fake int32 value given a field descriptor.

func Int64 added in v0.0.9

Int64 returns a fake int64 value given a field descriptor.

func Map added in v0.0.16

Map returns a fake repeated value given a field descriptor.

func NewMessage added in v0.0.10

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 Repeated added in v0.0.16

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

SInt32 returns a fake sint32 value given a field descriptor.

func SInt64 added in v0.0.9

SInt64 returns a fake sint64 value given a field descriptor.

func SetDataOnMessage added in v0.0.4

func SetDataOnMessage(msg protoreflect.ProtoMessage, opts GenOptions)

SetDataOnMessage generates fake data given a protoreflect.ProtoMessage and sets the field values.

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 := &elizav1.SayResponse{}
	fauxrpc.SetDataOnMessage(msg, fauxrpc.GenOptions{})
	b, _ := protojson.MarshalOptions{Indent: "  "}.Marshal(msg)
	fmt.Println(string(b))
}
Output:

func String added in v0.0.9

String returns a fake string value given a field descriptor.

func UInt32 added in v0.0.9

UInt32 returns a fake uint32 value given a field descriptor.

func UInt64 added in v0.0.9

UInt64 returns a fake uint64 value given a field descriptor.

Types

type GenOptions added in v0.0.14

type GenOptions struct {
	StubDB   stubs.StubDatabase
	MaxDepth int
	// contains filtered or unexported fields
}

Directories

Path Synopsis
cmd
private

Jump to

Keyboard shortcuts

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