mocks

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMutableClock added in v0.11.0

func NewMutableClock() (rate.Clock, func(time.Time))

NewMutableClock returns MockClock and function to set time of the clock at runtime.

Types

type BodyUnmarshalerMock added in v0.12.0

type BodyUnmarshalerMock struct {
	OnUnmarshal func(r *http.Response, v any) error
}

func (BodyUnmarshalerMock) Unmarshal added in v0.12.0

func (m BodyUnmarshalerMock) Unmarshal(r *http.Response, v any) error

type BurstLimiterMock added in v0.7.0

type BurstLimiterMock struct {
	rate.Limiter

	OnBurst func() uint64
	OnTakeN func(ctx context.Context, n uint64) (rate.Token, error)
}

func (BurstLimiterMock) Burst added in v0.7.0

func (m BurstLimiterMock) Burst() uint64

func (BurstLimiterMock) TakeN added in v0.7.0

func (m BurstLimiterMock) TakeN(ctx context.Context, n uint64) (rate.Token, error)

type BurstReservationLimiterMock added in v0.11.0

type BurstReservationLimiterMock struct {
	rate.BurstLimiter

	OnReserve  func(ctx context.Context) (rate.CancellableToken, error)
	OnReserveN func(ctx context.Context, n uint64) (rate.CancellableToken, error)
}

func (BurstReservationLimiterMock) Reserve added in v0.11.0

func (BurstReservationLimiterMock) ReserveN added in v0.11.0

type ByteIOFormatterMock added in v0.10.0

type ByteIOFormatterMock struct {
	OnMarshal       func(v any) ([]byte, error)
	OnUnmarshal     func(data []byte, v any) error
	OnMarshalTo     func(w io.Writer, v any) error
	OnUnmarshalFrom func(r io.Reader, v any) error
}

func (ByteIOFormatterMock) Marshal added in v0.10.0

func (m ByteIOFormatterMock) Marshal(v any) ([]byte, error)

func (ByteIOFormatterMock) MarshalTo added in v0.10.0

func (m ByteIOFormatterMock) MarshalTo(w io.Writer, v any) error

func (ByteIOFormatterMock) Unmarshal added in v0.10.0

func (m ByteIOFormatterMock) Unmarshal(data []byte, v any) error

func (ByteIOFormatterMock) UnmarshalFrom added in v0.10.0

func (m ByteIOFormatterMock) UnmarshalFrom(r io.Reader, v any) error

type CacheMock added in v0.8.0

type CacheMock struct {
	OnDelete func(key string) error
	OnGet    func(key string, v interface{}) error
	OnSet    func(key string, value interface{}, ttl time.Duration) error
}

func (CacheMock) Delete added in v0.8.0

func (m CacheMock) Delete(key string) error

func (CacheMock) Get added in v0.8.0

func (m CacheMock) Get(key string, v interface{}) error

func (CacheMock) Set added in v0.8.0

func (m CacheMock) Set(key string, value interface{}, ttl time.Duration) error

type ClientMock added in v0.8.0

type ClientMock struct {
	OnClose    func()
	OnDelete   func(ctx context.Context, url string) (*http.Response, error)
	OnGet      func(ctx context.Context, url string) (*http.Response, error)
	OnPost     func(ctx context.Context, url string, body io.Reader) (*http.Response, error)
	OnPostForm func(ctx context.Context, url string, form url.Values) (*http.Response, error)
	OnPut      func(ctx context.Context, url string, body io.Reader) (*http.Response, error)
	OnSend     func(ctx context.Context, req *http.Request) (*http.Response, error)
}

func (ClientMock) Close added in v0.8.0

func (m ClientMock) Close()

func (ClientMock) Delete added in v0.8.0

func (m ClientMock) Delete(ctx context.Context, url string) (*http.Response, error)

func (ClientMock) Get added in v0.8.0

func (m ClientMock) Get(ctx context.Context, url string) (*http.Response, error)

func (ClientMock) Post added in v0.8.0

func (m ClientMock) Post(ctx context.Context, url string, body io.Reader) (*http.Response, error)

func (ClientMock) PostForm added in v0.8.0

func (m ClientMock) PostForm(ctx context.Context, url string, form url.Values) (*http.Response, error)

func (ClientMock) Put added in v0.8.0

func (m ClientMock) Put(ctx context.Context, url string, body io.Reader) (*http.Response, error)

