testing

package
v0.0.0-...-d19fc40 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2020 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Helper

type Helper struct {
	// The test pubsub server.
	// PubsubServer.Messages can be called to retrieve all published raw
	// pubsub messages.
	PubsubServer *pstest.Server
	// The pubsub client connected to the test pubsub server.
	// Can be used to operate pubsub resources.
	PubsubClient *pubsub.Client
	// The cloudevents pubsub protocol backed by the test pubsub client.
	// Can be used to send/receive events from the test pubsub server.
	CePubsub *cepubsub.Protocol
	// The targets config maintained by this helper.
	Targets config.Targets
	// contains filtered or unexported fields
}

Helper provides helper functions to facilitate handler pool testing.

func NewHelper

func NewHelper(ctx context.Context, projectID string) (*Helper, error)

NewHelper creates a new helper.

func (*Helper) Close

func (h *Helper) Close()

Close cleans up all resources.

func (*Helper) DeleteBroker

func (h *Helper) DeleteBroker(ctx context.Context, t *testing.T, brokerKey string)

DeleteBroker deletes the broker by key. It also cleans up test resources used by the broker.

func (*Helper) DeleteTarget

func (h *Helper) DeleteTarget(ctx context.Context, t *testing.T, targetKey string)

DeleteTarget deletes a target and test resources used by it.

func (*Helper) GenerateBroker

func (h *Helper) GenerateBroker(ctx context.Context, t *testing.T, namespace string) *config.Broker

GenerateBroker generates a broker in the given namespace with random broker name. The following test resources will also be created. 1. The broker decouple topic and subscription. 2. The broker ingress server.

func (*Helper) GenerateTarget

func (h *Helper) GenerateTarget(ctx context.Context, t *testing.T, brokerKey string, filters map[string]string) *config.Target

GenerateTarget generates a target for the broker with a random name. The following test resources will also be created: 1. The target retry topic/subscription. 2. The subscriber server.

func (*Helper) RenewBroker

func (h *Helper) RenewBroker(ctx context.Context, t *testing.T, brokerKey string) *config.Broker

RenewBroker generates new test resources for an existing broker.

func (*Helper) RenewTarget

func (h *Helper) RenewTarget(ctx context.Context, t *testing.T, targetKey string) *config.Target

RenewTarget generates new test resources for a target.

func (*Helper) SendEventToDecoupleQueue

func (h *Helper) SendEventToDecoupleQueue(ctx context.Context, t *testing.T, brokerKey string, event *event.Event)

SendEventToDecoupleQueue sends the given event to the decouple queue of the given broker.

func (*Helper) SendEventToRetryQueue

func (h *Helper) SendEventToRetryQueue(ctx context.Context, t *testing.T, targetKey string, event *event.Event)

SendEventToRetryQueue sends the given event to the retry queue of the given target.

func (*Helper) VerifyAndRespondNextTargetEvent

func (h *Helper) VerifyAndRespondNextTargetEvent(ctx context.Context, t *testing.T, targetKey string, wantEvent, replyEvent *event.Event, statusCode int, delay time.Duration)

VerifyAndRespondNextTargetEvent verifies the next event the subscriber receives and replies with the given parameters. If wantEvent is nil, then it means such an event is not expected. This function is blocking and should be invoked in a separate goroutine with context timeout.

func (*Helper) VerifyNextBrokerIngressEvent

func (h *Helper) VerifyNextBrokerIngressEvent(ctx context.Context, t *testing.T, brokerKey string, wantEvent *event.Event)

VerifyNextBrokerIngressEvent verifies the next event the broker ingress receives. If wantEvent is nil, then it means such an event is not expected. This function is blocking and should be invoked in a separate goroutine with context timeout.

func (*Helper) VerifyNextTargetEvent

func (h *Helper) VerifyNextTargetEvent(ctx context.Context, t *testing.T, targetKey string, wantEvent *event.Event)

VerifyNextTargetEvent verifies the next event the subscriber receives. If wantEvent is nil, then it means such an event is not expected. This function is blocking and should be invoked in a separate goroutine with context timeout.

func (*Helper) VerifyNextTargetEventAndDelayResp

func (h *Helper) VerifyNextTargetEventAndDelayResp(ctx context.Context, t *testing.T, targetKey string, wantEvent *event.Event, delay time.Duration)

VerifyNextTargetEventAndDelayResp verifies the next event the subscriber receives but not respond a success infinitely.

func (*Helper) VerifyNextTargetRetryEvent

func (h *Helper) VerifyNextTargetRetryEvent(ctx context.Context, t *testing.T, targetKey string, wantEvent *event.Event)

VerifyNextTargetRetryEvent verifies the next event the target retry queue receives. Calling this function will also ack the next event. If wantEvent is nil, then it means such an event is not expected. This function is blocking and should be invoked in a separate goroutine with context timeout.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL