Documentation ¶
Overview ¶
Package featureBreaker contains filters for dynamically disabling/breaking API features at test-time.
In particular, it can be used to cause specific service methods to start returning specific errors during the test.
Index ¶
- Variables
- type BreakFeatureCallback
- type FeatureBreaker
- func FilterGI(c context.Context, defaultError error) (context.Context, FeatureBreaker)
- func FilterMC(c context.Context, defaultError error) (context.Context, FeatureBreaker)
- func FilterMail(c context.Context, defaultError error) (context.Context, FeatureBreaker)
- func FilterModule(c context.Context, defaultError error) (context.Context, FeatureBreaker)
- func FilterRDS(c context.Context, defaultError error) (context.Context, FeatureBreaker)
- func FilterTQ(c context.Context, defaultError error) (context.Context, FeatureBreaker)
- func FilterUser(c context.Context, defaultError error) (context.Context, FeatureBreaker)
Constants ¶
This section is empty.
Variables ¶
var DatastoreFeatures = []string{
"AllocateIDs",
"DecodeCursor",
"Run",
"Count",
"BeginTransaction",
"CommitTransaction",
"DeleteMulti",
"GetMulti",
"PutMulti",
}
DatastoreFeatures is a list of datastore features that can be "broken".
Functions ¶
This section is empty.
Types ¶
type BreakFeatureCallback ¶
BreakFeatureCallback can be used to break features at the time of the call.
If it return an error, this error will be returned by the corresponding API call as is. If returns nil, the call will be performed as usual.
It receives a derivative of a context passed to the original API call which can be used to extract any contextual information, if necessary.
The callback will be called often and concurrently. Provide your own synchronization if necessary.
type FeatureBreaker ¶
type FeatureBreaker interface { // BreakFeatures allows you to set an error that should be returned by the // corresponding functions. // // For example // m.BreakFeatures(memcache.ErrServerError, "Add") // // would make memcache.Add return memcache.ErrServerError. You can reverse // this by calling UnbreakFeatures("Add"). // // The only exception to this rule is two "fake" functions that can be used // to simulate breaking "RunInTransaction" in a more detailed way: // * Use "BeginTransaction" as a feature name to simulate breaking of a new // transaction attempt. It is called before each individual retry. // * Use "CommitTransaction" as a feature name to simulate breaking the // transaction commit RPC. It is called after the transaction body // completes. Returning datastore.ErrConcurrentTransaction here will cause // a retry. // // "RunInTransaction" itself is not breakable. Break "BeginTransaction" or // "CommitTransaction" instead. BreakFeatures(err error, feature ...string) // BreakFeaturesWithCallback is like BreakFeatures, except it allows you to // decide whether to return an error or not at the time the function call is // happening. // // The callback will be called often and concurrently. Provide your own // synchronization if necessary. // // You may use a callback returned by flaky.Errors(...) to emulate randomly // occurring errors. // // Note that the default error passed to Filter* functions are ignored when // using callbacks. BreakFeaturesWithCallback(cb BreakFeatureCallback, feature ...string) // UnbreakFeatures is the inverse of BreakFeatures/BreakFeaturesWithCallback, // and will return the named features back to their original functionality. UnbreakFeatures(feature ...string) }
FeatureBreaker is the state-access interface for all Filter* functions in this package. A feature is the Name of some method on the filtered service.
So if you had:
c, fb := FilterMC(...) mc := gae.GetMC(c)
you could do:
fb.BreakFeatures(memcache.ErrServerError, "Add", "Set")
and then
mc.Add(...) and mc.Set(...)
would return the error.
You may also pass nil as the error for BreakFeatures, and the fake will provide the DefaultError which you passed to the Filter function.
This interface can only break features which return errors.
func FilterMail ¶
FilterMail installs a featureBreaker mail filter in the context.
func FilterModule ¶
FilterModule installs a featureBreaker module filter in the context.
func FilterUser ¶
FilterUser installs a featureBreaker user filter in the context.