func (ClientMock) Send added in v0.8.0

func (m ClientMock) Send(ctx context.Context, req *http.Request) (*http.Response, error)

type CookiesJar added in v0.4.0

type CookiesJar struct {
	OnSetCookies func(u *url.URL, cookies []*http.Cookie)
	OnCookies    func(u *url.URL) []*http.Cookie
}

func (*CookiesJar) Cookies added in v0.4.0

func (m *CookiesJar) Cookies(u *url.URL) []*http.Cookie

func (*CookiesJar) SetCookies added in v0.4.0

func (m *CookiesJar) SetCookies(u *url.URL, cookies []*http.Cookie)

type DiCacheMock added in v0.8.0

type DiCacheMock struct {
	OnGet func(l di.LifeTime, t reflect.Type) (interface{}, bool)
	OnPut func(l di.LifeTime, t reflect.Type, v interface{}) bool
}

func (DiCacheMock) Get added in v0.8.0

func (m DiCacheMock) Get(l di.LifeTime, t reflect.Type) (interface{}, bool)

func (DiCacheMock) Put added in v0.8.0

func (m DiCacheMock) Put(l di.LifeTime, t reflect.Type, v interface{}) bool

type DistributedCacheMock added in v0.8.0

type DistributedCacheMock struct {
	OnDelete func(ctx context.Context, key string) error
	OnGet    func(ctx context.Context, key string, v interface{}) error
	OnSet    func(ctx context.Context, key string, value interface{}, ttl time.Duration) error
}

func (DistributedCacheMock) Delete added in v0.8.0

func (m DistributedCacheMock) Delete(ctx context.Context, key string) error

func (DistributedCacheMock) Get added in v0.8.0

func (m DistributedCacheMock) Get(ctx context.Context, key string, v interface{}) error

func (DistributedCacheMock) Set added in v0.8.0

func (m DistributedCacheMock) Set(ctx context.Context, key string, value interface{}, ttl time.Duration) error

type FormatterMock added in v0.8.0

type FormatterMock struct {
	OnFormat func(msg string, fields logf.Fields) string
}

func (FormatterMock) Format added in v0.8.0

func (m FormatterMock) Format(msg string, fields logf.Fields) string

type HttpfResponseWriterMock added in v0.8.0

type HttpfResponseWriterMock struct {
	OnHeader      func() http.Header
	OnWrite       func(data []byte) (int, error)
	OnWriteHeader func(statusCode int)
	OnResponse    func(code int, data interface{}) error
}

func (HttpfResponseWriterMock) Header added in v0.8.0

func (m HttpfResponseWriterMock) Header() http.Header

func (HttpfResponseWriterMock) Response added in v0.8.0

func (m HttpfResponseWriterMock) Response(code int, data interface{}) error

func (HttpfResponseWriterMock) Write added in v0.8.0

func (m HttpfResponseWriterMock) Write(data []byte) (int, error)

func (HttpfResponseWriterMock) WriteHeader added in v0.8.0

func (m HttpfResponseWriterMock) WriteHeader(statusCode int)

type LimiterMock added in v0.7.0

type LimiterMock struct {
	OnLimit  func() uint64
	OnTokens func(ctx context.Context) (uint64, error)
	OnTake   func(ctx context.Context) (rate.Token, error)
}

func (LimiterMock) Limit added in v0.7.0

func (m LimiterMock) Limit() uint64

func (LimiterMock) Take added in v0.7.0

func (m LimiterMock) Take(ctx context.Context) (rate.Token, error)

func (LimiterMock) Tokens added in v0.7.0

func (m LimiterMock) Tokens(ctx context.Context) (uint64, error)

type LimiterStoreMock added in v0.7.0

type LimiterStoreMock struct {
	OnLimit func(ctx context.Context, key string) (rate.Limiter, error)
}

func (LimiterStoreMock) Limit added in v0.7.0

func (m LimiterStoreMock) Limit(ctx context.Context, key string) (rate.Limiter, error)

type LoggerMock added in v0.8.0

type LoggerMock struct {
	OnDebug     func(v interface{})
	OnDebugf    func(format string, args ...any)
	OnError     func(v interface{})
	OnErrorf    func(format string, args ...any)
	OnFormatter func() logf.Formatter
	OnInfo      func(v interface{})
	OnInfof     func(format string, args ...any)
	OnOutput    func() io.Writer
	OnScope     func() logf.Fields
}

