Documentation ¶
Overview ¶
Package fake provides fake implementations for interfaces commonly used in the repository. The implementations offer configuration to return errors when it is needed by the unit test and it is also possible to record the call of functions of an object in some cases.
Index ¶
- Constants
- func CheckLog(msg string) (zerolog.Logger, func(t *testing.T))
- func Err(msg string) string
- func GetError() error
- func GetFakeFormatValue() []byte
- func GetTracerForAddrEmpty(_ string) (opentracing.Tracer, error)
- func GetTracerForAddrWithError(addr string) (opentracing.Tracer, error)
- func MakeCertificate(t *testing.T, ips ...net.IP) []byte
- func MakeCertificateChain(t *testing.T) []byte
- func MakeFullCertificate(t *testing.T) (*tls.Certificate, []byte)
- func NewBadContext() serde.Context
- func NewBadContextWithDelay(delay int) serde.Context
- func NewContext() serde.Context
- func NewContextWithFormat(f serde.Format) serde.Context
- func NewMsgContext() serde.Context
- func NewSigner() crypto.Signer
- func WaitLog(msg string, t time.Duration) (zerolog.Logger, func(t *testing.T))
- type Address
- type AddressFactory
- type AddressIterator
- type Bucket
- type Call
- type CollectiveAuthority
- func (ca CollectiveAuthority) AddressIterator() mino.AddressIterator
- func (ca CollectiveAuthority) GetAddress(index int) mino.Address
- func (ca CollectiveAuthority) GetPublicKey(addr mino.Address) (crypto.PublicKey, int)
- func (ca CollectiveAuthority) GetSigner(index int) crypto.Signer
- func (ca CollectiveAuthority) Len() int
- func (ca CollectiveAuthority) PublicKeyIterator() crypto.PublicKeyIterator
- func (ca CollectiveAuthority) Take(updaters ...mino.FilterUpdater) mino.Players
- type ContextEngine
- type Counter
- type Format
- type GenSigner
- type Hash
- type HashFactory
- type InMemoryDB
- type InMemorySnapshot
- type Message
- type MessageFactory
- type MessageFormat
- type Mino
- type PublicKey
- func (pk PublicKey) Equal(other interface{}) bool
- func (pk PublicKey) MarshalBinary() ([]byte, error)
- func (pk PublicKey) MarshalText() ([]byte, error)
- func (pk PublicKey) Serialize(serde.Context) ([]byte, error)
- func (pk PublicKey) String() string
- func (pk PublicKey) Verify([]byte, crypto.Signature) error
- type PublicKeyFactory
- type PublicKeyIterator
- type RPC
- func (rpc *RPC) Call(ctx context.Context, m serde.Message, p mino.Players) (<-chan mino.Response, error)
- func (rpc *RPC) Done()
- func (rpc *RPC) Reset()
- func (rpc *RPC) SendResponse(from mino.Address, msg serde.Message)
- func (rpc *RPC) SendResponseWithError(from mino.Address, err error)
- func (rpc *RPC) Stream(ctx context.Context, p mino.Players) (mino.Sender, mino.Receiver, error)
- type Receiver
- type ReceiverMessage
- type Sender
- type Signature
- type SignatureFactory
- type Signer
- func (s Signer) Aggregate(...crypto.Signature) (crypto.Signature, error)
- func (s Signer) GetPublicKey() crypto.PublicKey
- func (s Signer) GetPublicKeyFactory() crypto.PublicKeyFactory
- func (s Signer) GetSignatureFactory() crypto.SignatureFactory
- func (s Signer) GetVerifierFactory() crypto.VerifierFactory
- func (s Signer) Sign([]byte) (crypto.Signature, error)
- type Verifier
- type VerifierFactory
Constants ¶
const ( // GoodFormat should register working format engines. GoodFormat = serde.Format("FakeGood") // BadFormat should register non-working format engines. BadFormat = serde.Format("FakeBad") // MsgFormat should register an engine for fake.Message. MsgFormat = serde.Format("FakeMsg") )
const SignatureByte = 0xfe
SignatureByte is the byte returned when marshaling a fake signature.
Variables ¶
This section is empty.
Functions ¶
func CheckLog ¶
CheckLog returns a logger and a check function. When called, the function will verify if the logger has seen the message printed.
func GetFakeFormatValue ¶
func GetFakeFormatValue() []byte
GetFakeFormatValue returns the value of the fake format serialization.
func GetTracerForAddrEmpty ¶
GetTracerForAddrEmpty is used to mock `tracing.GetTracerForAddr` with an empty tracer.
func GetTracerForAddrWithError ¶
GetTracerForAddrWithError is used to mock `tracing.GetTracerForAddr` with an error.
func MakeCertificate ¶
MakeCertificate generates a valid certificate for the localhost address and for an hour. It outputs only its byte representation.
func MakeCertificateChain ¶
MakeCertificateChain creates a valid certificate chain with an intermediary certificate.
func MakeFullCertificate ¶
func MakeFullCertificate(t *testing.T) (*tls.Certificate, []byte)
MakeFullCertificate generates a valid certificate for the localhost address and for an hour. it outputs the TLS certificate and its byte representation.
func NewBadContext ¶
NewBadContext returns a new serde context that produces errors.
func NewBadContextWithDelay ¶
NewBadContextWithDelay returns a new serde context that produces errors after some calls.
func NewContextWithFormat ¶
NewContextWithFormat returns a new serde context that is using the provided format.
func NewMsgContext ¶
NewMsgContext returns a new serde context that always produces a fake message.
Types ¶
type Address ¶
Address is a fake implementation of an address.
- implements mino.Address
func NewAddress ¶
NewAddress returns a fake address with the given index.
func NewBadAddress ¶
func NewBadAddress() Address
NewBadAddress returns a fake address that returns an error when appropriate.
func (Address) ConnectionType ¶
func (a Address) ConnectionType() mino.AddressConnectionType
ConnectionType always returns ACTgRPCS
func (Address) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
type AddressFactory ¶
type AddressFactory struct {
mino.AddressFactory
}
AddressFactory is a fake implementation of an address factory.
- implements mino.AddressFactory
type AddressIterator ¶
type AddressIterator struct { mino.AddressIterator // contains filtered or unexported fields }
AddressIterator is a fake implementation an address iterator.
- implements mino.AddressIterator
func NewAddressIterator ¶
func NewAddressIterator(addrs []mino.Address) *AddressIterator
NewAddressIterator returns a new address iterator
func (*AddressIterator) GetNext ¶
func (i *AddressIterator) GetNext() mino.Address
GetNext implements mino.AddressIterator.
func (*AddressIterator) HasNext ¶
func (i *AddressIterator) HasNext() bool
HasNext implements mino.AddressIterator.
func (*AddressIterator) Seek ¶
func (i *AddressIterator) Seek(index int)
Seek implements mino.AddressIterator.
type Bucket ¶
Bucket is a fake key/value storage bucket.
- implements kv.Bucket
func NewBadDeleteBucket ¶
func NewBadDeleteBucket() *Bucket
NewBadDeleteBucket returns a new empty bucket that fails to delete.
func NewBadForeachBucket ¶
func NewBadForeachBucket() *Bucket
NewBadForeachBucket returns a new empty bucket that fails to iterate
func NewBadWriteBucket ¶
func NewBadWriteBucket() *Bucket
NewBadWriteBucket returns a new empty bucket that fails to write.
type CollectiveAuthority ¶
type CollectiveAuthority struct { crypto.CollectiveAuthority Call *Call PubkeyNotFound bool // contains filtered or unexported fields }
CollectiveAuthority is a fake implementation of a collective authority.
- implements crypto.CollectiveAuthority
func NewAuthority ¶
func NewAuthority(n int, g GenSigner) CollectiveAuthority
NewAuthority returns a new collective authority of n members with new signers generated by g.
func NewAuthorityFromMino ¶
func NewAuthorityFromMino(g GenSigner, instances ...mino.Mino) CollectiveAuthority
NewAuthorityFromMino returns a new fake collective authority using the addresses of the Mino instances.
func NewAuthorityWithBase ¶
func NewAuthorityWithBase(base int, n int, g GenSigner) CollectiveAuthority
NewAuthorityWithBase returns a new fake collective authority of size n with a given starting base index.
func (CollectiveAuthority) AddressIterator ¶
func (ca CollectiveAuthority) AddressIterator() mino.AddressIterator
AddressIterator implements mino.Players.
func (CollectiveAuthority) GetAddress ¶
func (ca CollectiveAuthority) GetAddress(index int) mino.Address
GetAddress returns the address at the provided index.
func (CollectiveAuthority) GetPublicKey ¶
GetPublicKey implements crypto.CollectiveAuthority.
func (CollectiveAuthority) GetSigner ¶
func (ca CollectiveAuthority) GetSigner(index int) crypto.Signer
GetSigner returns the signer at the provided index.
func (CollectiveAuthority) Len ¶
func (ca CollectiveAuthority) Len() int
Len implements mino.Players.
func (CollectiveAuthority) PublicKeyIterator ¶
func (ca CollectiveAuthority) PublicKeyIterator() crypto.PublicKeyIterator
PublicKeyIterator implements crypto.CollectiveAuthority.
func (CollectiveAuthority) Take ¶
func (ca CollectiveAuthority) Take(updaters ...mino.FilterUpdater) mino.Players
Take implements mino.Players.
type ContextEngine ¶
type ContextEngine struct { Count *Counter // contains filtered or unexported fields }
ContextEngine is a fake implementation of a serde context engine that is using JSON as the underlying marshaler.
- implements serde.ContextEngine
func (ContextEngine) GetFormat ¶
func (ctx ContextEngine) GetFormat() serde.Format
GetFormat implements serde.ContextEngine.
func (ContextEngine) Marshal ¶
func (ctx ContextEngine) Marshal(m interface{}) ([]byte, error)
Marshal implements serde.ContextEngine.
func (ContextEngine) Unmarshal ¶
func (ctx ContextEngine) Unmarshal(data []byte, m interface{}) error
Unmarshal implements serde.ContextEngine.
type Counter ¶
type Counter struct {
Value int
}
Counter is a helper to delay errors or actions. It can be nil without panics.
func NewCounter ¶
NewCounter returns a new counter set to the given value.
type Format ¶
Format is a fake format engine implementation.
- implements serde.FormatEngine
func NewBadFormat ¶
func NewBadFormat() Format
NewBadFormat returns a new format engine that always return an error.
type Hash ¶
Hash is a fake implementation of hash.Hash.
- implements hash.Hash
func NewBadHash ¶
func NewBadHash() *Hash
NewBadHash returns a fake hash that returns an error when appropriate.
func NewBadHashWithDelay ¶
NewBadHashWithDelay returns a fake hash that returns an error after a certain amount of calls.
func (*Hash) MarshalBinary ¶
MarshalBinary implements encoding.BinaryMarshaler.
func (*Hash) UnmarshalBinary ¶
UnmarshalBinary implements encodi8ng.BinaryUnmarshaler.
type HashFactory ¶
type HashFactory struct {
// contains filtered or unexported fields
}
HashFactory is a fake implementation of a hash factory.
- implements crypto.HashFactory
func NewHashFactory ¶
func NewHashFactory(h *Hash) HashFactory
NewHashFactory returns a fake hash factory.
type InMemoryDB ¶
type InMemoryDB struct {
// contains filtered or unexported fields
}
InMemoryDB is a fake implementation of a key/value storage.
- implements kv.DB
func NewBadDB ¶
func NewBadDB() *InMemoryDB
NewBadDB returns a new database that will return an error inside the transactions, and when closing the database.
func NewBadViewDB ¶
func NewBadViewDB() *InMemoryDB
NewBadViewDB returns a new database that fails to open view transactions.
func (*InMemoryDB) SetBucket ¶
func (db *InMemoryDB) SetBucket(name []byte, b *Bucket)
SetBucket allows to define a bucket in the database.
func (*InMemoryDB) Update ¶
func (db *InMemoryDB) Update(fn func(tx kv.WritableTx) error) error
Update implements kv.DB.
func (*InMemoryDB) View ¶
func (db *InMemoryDB) View(fn func(tx kv.ReadableTx) error) error
View implements kv.DB.
type InMemorySnapshot ¶
type InMemorySnapshot struct { store.Snapshot ErrRead error ErrWrite error ErrDelete error // contains filtered or unexported fields }
InMemorySnapshot is a fake implementation of a store snapshot.
- implements store.Snapshot
func NewBadSnapshot ¶
func NewBadSnapshot() *InMemorySnapshot
NewBadSnapshot creates a new empty snapshot that will always return an error.
func (*InMemorySnapshot) Delete ¶
func (snap *InMemorySnapshot) Delete(key []byte) error
Delete implements store.Snapshot.
func (*InMemorySnapshot) Get ¶
func (snap *InMemorySnapshot) Get(key []byte) ([]byte, error)
Get implements store.Snapshot.
func (*InMemorySnapshot) Set ¶
func (snap *InMemorySnapshot) Set(key, value []byte) error
Set implements store.Snapshot.
type Message ¶
type Message struct {
Digest []byte
}
Message is a fake implementation if a serde message.
- implements serde.Message
func (Message) Fingerprint ¶
Fingerprint implements serde.Fingerprinter.
type MessageFactory ¶
type MessageFactory struct {
// contains filtered or unexported fields
}
MessageFactory is a fake implementation of a serde factory.
- implements serde.Factory
func NewBadMessageFactory ¶
func NewBadMessageFactory() MessageFactory
NewBadMessageFactory returns a new message factory that returns an error.
func (MessageFactory) Deserialize ¶
Deserialize implements serde.Factory.
type MessageFormat ¶
type MessageFormat struct{}
MessageFormat is a format engine to encode and decode fake messages.
- implements serde.FormatEngine
type Mino ¶
Mino is a fake implementation of mino.
- implements mino.Mino
func NewBadMino ¶
func NewBadMino() Mino
NewBadMino returns a Mino instance that returns an error when appropriate.
func (Mino) GetAddressFactory ¶
func (m Mino) GetAddressFactory() mino.AddressFactory
GetAddressFactory implements mino.Mino.
type PublicKey ¶
PublicKey is a fake implementation of crypto.PublicKey.
- implements crypto.PublicKey
func NewBadPublicKey ¶
func NewBadPublicKey() PublicKey
NewBadPublicKey returns a new fake public key that returns error when appropriate.
func NewInvalidPublicKey ¶
func NewInvalidPublicKey() PublicKey
NewInvalidPublicKey returns a fake public key that never verifies.
func (PublicKey) MarshalBinary ¶
MarshalBinary implements encoding.BinaryMarshaler.
func (PublicKey) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
type PublicKeyFactory ¶
type PublicKeyFactory struct {
// contains filtered or unexported fields
}
PublicKeyFactory is a fake implementation of a public key factory.
- implements crypto.PublicKeyFactory.
func NewBadPublicKeyFactory ¶
func NewBadPublicKeyFactory() PublicKeyFactory
NewBadPublicKeyFactory returns a fake public key factory that returns an error when appropriate.
func NewPublicKeyFactory ¶
func NewPublicKeyFactory(pubkey PublicKey) PublicKeyFactory
NewPublicKeyFactory returns a fake public key factory that returns the given public key.
func (PublicKeyFactory) Deserialize ¶
Deserialize implements serde.Factory.
func (PublicKeyFactory) FromBytes ¶
func (f PublicKeyFactory) FromBytes([]byte) (crypto.PublicKey, error)
FromBytes implements crypto.PublicKeyFactory.
func (PublicKeyFactory) PublicKeyOf ¶
PublicKeyOf implements crypto.PublicKeyFactory.
type PublicKeyIterator ¶
type PublicKeyIterator struct {
// contains filtered or unexported fields
}
PublicKeyIterator is a fake implementation of a public key iterator.
- implements crypto.PublicKeyIterator
func NewPublicKeyIterator ¶
func NewPublicKeyIterator(signers []crypto.Signer) *PublicKeyIterator
NewPublicKeyIterator returns a new address iterator
func (*PublicKeyIterator) GetNext ¶
func (i *PublicKeyIterator) GetNext() crypto.PublicKey
GetNext implements crypto.PublicKeyIterator.
func (*PublicKeyIterator) HasNext ¶
func (i *PublicKeyIterator) HasNext() bool
HasNext implements crypto.PublicKeyIterator.
func (*PublicKeyIterator) Seek ¶
func (i *PublicKeyIterator) Seek(index int)
Seek implements crypto.PublicKeyIterator.
type RPC ¶
RPC is a fake implementation of an RPC.
- implements mino.RPC
func NewBadRPC ¶
func NewBadRPC() *RPC
NewBadRPC returns a fake rpc that returns an error when appropriate.
func NewStreamRPC ¶
NewStreamRPC returns a fake rpc with specific stream options.
func (*RPC) Call ¶
func (rpc *RPC) Call(ctx context.Context, m serde.Message, p mino.Players) (<-chan mino.Response, error)
Call implements mino.RPC.
func (*RPC) SendResponse ¶
SendResponse fills the rpc with a message.
func (*RPC) SendResponseWithError ¶
SendResponseWithError fills the rpc with an error.
type Receiver ¶
type Receiver struct { mino.Receiver Msgs []ReceiverMessage // contains filtered or unexported fields }
Receiver is a fake RPC stream receiver. It will return the consecutive messages stored in the Msg slice.
- implements mino.Receiver
func NewBadReceiver ¶
func NewBadReceiver(msg ...ReceiverMessage) *Receiver
NewBadReceiver returns a new receiver that returns an error.
func NewBlockingReceiver ¶
func NewBlockingReceiver() *Receiver
NewBlockingReceiver returns a new fake receiver that is blocking until the context is done.
func NewReceiver ¶
func NewReceiver(msgs ...ReceiverMessage) *Receiver
NewReceiver returns a new receiver
type ReceiverMessage ¶
ReceiverMessage is the combination of an address and a message that is returned by the receiver.
func NewRecvMsg ¶
func NewRecvMsg(addr mino.Address, msg serde.Message) ReceiverMessage
NewRecvMsg creates a new receiver message.
type Sender ¶
Sender is a fake RPC stream sender.
- implements mino.Sender
func NewBadSender ¶
func NewBadSender() Sender
NewBadSender returns a sender that always returns an error.
type Signature ¶
Signature is a fake implementation of the signature.
- implements crypto.Signature
func NewBadSignature ¶
func NewBadSignature() Signature
NewBadSignature returns a signature that will return error when appropriate.
func (Signature) MarshalBinary ¶
MarshalBinary implements crypto.Signature.
type SignatureFactory ¶
type SignatureFactory struct { Counter *Counter // contains filtered or unexported fields }
SignatureFactory is a fake implementation of the signature factory.
- implements crypto.SignatureFactory
func NewBadSignatureFactory ¶
func NewBadSignatureFactory() SignatureFactory
NewBadSignatureFactory returns a signature factory that will return an error when appropriate.
func NewBadSignatureFactoryWithDelay ¶
func NewBadSignatureFactoryWithDelay(value int) SignatureFactory
NewBadSignatureFactoryWithDelay returns a signature factory that will return an error after some calls.
func NewSignatureFactory ¶
func NewSignatureFactory(s Signature) SignatureFactory
NewSignatureFactory returns a fake signature factory.
func (SignatureFactory) Deserialize ¶
Deserialize implements serde.Factory.
func (SignatureFactory) SignatureOf ¶
SignatureOf implements crypto.SignatureFactory.
type Signer ¶
type Signer struct { crypto.AggregateSigner // contains filtered or unexported fields }
Signer is a fake implementation of the crypto.AggregateSigner interface.
- implements crypto.Signer
func NewAggregateSigner ¶
func NewAggregateSigner() Signer
NewAggregateSigner returns a new signer that implements aggregation.
func NewBadSigner ¶
func NewBadSigner() Signer
NewBadSigner returns a fake signer that will return an error when appropriate.
func NewSignerWithPublicKey ¶
NewSignerWithPublicKey returns a new fake signer with the specific public key.
func NewSignerWithSignatureFactory ¶
func NewSignerWithSignatureFactory(f SignatureFactory) Signer
NewSignerWithSignatureFactory returns a fake signer with the provided factory.
func NewSignerWithVerifierFactory ¶
func NewSignerWithVerifierFactory(f VerifierFactory) Signer
NewSignerWithVerifierFactory returns a new fake signer with the specific verifier factory.
func (Signer) GetPublicKey ¶
GetPublicKey implements crypto.Signer.
func (Signer) GetPublicKeyFactory ¶
func (s Signer) GetPublicKeyFactory() crypto.PublicKeyFactory
GetPublicKeyFactory implements crypto.Signer.
func (Signer) GetSignatureFactory ¶
func (s Signer) GetSignatureFactory() crypto.SignatureFactory
GetSignatureFactory implements crypto.Signer.
func (Signer) GetVerifierFactory ¶
func (s Signer) GetVerifierFactory() crypto.VerifierFactory
GetVerifierFactory implements crypto.Signer.
type Verifier ¶
Verifier is a fake implementation of crypto.Verifier.
- implements crypto.Verifier
func NewBadVerifier ¶
func NewBadVerifier() Verifier
NewBadVerifier returns a verifier that will return an error when appropriate.
func NewBadVerifierWithDelay ¶
NewBadVerifierWithDelay returns a verifier that will return an error after a given delay.
type VerifierFactory ¶
type VerifierFactory struct { crypto.VerifierFactory // contains filtered or unexported fields }
VerifierFactory is a fake implementation of crypto.VerifierFactory.
- implements crypto.VerifierFactory
func NewBadVerifierFactory ¶
func NewBadVerifierFactory() VerifierFactory
NewBadVerifierFactory returns a fake verifier factory that returns an error when appropriate.
func NewVerifierFactory ¶
func NewVerifierFactory(v Verifier) VerifierFactory
NewVerifierFactory returns a new fake verifier factory.
func NewVerifierFactoryWithCalls ¶
func NewVerifierFactoryWithCalls(c *Call) VerifierFactory
NewVerifierFactoryWithCalls returns a new verifier factory that will register the calls.
func (VerifierFactory) FromAuthority ¶
func (f VerifierFactory) FromAuthority(ca crypto.CollectiveAuthority) (crypto.Verifier, error)
FromAuthority implements crypto.VerifierFactory.