...

Source file src/edge-infra.dev/test/f2/x/pstest/options.go

Documentation: edge-infra.dev/test/f2/x/pstest

     1  package pstest
     2  
     3  import "time"
     4  
     5  // PubSub Options
     6  
     7  type PubSubOption func(*pubsuboptions)
     8  
     9  type pubsuboptions struct {
    10  	// disableTeardown (maybe?)
    11  	port      int
    12  	projectID string
    13  }
    14  
    15  func makePubSubOptions(opts ...PubSubOption) *pubsuboptions {
    16  	options := &pubsuboptions{}
    17  	for _, o := range opts {
    18  		o(options)
    19  	}
    20  	return options
    21  }
    22  
    23  // By default, pstest will connect the server to a random free port.
    24  // Ensure the port set here isn't already being used.
    25  func WithFixedPort(port int) PubSubOption {
    26  	return func(o *pubsuboptions) {
    27  		o.port = port
    28  	}
    29  }
    30  
    31  // Make sure that if you use PubSub struct methods, topics and subscriptions created match this project ID.
    32  func WithProjectID(id string) PubSubOption {
    33  	return func(o *pubsuboptions) {
    34  		o.projectID = id
    35  	}
    36  }
    37  
    38  // Subscription Options
    39  
    40  type SubOption func(*suboptions)
    41  
    42  type suboptions struct {
    43  	filter           string
    44  	ackDeadline      time.Duration
    45  	expirationPolicy time.Duration
    46  }
    47  
    48  func makeSubOptions(opts ...SubOption) *suboptions {
    49  	options := &suboptions{}
    50  	for _, o := range opts {
    51  		o(options)
    52  	}
    53  	return options
    54  }
    55  
    56  func WithFilter(filter string) SubOption {
    57  	return func(o *suboptions) {
    58  		o.filter = filter
    59  	}
    60  }
    61  
    62  func WithAckDeadline(ackDeadline time.Duration) SubOption {
    63  	return func(o *suboptions) {
    64  		o.ackDeadline = ackDeadline
    65  	}
    66  }
    67  
    68  func WithExpirationPolicy(expirationPolicy time.Duration) SubOption {
    69  	return func(o *suboptions) {
    70  		o.expirationPolicy = expirationPolicy
    71  	}
    72  }
    73  

View as plain text