...

Package pstest

import "edge-infra.dev/test/f2/x/pstest"
Overview
Index

Overview ▾

func WithNewSubscription

func WithNewSubscription(
    subID, topicID string,
    opts ...SubOption,
) func(ctx f2.Context, t *testing.T) f2.Context

func WithNewTopic

func WithNewTopic(topicID string) func(ctx f2.Context, t *testing.T) f2.Context

type PubSub

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

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

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

func New(opts ...PubSubOption) (ps *PubSub)

Create a new mock PubSub instance.

func (*PubSub) CreateSubscription

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 (*PubSub) CreateTopic

func (ps *PubSub) CreateTopic(ctx context.Context, topicID string) (*pubsub.Topic, error)

Creates a new topic in the PubSub instance.

func (*PubSub) IntoContext

func (ps *PubSub) IntoContext(ctx f2.Context) f2.Context

IntoContext stores the framework extension in the test context.

func (*PubSub) Publish

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 (*PubSub) RegisterFns

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 (*PubSub) Subscribe

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

type PubSubOption func(*pubsuboptions)

func WithFixedPort

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

func WithProjectID(id string) PubSubOption

Make sure that if you use PubSub struct methods, topics and subscriptions created match this project ID.

type SubOption

type SubOption func(*suboptions)

func WithAckDeadline

func WithAckDeadline(ackDeadline time.Duration) SubOption

func WithExpirationPolicy

func WithExpirationPolicy(expirationPolicy time.Duration) SubOption

func WithFilter

func WithFilter(filter string) SubOption