firestarter

package module
v0.0.0-...-c07a055 Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

README

go-firestarter

go-firestarter an emulator for Google Firestore. It stores documents and collections in memory and performs queries against that in-memory store.

go-firestarter was forked from go-mockfs (https://github.com/weathersource/go-mockfs). go-mockfs is a low level mock for Google Firestore matching the request's protobuf message and returning a response protofbuf message. go-firestarter differs by implementing the logic for creating/updating documents and querying.

Missing Functionality

How To Use?

client_test.go (https://github.com/ISBX/go-firestarter/blob/master/client_test.go) is a good reference.

An example:

ctx := context.Background()
client, srv, err := New()
assert.Nil(t, err)
defer srv.Close()

srv.LoadFromJSONFile("test.json")

docSnaps, err := client.Collection("collection-1").Where("field1", "==", "value-1-2-1").Documents(ctx).GetAll()
assert.Nil(t, err)

assert.Len(t, docSnaps, 1)
assert.Equal(t, "document-1-2", docSnaps[0].Ref.ID)
func (s *MockServer) LoadFromJSONFile(filePath string) error

Since JSON types only cover a subset of Firestore types, LoadFromJSONFile will parse strings for Timestamps and Bytes.

  • If the string is a RFC3339 (https://pkg.go.dev/time#pkg-constants), the value will be stored as a time.Time internally and returned as a pb.Value_TimestampValue.
  • If the string is a data URL, the value will be stored as a []byte and returned as a pb.Value_BytesValue.

test.json (https://github.com/ISBX/go-firestarter/blob/master/test.json) has a few examples.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCollectionNotFound = status.Error(codes.NotFound, "collection not found")
View Source
var ErrDocumentNotFound = status.Error(codes.NotFound, "document not found")

Functions

This section is empty.

Types

type Collection

type Collection struct {
	// contains filtered or unexported fields
}

type Document

type Document struct {
	// contains filtered or unexported fields
}

func (*Document) Clear

func (d *Document) Clear()

func (*Document) Get

func (d *Document) Get(name string) interface{}

func (*Document) SetWithValue

func (d *Document) SetWithValue(name string, value *pb.Value)

func (*Document) ToProto

func (d *Document) ToProto(fullPath string) *pb.Document

type MockServer

type MockServer struct {
	pb.FirestoreServer
	Addr string
	// contains filtered or unexported fields
}

MockServer mocks the pb.FirestoreServer interface (https://godoc.org/google.golang.org/genproto/googleapis/firestore/v1beta1#FirestoreServer)

func New

func New() (*firestore.Client, *MockServer, error)

New creates a new Firestore Client and MockServer

func (*MockServer) BatchGetDocuments

BatchGetDocuments overrides the FirestoreServer BatchGetDocuments method

func (*MockServer) BeginTransaction

BeginTransaction overrides the FirestoreServer BeginTransaction method

func (*MockServer) Close

func (s *MockServer) Close()

func (*MockServer) Commit

func (s *MockServer) Commit(ctx context.Context, req *pb.CommitRequest) (*pb.CommitResponse, error)

Commit overrides the FirestoreServer Commit method

func (*MockServer) GetDocument

func (s *MockServer) GetDocument(ctx context.Context, req *pb.GetDocumentRequest) (*pb.Document, error)

GetDocument overrides the FirestoreServer GetDocument method

func (*MockServer) Listen

func (s *MockServer) Listen(stream pb.Firestore_ListenServer) error

Listen overrides the FirestoreServer Listen method

func (*MockServer) LoadFromJSONFile

func (s *MockServer) LoadFromJSONFile(filePath string) error

LoadFromFile loads a JSON file into the MockServer.

func (*MockServer) Reset

func (s *MockServer) Reset()

Reset returns the MockServer to an empty state.

func (*MockServer) Rollback

func (s *MockServer) Rollback(ctx context.Context, req *pb.RollbackRequest) (*empty.Empty, error)

Rollback overrides the FirestoreServer Rollback method

func (*MockServer) RunQuery

RunQuery overrides the FirestoreServer RunQuery method

Jump to

Keyboard shortcuts

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