Documentation ¶
Overview ¶
Package pstest provides a fake Cloud PubSub service for testing. It implements a simplified form of the service, suitable for unit tests. It may behave differently from the actual service in ways in which the service is non-deterministic or unspecified: timing, delivery order, etc.
This package is EXPERIMENTAL and is subject to change without notice.
See the example for usage.
Index ¶
- func ResetMinAckDeadline()
- func SetMinAckDeadline(n time.Duration)
- type GServer
- func (s *GServer) Acknowledge(_ context.Context, req *pb.AcknowledgeRequest) (*emptypb.Empty, error)
- func (s *GServer) CreateSubscription(_ context.Context, ps *pb.Subscription) (*pb.Subscription, error)
- func (s *GServer) CreateTopic(_ context.Context, t *pb.Topic) (*pb.Topic, error)
- func (s *GServer) DeleteSubscription(_ context.Context, req *pb.DeleteSubscriptionRequest) (*emptypb.Empty, error)
- func (s *GServer) DeleteTopic(_ context.Context, req *pb.DeleteTopicRequest) (*emptypb.Empty, error)
- func (s *GServer) GetSubscription(_ context.Context, req *pb.GetSubscriptionRequest) (*pb.Subscription, error)
- func (s *GServer) GetTopic(_ context.Context, req *pb.GetTopicRequest) (*pb.Topic, error)
- func (s *GServer) ListSubscriptions(_ context.Context, req *pb.ListSubscriptionsRequest) (*pb.ListSubscriptionsResponse, error)
- func (s *GServer) ListTopicSubscriptions(_ context.Context, req *pb.ListTopicSubscriptionsRequest) (*pb.ListTopicSubscriptionsResponse, error)
- func (s *GServer) ListTopics(_ context.Context, req *pb.ListTopicsRequest) (*pb.ListTopicsResponse, error)
- func (s *GServer) ModifyAckDeadline(_ context.Context, req *pb.ModifyAckDeadlineRequest) (*emptypb.Empty, error)
- func (s *GServer) Publish(_ context.Context, req *pb.PublishRequest) (*pb.PublishResponse, error)
- func (s *GServer) Pull(ctx context.Context, req *pb.PullRequest) (*pb.PullResponse, error)
- func (s *GServer) Seek(ctx context.Context, req *pb.SeekRequest) (*pb.SeekResponse, error)
- func (s *GServer) StreamingPull(sps pb.Subscriber_StreamingPullServer) error
- func (s *GServer) UpdateSubscription(_ context.Context, req *pb.UpdateSubscriptionRequest) (*pb.Subscription, error)
- func (s *GServer) UpdateTopic(_ context.Context, req *pb.UpdateTopicRequest) (*pb.Topic, error)
- type Message
- type Modack
- type Server
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ResetMinAckDeadline ¶ added in v0.26.0
func ResetMinAckDeadline()
ResetMinAckDeadline resets the minack deadline to the default.
func SetMinAckDeadline ¶ added in v0.26.0
SetMinAckDeadline changes the minack deadline to n. Must be greater than or equal to 1 second. Remember to reset this value to the default after your test changes it. Example usage:
pstest.SetMinAckDeadlineSecs(1) defer pstest.ResetMinAckDeadlineSecs()
Types ¶
type GServer ¶ added in v0.35.0
type GServer struct { pb.PublisherServer pb.SubscriberServer // contains filtered or unexported fields }
GServer is the underlying service implementor. It is not intended to be used directly.
func (*GServer) Acknowledge ¶ added in v0.35.0
func (*GServer) CreateSubscription ¶ added in v0.35.0
func (s *GServer) CreateSubscription(_ context.Context, ps *pb.Subscription) (*pb.Subscription, error)
func (*GServer) CreateTopic ¶ added in v0.35.0
func (*GServer) DeleteSubscription ¶ added in v0.35.0
func (*GServer) DeleteTopic ¶ added in v0.35.0
func (*GServer) GetSubscription ¶ added in v0.35.0
func (s *GServer) GetSubscription(_ context.Context, req *pb.GetSubscriptionRequest) (*pb.Subscription, error)
func (*GServer) ListSubscriptions ¶ added in v0.35.0
func (s *GServer) ListSubscriptions(_ context.Context, req *pb.ListSubscriptionsRequest) (*pb.ListSubscriptionsResponse, error)
func (*GServer) ListTopicSubscriptions ¶ added in v0.35.0
func (s *GServer) ListTopicSubscriptions(_ context.Context, req *pb.ListTopicSubscriptionsRequest) (*pb.ListTopicSubscriptionsResponse, error)
func (*GServer) ListTopics ¶ added in v0.35.0
func (s *GServer) ListTopics(_ context.Context, req *pb.ListTopicsRequest) (*pb.ListTopicsResponse, error)
func (*GServer) ModifyAckDeadline ¶ added in v0.35.0
func (*GServer) Publish ¶ added in v0.35.0
func (s *GServer) Publish(_ context.Context, req *pb.PublishRequest) (*pb.PublishResponse, error)
func (*GServer) Pull ¶ added in v0.35.0
func (s *GServer) Pull(ctx context.Context, req *pb.PullRequest) (*pb.PullResponse, error)
func (*GServer) Seek ¶ added in v0.35.0
func (s *GServer) Seek(ctx context.Context, req *pb.SeekRequest) (*pb.SeekResponse, error)
func (*GServer) StreamingPull ¶ added in v0.35.0
func (s *GServer) StreamingPull(sps pb.Subscriber_StreamingPullServer) error
func (*GServer) UpdateSubscription ¶ added in v0.35.0
func (s *GServer) UpdateSubscription(_ context.Context, req *pb.UpdateSubscriptionRequest) (*pb.Subscription, error)
func (*GServer) UpdateTopic ¶ added in v0.35.0
type Message ¶
type Message struct { ID string Data []byte Attributes map[string]string PublishTime time.Time Deliveries int // number of times delivery of the message was attempted Acks int // number of acks received from clients Modacks []Modack // modacks received by server for this message // contains filtered or unexported fields }
A Message is a message that was published to the server.
type Server ¶
type Server struct { Addr string // The address that the server is listening on. GServer GServer // Not intended to be used directly. // contains filtered or unexported fields }
Server is a fake Pub/Sub server.
func NewServer ¶
func NewServer() *Server
NewServer creates a new fake server running in the current process.
Example ¶
package main import ( "context" "cloud.google.com/go/pubsub" "cloud.google.com/go/pubsub/pstest" "google.golang.org/api/option" "google.golang.org/grpc" ) func main() { ctx := context.Background() // Start a fake server running locally. srv := pstest.NewServer() defer srv.Close() // Connect to the server without using TLS. conn, err := grpc.Dial(srv.Addr, grpc.WithInsecure()) if err != nil { // TODO: Handle error. } defer conn.Close() // Use the connection when creating a pubsub client. client, err := pubsub.NewClient(ctx, "project", option.WithGRPCConn(conn)) if err != nil { // TODO: Handle error. } defer client.Close() _ = client // TODO: Use the client. }
Output:
func (*Server) Message ¶
Message returns the message with the given ID, or nil if no message with that ID was published.
func (*Server) Publish ¶
Publish behaves as if the Publish RPC was called with a message with the given data and attrs. It returns the ID of the message. The topic will be created if it doesn't exist.
Publish panics if there is an error, which is appropriate for testing.
func (*Server) SetStreamTimeout ¶
SetStreamTimeout sets the amount of time a stream will be active before it shuts itself down. This mimics the real service's behavior of closing streams after 30 minutes. If SetStreamTimeout is never called or is passed zero, streams never shut down.