Documentation ¶
Index ¶
- func JSONBody(v interface{}) (*bytes.Reader, error)
- func ParseJSONBody(body io.ReadCloser, target interface{}) error
- func RequireEnv(envVars ...string) (map[string]string, error)
- func TestDB(t *testing.T) (*hnysqlx.DB, func() error)
- func TestRedis(t *testing.T) (*redis.Client, func() error)
- type Clock
- type HTTPClient
- type IDGenerator
- type Random
- type RealClock
- type SecureRandom
- type TestClock
- type TestHTTPClient
- type TestIDGenerator
- type TestRandom
- type UUIDGenerator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func JSONBody ¶
JSONBody returns the serialized JSON of the given value as a *bytes.Reader Useful for populating HTTP request bodies
func ParseJSONBody ¶
func ParseJSONBody(body io.ReadCloser, target interface{}) error
ParseJSONBody parse the given body into target using a JSON Decoder
func RequireEnv ¶
RequireEnv takes a variable number of environment variables and ensures they are all set
Types ¶
type Clock ¶
The Clock interface implements Now(), useful in order to inject specific times during testing
type HTTPClient ¶
HTTPClient describes the interface for an HTTP client
type IDGenerator ¶
type IDGenerator interface {
Generate() string
}
IDGenerator interface is used to implement uuid generators
type SecureRandom ¶
type SecureRandom struct{}
SecureRandom implements Random using the crypto/rand package
type TestHTTPClient ¶
type TestHTTPClient struct {
// contains filtered or unexported fields
}
TestHTTPClient struct represents a mocked HTTPClient
func NewTestHTTPClient ¶
func NewTestHTTPClient() *TestHTTPClient
NewTestHTTPClient creates a new TestHTTPClient struct
func (*TestHTTPClient) Do ¶
Do satisfies the HTTPClient interface, allowing the TestHTTPClient to be used in place of real HTTPClients in tests.
func (*TestHTTPClient) Mock ¶
func (c *TestHTTPClient) Mock(method, url string, handler requestHandler)
Mock sets up a new mocked handler for the given method and URL
type TestIDGenerator ¶
type TestIDGenerator struct {
ID string
}
TestIDGenerator implements IDGenerator with a constant value
func (*TestIDGenerator) Generate ¶
func (generator *TestIDGenerator) Generate() string
Generate returns the ID parameter of TestIDGenerator
type TestRandom ¶
type TestRandom struct {
Value []byte
}
TestRandom implements the Random implementation by returning a known value.
type UUIDGenerator ¶
type UUIDGenerator struct{}
UUIDGenerator implements IdGenerator via google/uuid generation
func (*UUIDGenerator) Generate ¶
func (generator *UUIDGenerator) Generate() string
Generate returns a random UUID string