Documentation ¶
Overview ¶
Package psiface provides a set of interfaces for the types in cloud.google.com/go/pubsub. These can be used to create mocks or other test doubles. The package also provides adapters to enable the types of the pubsub package to implement these interfaces.
We do not recommend using mocks for most testing. Please read https://testing.googleblog.com/2013/05/testing-on-toilet-dont-overuse-mocks.html.
Note: This package is in alpha. Some backwards-incompatible changes may occur.
You must embed these interfaces to implement them:
type ClientMock struct { psiface.Client ... }
This ensures that your implementations will not break when methods are added to the interfaces.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface { CreateTopic(ctx context.Context, topicID string) (Topic, error) Topic(id string) Topic CreateSubscription(ctx context.Context, id string, cfg SubscriptionConfig) (Subscription, error) Subscription(id string) Subscription // contains filtered or unexported methods }
func AdaptClient ¶
AdaptClient adapts a pubsub.Client so that it satisfies the Client interface.
Example ¶
package main import ( "context" "cloud.google.com/go/pubsub" "github.com/googleapis/google-cloud-go-testing/pubsub/psiface" ) func main() { ctx := context.Background() c, err := pubsub.NewClient(ctx, "") if err != nil { // TODO: Handle error. } client := psiface.AdaptClient(c) msg := psiface.AdaptMessage(&pubsub.Message{}) _, err = client.Topic("my-topic").Publish(ctx, msg).Get(ctx) if err != nil { // TODO: Handle error. } }
Output:
type Message ¶
type Message interface { ID() string Data() []byte Attributes() map[string]string PublishTime() time.Time Ack() Nack() // contains filtered or unexported methods }
func AdaptMessage ¶
AdaptMessage adapts a pubsub.Message so that it satisfies the Message interface.
type PublishResult ¶
type Subscription ¶
type SubscriptionConfig ¶
type SubscriptionConfig struct { pubsub.SubscriptionConfig Topic Topic // shadows pubsub.SubscriptionConfig's field }