func WithNewSubscription( subID, topicID string, opts ...SubOption, ) func(ctx f2.Context, t *testing.T) f2.Context
func WithNewTopic(topicID string) func(ctx f2.Context, t *testing.T) f2.Context
type PubSub struct { // Conn provides the following: // // 1. Test subscriptions losing connection by calling // ps.Conn.Close() // // 2. Create pubsub clients in different projects by calling // pubsub.NewClient(ctx, "projectID", option.WithGRPCConn(ps.Conn)) Conn *grpc.ClientConn // contains filtered or unexported fields }
func FromContext(ctx context.Context) (*PubSub, error)
FromContext attempts to fetch an instance of PubSub from the test context and returns an error if it is not discovered.
func FromContextT(ctx fctx.Context, t *testing.T) *PubSub
FromContextT is a testing variant of FromContext that immediately fails the test if PubSub is not present in the testing context.
func New(opts ...PubSubOption) (ps *PubSub)
Create a new mock PubSub instance.
func (ps *PubSub) CreateSubscription(ctx context.Context, topicID, subID string, opts ...SubOption) (*pubsub.Subscription, error)
Creates a new subscription to a given topic in the Pubsub instance.
func (ps *PubSub) CreateTopic(ctx context.Context, topicID string) (*pubsub.Topic, error)
Creates a new topic in the PubSub instance.
func (ps *PubSub) IntoContext(ctx f2.Context) f2.Context
IntoContext stores the framework extension in the test context.
func (ps *PubSub) Publish(ctx context.Context, topicID, data string, attributes map[string]string) (msgID string, err error)
Publishes a pubsub message to all subscribers of a given topic
func (ps *PubSub) RegisterFns(f f2.Framework)
RegisterFns is called by the framework after binding and parsing test flags (not currently implemented here). Ensures that every test has a fresh instance of PubSub.
func (ps *PubSub) Subscribe(ctx context.Context, subID string, receiveFunc func(context.Context, *pubsub.Message)) error
Starts an active subscription with a given receive function
type PubSubOption func(*pubsuboptions)
func WithFixedPort(port int) PubSubOption
By default, pstest will connect the server to a random free port. Ensure the port set here isn't already being used.
func WithProjectID(id string) PubSubOption
Make sure that if you use PubSub struct methods, topics and subscriptions created match this project ID.
type SubOption func(*suboptions)
func WithAckDeadline(ackDeadline time.Duration) SubOption
func WithExpirationPolicy(expirationPolicy time.Duration) SubOption
func WithFilter(filter string) SubOption