func (LoggerMock) Debug added in v0.8.0

func (m LoggerMock) Debug(v interface{})

func (LoggerMock) Debugf added in v0.8.0

func (m LoggerMock) Debugf(format string, args ...any)

func (LoggerMock) Error added in v0.8.0

func (m LoggerMock) Error(v interface{})

func (LoggerMock) Errorf added in v0.8.0

func (m LoggerMock) Errorf(format string, args ...any)

func (LoggerMock) Formatter added in v0.8.0

func (m LoggerMock) Formatter() logf.Formatter

func (LoggerMock) Info added in v0.8.0

func (m LoggerMock) Info(v interface{})

func (LoggerMock) Infof added in v0.8.0

func (m LoggerMock) Infof(format string, args ...any)

func (LoggerMock) Output added in v0.8.0

func (m LoggerMock) Output() io.Writer

func (LoggerMock) Scope added in v0.8.0

func (m LoggerMock) Scope() logf.Fields

type MockClock added in v0.11.0

type MockClock struct {
	NowFunc func() time.Time
}

func (MockClock) Now added in v0.11.0

func (c MockClock) Now() time.Time

type ParamsParserMock added in v0.8.0

type ParamsParserMock struct {
	OnParseParams func(r *http.Request) map[string]string
}

func (ParamsParserMock) ParseParams added in v0.8.0

func (m ParamsParserMock) ParseParams(r *http.Request) map[string]string

type ProviderMock added in v0.8.0

type ProviderMock struct {
	OnLoad func(ctx context.Context, v any, opts ...config.LoadOption) error
}

func (ProviderMock) Load added in v0.8.0

func (m ProviderMock) Load(ctx context.Context, v any, opts ...config.LoadOption) error

type ReservationLimiterMock added in v0.11.0

type ReservationLimiterMock struct {
	rate.Limiter

	OnReserve func(ctx context.Context) (rate.CancellableToken, error)
}

func (ReservationLimiterMock) Reserve added in v0.11.0

type ResponseWriter added in v0.4.0

type ResponseWriter struct {
	OnHeader      func() http.Header
	OnWrite       func([]byte) (int, error)
	OnWriteHeader func(int)
	OnResponse    func(int, interface{}) error
}

func (*ResponseWriter) Header added in v0.4.0

func (m *ResponseWriter) Header() http.Header

func (*ResponseWriter) Response added in v0.4.0

func (m *ResponseWriter) Response(code int, data interface{}) error

func (*ResponseWriter) Write added in v0.4.0

func (m *ResponseWriter) Write(b []byte) (int, error)

func (*ResponseWriter) WriteHeader added in v0.4.0

func (m *ResponseWriter) WriteHeader(statusCode int)

type RetryPolicyMock added in v0.8.0

type RetryPolicyMock struct {
	OnExecute func(ctx context.Context, fn func() error) error
}

func (RetryPolicyMock) Execute added in v0.8.0

func (m RetryPolicyMock) Execute(ctx context.Context, fn func() error) error

type RoundTripper added in v0.4.0

type RoundTripper struct {
	OnRoundTrip func(*http.Request) (*http.Response, error)
}

func (*RoundTripper) RoundTrip added in v0.4.0

func (m *RoundTripper) RoundTrip(r *http.Request) (*http.Response, error)

type RouteBuilderMock added in v0.8.0

type RouteBuilderMock struct {
	OnBuild               func() httpf.Router
	OnDelete              func(pattern string, handler httpf.Handler) httpf.RouteBuilder
	OnGet                 func(pattern string, handler httpf.Handler) httpf.RouteBuilder
	OnOptions             func(pattern string, handler httpf.Handler) httpf.RouteBuilder
	OnPatch               func(pattern string, handler httpf.Handler) httpf.RouteBuilder
	OnPost                func(pattern string, handler httpf.Handler) httpf.RouteBuilder
	OnPut                 func(pattern string, handler httpf.Handler) httpf.RouteBuilder
	OnWithErrorHandler    func(handler httpf.ErrorHandler) httpf.RouteBuilder
	OnWithParamsParser    func(parser httpf.ParamsParser) httpf.RouteBuilder
	OnWithWriterDecorator func(decorator func(http.ResponseWriter) httpf.ResponseWriter) httpf.RouteBuilder
}

func (RouteBuilderMock) Build added in v0.8.0

func (m RouteBuilderMock) Build() httpf.Router

