callback

package
v0.0.0-...-71aaf32 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActiveChannel

type ActiveChannel struct {
	*PassiveChannel
	// contains filtered or unexported fields
}

func NewActiveChannel

func NewActiveChannel(timeout time.Duration) *ActiveChannel

NewActiveChannel returns a channel which can receive and modify callback responses. The timeout controls how long Recv() and Send() can wait for callback data before failing.

Channels are useful when tests want to manipulate callbacks from within an `inner` function.

func (*ActiveChannel) Callback

func (c *ActiveChannel) Callback() Fn

Callback returns the callback implementation used to send data to this channel.

func (*ActiveChannel) Send

func (c *ActiveChannel) Send(t ct.TestLike, res *Response)

Send a callback response to this channel. Fails the test if the response cannot be put into the channel for $timeout time.

type CallbackServer

type CallbackServer struct {
	// contains filtered or unexported fields
}

func NewCallbackServer

func NewCallbackServer(t ct.TestLike, hostnameRunningComplement string) (*CallbackServer, error)

NewCallbackServer runs a local HTTP server that can read callbacks from mitmproxy. Automatically listens on a high numbered port. Must be Close()d at the end of the test. Register callback handlers via CallbackServer.SetOnRequestCallback and CallbackServer.SetOnResponseCallback

func (*CallbackServer) Close

func (s *CallbackServer) Close()

Shut down the server.

func (*CallbackServer) SetOnRequestCallback

func (s *CallbackServer) SetOnRequestCallback(t ct.TestLike, cb Fn) (callbackURL string)

func (*CallbackServer) SetOnResponseCallback

func (s *CallbackServer) SetOnResponseCallback(t ct.TestLike, cb Fn) (callbackURL string)

type Data

type Data struct {
	Method       string          `json:"method"`
	URL          string          `json:"url"`
	AccessToken  string          `json:"access_token"`
	ResponseCode int             `json:"response_code"`
	ResponseBody json.RawMessage `json:"response_body"`
	RequestBody  json.RawMessage `json:"request_body"`
}

func (Data) String

func (cd Data) String() string

type Fn

type Fn func(Data) *Response

Fn represents the callback function to invoke

func SendError

func SendError(count uint32, statusCode int) Fn

SendError returns a callback.Fn which returns the provided statusCode along with a JSON error $count times, after which it lets the response pass through. This is useful for testing retries. If count=0, always send an error response.

type PassiveChannel

type PassiveChannel struct {
	// contains filtered or unexported fields
}

func NewPassiveChannel

func NewPassiveChannel(timeout time.Duration, blocking bool) *PassiveChannel

NewPassiveChannel returns a channel which can receive callback responses, but cannot modify them. This is useful for sniffing network traffic. The timeout controls how long Recv() can wait until there is callback data before failing. If blocking is true, callbacks will not return until Recv() is called. This can be useful for synchronising actions when a callback is invoked.

Channels are useful when tests want to manipulate callbacks from within an `inner` function.

func (*PassiveChannel) Callback

func (c *PassiveChannel) Callback() Fn

Callback returns the callback implementation used to send data to this channel.

func (*PassiveChannel) Chan

func (c *PassiveChannel) Chan() <-chan *Data

Chan returns a consume-only channel.

This exists as an escape hatch for when Recv/TryRecv are insufficient, and this channel needs to be used as part of a larger `select` block.

func (*PassiveChannel) Close

func (c *PassiveChannel) Close()

func (*PassiveChannel) Recv

func (c *PassiveChannel) Recv(t ct.TestLike, msg string, args ...any) *Data

Block until this channel receives a callback.

func (*PassiveChannel) TryRecv

func (c *PassiveChannel) TryRecv(t ct.TestLike) *Data

Try to receive from the channel. Does not block. Returns nil if there is nothing waiting in the channel. Useful for detecting absence of a callback.

type Response

type Response struct {
	// if set, changes the HTTP response status code for this request.
	RespondStatusCode int `json:"respond_status_code,omitempty"`
	// if set, changes the HTTP response body for this request.
	RespondBody json.RawMessage `json:"respond_body,omitempty"`
}

Jump to

Keyboard shortcuts

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