Documentation ¶
Overview ¶
Package util provides assorted utility functions that can be reused across the poc-gcp-ecomm project.
Index ¶
- func CaptureLogging(f func()) string
- type DocIteratorProxy
- type DocRefProxy
- func (p *DocRefProxy) Create(doc *firestore.DocumentRef, ctx context.Context, data interface{}) (*firestore.WriteResult, error)
- func (p *DocRefProxy) Delete(doc *firestore.DocumentRef, ctx context.Context) (*firestore.WriteResult, error)
- func (p *DocRefProxy) Get(doc *firestore.DocumentRef, ctx context.Context) (*firestore.DocumentSnapshot, error)
- func (p *DocRefProxy) Set(doc *firestore.DocumentRef, ctx context.Context, data interface{}) (*firestore.WriteResult, error)
- type DocSnapProxy
- type DocumentIteratorProxy
- type DocumentRefProxy
- type DocumentSnapshotProxy
- type ItemCollGetterProxy
- type ItemCollectionGetterProxy
- type ItemsCollProxy
- type ItemsCollectionProxy
- type UTDocIteratorProxy
- type UTDocRefProxy
- func (p *UTDocRefProxy) Create(doc *firestore.DocumentRef, ctx context.Context, data interface{}) (*firestore.WriteResult, error)
- func (p *UTDocRefProxy) Delete(doc *firestore.DocumentRef, ctx context.Context) (*firestore.WriteResult, error)
- func (p *UTDocRefProxy) Get(doc *firestore.DocumentRef, ctx context.Context) (*firestore.DocumentSnapshot, error)
- func (p *UTDocRefProxy) Set(doc *firestore.DocumentRef, ctx context.Context, data interface{}) (*firestore.WriteResult, error)
- type UTDocSnapProxy
- type UTItemCollGetterProxy
- type UTItemsCollProxy
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CaptureLogging ¶
func CaptureLogging(f func()) string
CaptureLogging allows unit tests to override the default Zap logger to capture the logging output that results from execution of the supplied function. The captured log output is returned as a string after the default logger has been restored.
The supplied function parameter would typically be an inline function supplied by a unit test that needs to evaluate the log output of some test subject to determine if the test passed or failed.
Types ¶
type DocIteratorProxy ¶
type DocIteratorProxy struct { DocumentIteratorProxy // contains filtered or unexported fields }
DocIteratorProxy is the production (i.e. non-unit test) implementation of the DocumentIteratorProxy interface.
It is returned by calls to the CollRefProxy Documents function, itself a proxy implementation of firestore.CollectionRef.
func (*DocIteratorProxy) Next ¶
func (p *DocIteratorProxy) Next(target interface{}) error
Next returns the next result. Its second return value is iterator.Done if there are no more results. Once Next returns Done, all subsequent calls will return Done.
func (*DocIteratorProxy) Stop ¶
func (p *DocIteratorProxy) Stop()
Stop stops the iterator, freeing its resources. Always call Stop when you are done with a DocumentIterator. It is not safe to call Stop concurrently with Next.
type DocRefProxy ¶
type DocRefProxy struct {
DocumentRefProxy
}
DocRefProxy is the production (i.e. non-unit test) implementation of the DocumentRefProxy interface. NewCartService configures it as the default in new CartService structure constructions.
func (*DocRefProxy) Create ¶
func (p *DocRefProxy) Create(doc *firestore.DocumentRef, ctx context.Context, data interface{}) (*firestore.WriteResult, error)
Create is a direct pass through to the firestore.DocumentRef Create function. We use this rather than calling the firestore.DocumentRef function directly so that we can replace this implementation with one that allows errors to be inserted into the response when executing uni tests.
func (*DocRefProxy) Delete ¶
func (p *DocRefProxy) Delete(doc *firestore.DocumentRef, ctx context.Context) (*firestore.WriteResult, error)
Delete is a direct pass through to the firestore.DocumentRef Delete function. We use this rather than calling the firestore.DocumentRef function directly so that we can replace this implementation with one that allows errors to be inserted into the response when executing uni tests.
func (*DocRefProxy) Get ¶
func (p *DocRefProxy) Get(doc *firestore.DocumentRef, ctx context.Context) (*firestore.DocumentSnapshot, error)
Get is a direct pass through to the firestore.DocumentRef Get function. We use this rather than calling the firestore.DocumentRef function directly so that we can replace this implementation with one that allows errors to be inserted into the response when executing uni tests.
func (*DocRefProxy) Set ¶
func (p *DocRefProxy) Set(doc *firestore.DocumentRef, ctx context.Context, data interface{}) (*firestore.WriteResult, error)
Set is a direct pass through to the firestore.DocumentRef Set function. We use this rather than calling the firestore.DocumentRef function directly so that we can replace this implementation with one that allows errors to be inserted into the response when executing uni tests.
type DocSnapProxy ¶
type DocSnapProxy struct {
DocumentRefProxy
}
DocSnapProxy is the production (i.e. non-unit test) implementation of the DocumentSnapshotProxy interface. NewCartService configures it as the default in new CartService structure constructions.
func (*DocSnapProxy) DataTo ¶
func (p *DocSnapProxy) DataTo(snap *firestore.DocumentSnapshot, target interface{}) error
DataTo is a direct pass through to the firestore.DocumentSnapshot DataTo function. We use this rather than calling the firestore.DocumentSnapshot function directly so that we can replace this implementation with one that allows errors to be inserted into the response when executing uni tests.
type DocumentIteratorProxy ¶
type DocumentIteratorProxy interface { Next(target interface{}) error Stop() }
DocumentIteratorProxy defines the interface for a swappable junction that will allow us to maximize unit test coverage by intercepting calls to firestore.DocumentIterator methods and having them return either mock errors or document and/or iterator proxies. The default production implementation of the interface will add a couple of nanoseconds of delay to normal operation but that extra test coverage is worth the price.
See https://pkg.go.dev/cloud.google.com/go/firestore#DocumentIterator
type DocumentRefProxy ¶
type DocumentRefProxy interface { Create(doc *firestore.DocumentRef, ctx context.Context, data interface{}) (*firestore.WriteResult, error) Get(doc *firestore.DocumentRef, ctx context.Context) (*firestore.DocumentSnapshot, error) Set(doc *firestore.DocumentRef, ctx context.Context, data interface{}) (*firestore.WriteResult, error) Delete(doc *firestore.DocumentRef, ctx context.Context) (*firestore.WriteResult, error) }
DocumentRefProxy defines the interface for a swappable junction that will allow us to maximize unit test coverage by intercepting calls to firestore.DocumentRef methods and having them return mock errors. The default production implementation of the interface will add a couple of nanoseconds of delay to normal operation but that extra test coverage is worth the price.
See https://pkg.go.dev/cloud.google.com/go/firestore#DocumentRef
type DocumentSnapshotProxy ¶
type DocumentSnapshotProxy interface {
DataTo(snap *firestore.DocumentSnapshot, target interface{}) error
}
DocumentSnapshotProxy defines the interface for a swappable junction that will allow us to maximize unit test coverage by intercepting calls to firestore.DocumentSnapshot methods and having them return mock errors. The default production implementation of the interface will add a couple of nanoseconds of delay to normal operation but that extra test coverage is worth the price.
See https://pkg.go.dev/cloud.google.com/go/firestore#DocumentSnapshot
type ItemCollGetterProxy ¶
type ItemCollGetterProxy struct { ItemCollectionGetterProxy // FsClient is the GCP Firestore client - it is thread safe and can be reused concurrently FsClient *firestore.Client }
ItemCollGetterProxy is the production (i.e. non-unit test) implementation of the ItemCollectionGetterProxy interface. NewCartService configures it as the default in new CartService structure constructions.
func (*ItemCollGetterProxy) Items ¶
func (p *ItemCollGetterProxy) Items(path string) ItemsCollectionProxy
Items returns a collection reference proxy that allows the shopping cart items of the given cart to be retrieved from Firestore.
type ItemCollectionGetterProxy ¶
type ItemCollectionGetterProxy interface {
Items(path string) ItemsCollectionProxy
}
ItemCollectionGetterProxy defines an interface that the cart service can use to obtain an ItemsCollectionProxy for a given cart. Unit tests may substitute an alternative implementation this interface in order to be able to insert errors etc. into the responses of the ItemsCollectionProxy that the ItemCollectionGetterProxy returns.
type ItemsCollProxy ¶
type ItemsCollProxy struct { ItemsCollectionProxy // contains filtered or unexported fields }
ItemsCollProxy is the production (i.e. non-unit test) implementation of the ItemsCollectionProxy interface.
See https://pkg.go.dev/cloud.google.com/go/firestore#CollectionRef
func (*ItemsCollProxy) GetAll ¶
func (p *ItemsCollProxy) GetAll(ctx context.Context) DocumentIteratorProxy
GetAll is a wrapper around the firestore.CollectionRef Documents function (actually the firestore.Query Documents function) that will return an iterator over shopping cart items from a Firestore cart representation.
type ItemsCollectionProxy ¶
type ItemsCollectionProxy interface {
GetAll(ctx context.Context) DocumentIteratorProxy
}
ItemsCollectionProxy defines the interface for a swappable junction that will allow us to maximize unit test coverage by wrapping calls to the firestore.CollectionRef Documents method and so allowing unit test implementations to return either mock errors, mock documents, or mock iterator proxies. The default production implementation of the interface will add a couple of nanoseconds of delay to normal operation but that extra test coverage is worth the price.
See https://pkg.go.dev/cloud.google.com/go/firestore#CollectionRef
type UTDocIteratorProxy ¶
type UTDocIteratorProxy struct { DocumentIteratorProxy DocsIterator *firestore.DocumentIterator DsProxy DocumentSnapshotProxy // Err is the error to be returned if it is not nil Err error // AllowCount, if greater than zero, is the number of calls to allow before returning the error AllowCount int }
UTDocIteratorProxy is a unit test implementation of the DocumentIteratorProxy interface that allows unit tests to have Firestore operations return errors.
func (*UTDocIteratorProxy) Next ¶
func (p *UTDocIteratorProxy) Next(target interface{}) error
Next returns the next result. Its second return value is iterator.Done if there are no more results. Once Next returns Done, all subsequent calls will return Done.
func (*UTDocIteratorProxy) Stop ¶
func (p *UTDocIteratorProxy) Stop()
Stop stops the iterator, freeing its resources. Always call Stop when you are done with a DocumentIterator. It is not safe to call Stop concurrently with Next.
type UTDocRefProxy ¶
type UTDocRefProxy struct { DocumentRefProxy // Err is the error to be returned if it is not nil Err error // AllowCount, if greater than zero, is the number of calls to allow before returning the error AllowCount int }
UTDocRefProxy is a unit test implementation of the DocumentRefProxy interface that allows unit tests to have Firestore operations return errors.
func (*UTDocRefProxy) Create ¶
func (p *UTDocRefProxy) Create(doc *firestore.DocumentRef, ctx context.Context, data interface{}) (*firestore.WriteResult, error)
Create is a pass through to the firestore.DocumentRef Create function that allows unit tests to have Firestore operations return errors.
func (*UTDocRefProxy) Delete ¶
func (p *UTDocRefProxy) Delete(doc *firestore.DocumentRef, ctx context.Context) (*firestore.WriteResult, error)
Delete is a pass through to the firestore.DocumentRef Delete function that allows unit tests to have Firestore operations return errors.
func (*UTDocRefProxy) Get ¶
func (p *UTDocRefProxy) Get(doc *firestore.DocumentRef, ctx context.Context) (*firestore.DocumentSnapshot, error)
Get is a pass through to the firestore.DocumentRef Get function that allows unit tests to have Firestore operations return errors.
func (*UTDocRefProxy) Set ¶
func (p *UTDocRefProxy) Set(doc *firestore.DocumentRef, ctx context.Context, data interface{}) (*firestore.WriteResult, error)
Set is a pass through to the firestore.DocumentRef Set function that allows unit tests to have Firestore operations return errors.
type UTDocSnapProxy ¶
type UTDocSnapProxy struct { DocumentRefProxy // err is the error to be returned if it is not nil Err error // AllowCount, if greater than zero, is the number of calls to allow before returning the error AllowCount int }
UTDocSnapProxy is a unit test implementation of the DocumentSnapshotProxy interface that allows unit tests to have Firestore operations return errors.
func (*UTDocSnapProxy) DataTo ¶
func (p *UTDocSnapProxy) DataTo(snap *firestore.DocumentSnapshot, target interface{}) error
DataTo is a direct pass through to the firestore.DocumentSnapshot DataTo function that allows unit tests to have Firestore operations return errors.
type UTItemCollGetterProxy ¶
type UTItemCollGetterProxy struct { ItemCollectionGetterProxy // FsClient is the GCP Firestore client - it is thread safe and can be reused concurrently FsClient *firestore.Client // Err is the error to be returned if it is not nil Err error // AllowCount, if greater than zero, is the number of calls to allow before returning the error AllowCount int }
UTItemCollGetterProxy is a unit test implementation of the ItemCollectionGetterProxy interface that allows unit tests to have Firestore operations return errors.
func (*UTItemCollGetterProxy) Items ¶
func (p *UTItemCollGetterProxy) Items(path string) ItemsCollectionProxy
Items returns a collection reference proxy that allows the shopping cart items of the given cart to be retrieved from Firestore.
type UTItemsCollProxy ¶
type UTItemsCollProxy struct { ItemsCollectionProxy // Ref is the items collection references that this proxy is wrapping Ref *firestore.CollectionRef // Err is the error to be returned if it is not nil Err error // AllowCount, if greater than zero, is the number of calls to allow before returning the error AllowCount int }
UTItemsCollProxy is a unit test implementation of the ItemsCollectionProxy interface that allows unit tests to have Firestore operations return errors.
func (*UTItemsCollProxy) GetAll ¶
func (p *UTItemsCollProxy) GetAll(ctx context.Context) DocumentIteratorProxy
GetAll is a wrapper around the firestore.CollectionRef Documents function (actually the firestore.Query Documents function) that will return an iterator over shopping cart items from a Firestore cart representation.