mockcoreserver

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const Endless = -1

Endless ...

Variables

This section is empty.

Functions

This section is empty.

Types

type Call

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

Call is a call expectation structure

func (*Call) Expect

func (c *Call) Expect(fn ExpectFunc) *Call

Expect sets an expectation on a request

func (*Call) Forever

func (c *Call) Forever() *Call

Forever do not use number expected calls for a mock

func (*Call) Once

func (c *Call) Once() *Call

Once sets only one expected call

func (*Call) Respond

func (c *Call) Respond(opts ...HandlerOptionFunc) *Call

Respond sets a response by a request

func (*Call) Times

func (c *Call) Times(cnt int) *Call

Times sets the expected number of calls

type CoreServer

CoreServer is an interface of a mock core-server

type ExpectFunc

type ExpectFunc func(req *http.Request) error

func And

func And(fns ...ExpectFunc) ExpectFunc

And ...

func BodyShouldBeEmpty

func BodyShouldBeEmpty() ExpectFunc

BodyShouldBeEmpty expects that a request body should be empty

func BodyShouldBeSame

func BodyShouldBeSame(v interface{}) ExpectFunc

BodyShouldBeSame compares a body from received request and passed byte slice

func Debug

func Debug() ExpectFunc

Debug is a debug JRPC request handler

func JRPCParamsEmpty

func JRPCParamsEmpty() ExpectFunc

JRPCParamsEmpty is a request expectation of empty JRPC params

func JRPCRequest

func JRPCRequest(fns ...func(ctx context.Context, req btcjson.Request) error) ExpectFunc

JRPCRequest transforms http.Request into btcjson.Request and executes passed list of functions

func QueryShouldHave

func QueryShouldHave(expectedVales url.Values) ExpectFunc

QueryShouldHave expects that a request query values should match on passed values

type HTTPServer

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

HTTPServer is a mock http server the idea is to use this server in a test flow to check requests and passed response

func NewHTTPServer

func NewHTTPServer(addr string) *HTTPServer

NewHTTPServer returns a mock http server

func (*HTTPServer) On

func (s *HTTPServer) On(pattern string) *Call

On returns a call structure to setup afterwards

func (*HTTPServer) Start

func (s *HTTPServer) Start()

Start listens and serves http requests

func (*HTTPServer) Stop

func (s *HTTPServer) Stop(ctx context.Context)

Stop stops http server

func (*HTTPServer) WaitReady

func (s *HTTPServer) WaitReady()

WaitReady waits a signal in a channel that a server is ready

type HandlerFunc

type HandlerFunc func(w http.ResponseWriter, req *http.Request) error

type HandlerOptionFunc

type HandlerOptionFunc func(opt *respOption, req *http.Request) error

func Body

func Body(body []byte) HandlerOptionFunc

Body ...

func ContentType

func ContentType(val string) HandlerOptionFunc

ContentType ...

func Header(key string, values ...string) HandlerOptionFunc

Header ...

func JRPCResult

func JRPCResult(v interface{}) HandlerOptionFunc

JRPCResult ..

func JSONBody

func JSONBody(v interface{}) HandlerOptionFunc

JSONBody ...

func JSONContentType

func JSONContentType() HandlerOptionFunc

JSONContentType ...

func OnMethod

func OnMethod(fn func(ctx context.Context, req btcjson.Request) (interface{}, error)) HandlerOptionFunc

OnMethod ...

type JRPCServer

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

JRPCServer is a mock JRPC server implementation

func NewJRPCServer

func NewJRPCServer(addr, endpointURL string) *JRPCServer

NewJRPCServer creates and returns a new mock of JRPC server

func WithMethods

func WithMethods(srv *JRPCServer, methods ...func(srv *JRPCServer)) *JRPCServer

WithMethods ...

func (*JRPCServer) On

func (s *JRPCServer) On(pattern string) *Call

On ...

func (*JRPCServer) Start

func (s *JRPCServer) Start()

Start starts listening and handling JRPC requests

func (*JRPCServer) Stop

func (s *JRPCServer) Stop(ctx context.Context)

Stop ...

type MethodFunc

type MethodFunc func(srv *JRPCServer)

MethodFunc ...

func WithGetNetworkInfoMethod

func WithGetNetworkInfoMethod(cs CoreServer, times int) MethodFunc

WithGetNetworkInfoMethod ...

func WithMasternodeMethod

func WithMasternodeMethod(cs CoreServer, times int) MethodFunc

WithMasternodeMethod ...

func WithPingMethod

func WithPingMethod(cs CoreServer, times int) MethodFunc

WithPingMethod ...

func WithQuorumInfoMethod

func WithQuorumInfoMethod(cs CoreServer, times int) MethodFunc

WithQuorumInfoMethod ...

func WithQuorumSignMethod

func WithQuorumSignMethod(cs CoreServer, times int, quorumType btcjson.LLMQType) MethodFunc

WithQuorumSignMethod ...

func WithQuorumVerifyMethod

func WithQuorumVerifyMethod(cs CoreServer, times int) MethodFunc

WithQuorumVerifyMethod ...

type MockCoreServer

type MockCoreServer struct {
	ChainID  string
	LLMQType btcjson.LLMQType
	FilePV   *privval.FilePV
}

MockCoreServer is an implementation of a mock core-server

func (*MockCoreServer) GetNetworkInfo

GetNetworkInfo returns network-info result

func (*MockCoreServer) MasternodeStatus

MasternodeStatus returns a masternode-status result

func (*MockCoreServer) Ping

Ping ...

func (*MockCoreServer) QuorumInfo

QuorumInfo returns a quorum-info result

func (*MockCoreServer) QuorumSign

QuorumSign returns a quorum-sign result

func (*MockCoreServer) QuorumVerify

QuorumVerify returns a quorum-verify result

type MockServer

type MockServer interface {
	Start()
	Stop(ctx context.Context)
	On(pattern string) *Call
}

MockServer ...

type StaticCoreServer

type StaticCoreServer struct {
	QuorumInfoResult       btcjson.QuorumInfoResult
	QuorumSignResult       btcjson.QuorumSignResult
	QuorumVerifyResult     btcjson.QuorumVerifyResult
	MasternodeStatusResult btcjson.MasternodeStatusResult
	GetNetworkInfoResult   btcjson.GetNetworkInfoResult
}

StaticCoreServer is a mock of core-server with static result data

func (*StaticCoreServer) GetNetworkInfo

GetNetworkInfo returns constant network-info result

func (*StaticCoreServer) MasternodeStatus

MasternodeStatus returns constant masternode-status result

func (*StaticCoreServer) Ping

Ping ...

func (*StaticCoreServer) QuorumInfo

QuorumInfo returns constant quorum-info result

func (*StaticCoreServer) QuorumSign

QuorumSign returns constant quorum-sign result

func (*StaticCoreServer) QuorumVerify

QuorumVerify returns constant quorum-sign result

Jump to

Keyboard shortcuts

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