func (RouteBuilderMock) Delete added in v0.8.0

func (m RouteBuilderMock) Delete(pattern string, handler httpf.Handler) httpf.RouteBuilder

func (RouteBuilderMock) Get added in v0.8.0

func (m RouteBuilderMock) Get(pattern string, handler httpf.Handler) httpf.RouteBuilder

func (RouteBuilderMock) Options added in v0.8.0

func (m RouteBuilderMock) Options(pattern string, handler httpf.Handler) httpf.RouteBuilder

func (RouteBuilderMock) Patch added in v0.8.0

func (m RouteBuilderMock) Patch(pattern string, handler httpf.Handler) httpf.RouteBuilder

func (RouteBuilderMock) Post added in v0.8.0

func (m RouteBuilderMock) Post(pattern string, handler httpf.Handler) httpf.RouteBuilder

func (RouteBuilderMock) Put added in v0.8.0

func (m RouteBuilderMock) Put(pattern string, handler httpf.Handler) httpf.RouteBuilder

func (RouteBuilderMock) WithErrorHandler added in v0.8.0

func (m RouteBuilderMock) WithErrorHandler(handler httpf.ErrorHandler) httpf.RouteBuilder

func (RouteBuilderMock) WithParamsParser added in v0.8.0

func (m RouteBuilderMock) WithParamsParser(parser httpf.ParamsParser) httpf.RouteBuilder

func (RouteBuilderMock) WithWriterDecorator added in v0.8.0

func (m RouteBuilderMock) WithWriterDecorator(decorator func(http.ResponseWriter) httpf.ResponseWriter) httpf.RouteBuilder

type RouterMock added in v0.8.0

type RouterMock struct {
	OnServeHTTP func(http.ResponseWriter, *http.Request)
	OnHandle    func(pattern string, handler http.Handler)
}

func (RouterMock) Handle added in v0.8.0

func (m RouterMock) Handle(pattern string, handler http.Handler)

func (RouterMock) ServeHTTP added in v0.8.0

func (m RouterMock) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ServerMock added in v0.8.0

type ServerMock struct {
	OnClose              func() error
	OnListenAndServe     func() error
	OnListenAndServeTLS  func(certFile string, keyFile string) error
	OnRegisterOnShutdown func(f func())
	OnServe              func(l net.Listener) error
	OnServeTLS           func(l net.Listener, certFile string, keyFile string) error
	OnShutdown           func(ctx context.Context) error
}

func (ServerMock) Close added in v0.8.0

func (m ServerMock) Close() error

func (ServerMock) ListenAndServe added in v0.8.0

func (m ServerMock) ListenAndServe() error

func (ServerMock) ListenAndServeTLS added in v0.8.0

func (m ServerMock) ListenAndServeTLS(certFile string, keyFile string) error

func (ServerMock) RegisterOnShutdown added in v0.8.0

func (m ServerMock) RegisterOnShutdown(f func())

func (ServerMock) Serve added in v0.8.0

func (m ServerMock) Serve(l net.Listener) error

func (ServerMock) ServeTLS added in v0.8.0

func (m ServerMock) ServeTLS(l net.Listener, certFile string, keyFile string) error

func (ServerMock) Shutdown added in v0.8.0

func (m ServerMock) Shutdown(ctx context.Context) error

type Stringer

type Stringer struct {
	Value string
}

func (Stringer) GoString

func (m Stringer) GoString() string

func (Stringer) String

func (m Stringer) String() string

type TokenMock added in v0.7.0

type TokenMock struct {
	OnAllow    func() bool
	OnResetsAt func() time.Time
	OnUse      func() error
	OnCancel   func()
	OnContext  func() context.Context
}

func (TokenMock) Allow added in v0.7.0

func (m TokenMock) Allow() bool

func (TokenMock) Cancel added in v0.7.0

func (m TokenMock) Cancel()

func (TokenMock) Context added in v0.11.0

func (m TokenMock) Context() context.Context

func (TokenMock) ResetsAt added in v0.7.0

func (m TokenMock) ResetsAt() time.Time

func (TokenMock) Use added in v0.7.0

func (m TokenMock) Use() error

type Writer

type Writer struct {
	OnWrite func(p []byte) (n int, err error)
}

func NewWriterMock

func NewWriterMock(writeFn func(p []byte) (n int, err error)) *Writer

func (*Writer) Write

func (m *Writer) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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