events

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package events implements event listeners for mocha internal actions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Emitter

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

Emitter implements a event listener, subscriber and emitter.

func NewEmitter

func NewEmitter(ctx context.Context) *Emitter

NewEmitter creates an Emitter instance.

func (*Emitter) Emit

func (h *Emitter) Emit(data any)

Emit dispatches a new event. Parameter data must be: - OnRequest - OnRequestMatch - OnRequestNotMatched - OnError

func (*Emitter) Subscribe

func (h *Emitter) Subscribe(evt Events)

Subscribe subscribes new event handlers.

type Events

type Events interface {
	OnRequest(OnRequest)
	OnRequestMatched(OnRequestMatch)
	OnRequestNotMatched(OnRequestNotMatched)
	OnError(OnError)
}

Events interface defines available event handlers.

type InternalEvents

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

InternalEvents implements default event handlers that logs event information.

func NewInternalEvents

func NewInternalEvents(l Logger) *InternalEvents

NewInternalEvents creates an internal event handlers.

func (*InternalEvents) OnError

func (h *InternalEvents) OnError(e OnError)

func (*InternalEvents) OnRequest

func (h *InternalEvents) OnRequest(e OnRequest)

func (*InternalEvents) OnRequestMatched added in v1.1.0

func (h *InternalEvents) OnRequestMatched(e OnRequestMatch)

func (*InternalEvents) OnRequestNotMatched

func (h *InternalEvents) OnRequestNotMatched(e OnRequestNotMatched)

type Logger

type Logger interface {
	Logf(string, ...any)
}

Logger defines internal events logger contract.

type Mock

type Mock struct {
	ID   int
	Name string
}

Mock defines core.Mock information to be logged.

type OnError

type OnError struct {
	Request Request
	Err     error
}

OnError event is triggered when an error occurs during request matching.

type OnRequest

type OnRequest struct {
	Request   Request
	StartedAt time.Time
}

OnRequest event is triggered every time a request arrives at the mock handler.

type OnRequestMatch

type OnRequestMatch struct {
	Request            Request
	ResponseDefinition Response
	Mock               Mock
	Elapsed            time.Duration
}

OnRequestMatch event is triggered when a mock is found for a request.

type OnRequestNotMatched

type OnRequestNotMatched struct {
	Request Request
	Result  Result
}

OnRequestNotMatched event is triggered when no mocks are found for a request.

type Request

type Request struct {
	Method     string
	Path       string
	RequestURI string
	Host       string
	Header     http.Header
}

Request defines information from http.Request to be logged.

func FromRequest

func FromRequest(r *http.Request) Request

FromRequest is a helper function that creates a new Request from a http.Request.

type Response

type Response struct {
	Status int
	Header http.Header
}

Response defines HTTP Response information to be logged.

type Result

type Result struct {
	HasClosestMatch bool
	ClosestMatch    Mock
	Details         []ResultDetail
}

Result defines matching result to be logged.

type ResultDetail

type ResultDetail struct {
	Name        string
	Target      string
	Description string
}

ResultDetail defines matching result details to be logged.

Jump to

Keyboard shortcuts

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