Documentation ¶
Index ¶
- func AssertNoUnmatchedRequests(t UnmatchedRequestsTestingT)
- func DeleteCreatedEntities(db *gorm.DB) func()
- type BufferLogger
- func (l *BufferLogger) Bytes() []byte
- func (l *BufferLogger) ForAccount(acc any) logger.Logger
- func (l *BufferLogger) ForConnection(conn any) logger.Logger
- func (l *BufferLogger) ForHandler(handler any) logger.Logger
- func (l *BufferLogger) Read(p []byte) (n int, err error)
- func (l *BufferLogger) Reset()
- func (l *BufferLogger) String() string
- func (l *BufferLogger) With(fields ...zapcore.Field) logger.Logger
- func (l *BufferLogger) WithLazy(fields ...zapcore.Field) logger.Logger
- type BufferedLogger
- type JSONRecordScanner
- type LockableBuffer
- func (b *LockableBuffer) Available() int
- func (b *LockableBuffer) AvailableBuffer() []byte
- func (b *LockableBuffer) Bytes() []byte
- func (b *LockableBuffer) Cap() int
- func (b *LockableBuffer) Grow(n int)
- func (b *LockableBuffer) Len() int
- func (b *LockableBuffer) Next(n int) []byte
- func (b *LockableBuffer) Read(p []byte) (n int, err error)
- func (b *LockableBuffer) ReadByte() (byte, error)
- func (b *LockableBuffer) ReadBytes(delim byte) (line []byte, err error)
- func (b *LockableBuffer) ReadFrom(r io.Reader) (n int64, err error)
- func (b *LockableBuffer) ReadRune() (r rune, size int, err error)
- func (b *LockableBuffer) ReadString(delim byte) (line string, err error)
- func (b *LockableBuffer) Reset()
- func (b *LockableBuffer) String() string
- func (b *LockableBuffer) Sync() error
- func (b *LockableBuffer) Truncate(n int)
- func (b *LockableBuffer) UnreadByte() error
- func (b *LockableBuffer) UnreadRune() error
- func (b *LockableBuffer) Write(p []byte) (n int, err error)
- func (b *LockableBuffer) WriteByte(c byte) error
- func (b *LockableBuffer) WriteRune(r rune) (n int, err error)
- func (b *LockableBuffer) WriteString(s string) (n int, err error)
- func (b *LockableBuffer) WriteTo(w io.Writer) (n int64, err error)
- type LogRecord
- type ReadBuffer
- type TranslationsExtractor
- type UnmatchedRequestsTestingT
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertNoUnmatchedRequests ¶
func AssertNoUnmatchedRequests(t UnmatchedRequestsTestingT)
AssertNoUnmatchedRequests check that gock didn't receive any request that it was not able to match. It will print out an entire request data for every unmatched request.
func DeleteCreatedEntities ¶
DeleteCreatedEntities sets up GORM `onCreate` hook and return a function that can be deferred to remove all the entities created after the hook was set up. You can use it like this:
func TestSomething(t *testing.T){ db, _ := gorm.Open(...) cleaner := DeleteCreatedEntities(db) defer cleaner() }.
Types ¶
type BufferLogger ¶
BufferLogger is an implementation of the BufferedLogger.
BufferLogger can be used in tests to match specific log messages. It uses JSON by default (hardcoded for now). It implements fmt.Stringer and provides an adapter to the underlying buffer, which means it can also return Bytes(), can be used like io.Reader and can be cleaned using Reset() method.
Usage:
log := NewBufferedLogger() // Some other code that works with logger. fmt.Println(log.String())
func (*BufferLogger) Bytes ¶
func (l *BufferLogger) Bytes() []byte
Bytes is a shorthand for the underlying bytes.Buffer method. Returns byte slice with the buffer contents.
func (*BufferLogger) ForAccount ¶ added in v2.8.0
func (l *BufferLogger) ForAccount(acc any) logger.Logger
func (*BufferLogger) ForConnection ¶ added in v2.8.0
func (l *BufferLogger) ForConnection(conn any) logger.Logger
func (*BufferLogger) ForHandler ¶ added in v2.8.0
func (l *BufferLogger) ForHandler(handler any) logger.Logger
func (*BufferLogger) Read ¶
func (l *BufferLogger) Read(p []byte) (n int, err error)
Read bytes from the logger buffer. io.Reader implementation.
func (*BufferLogger) Reset ¶
func (l *BufferLogger) Reset()
Reset is a shorthand for the underlying bytes.Buffer method. It will reset buffer contents.
func (*BufferLogger) String ¶
func (l *BufferLogger) String() string
String contents of the logger buffer. fmt.Stringer implementation.
type BufferedLogger ¶
type BufferedLogger interface { ReadBuffer logger.Logger }
BufferedLogger is a logger that can return the data written to it.
func NewBufferedLogger ¶
func NewBufferedLogger() BufferedLogger
NewBufferedLogger returns new BufferedLogger instance.
type JSONRecordScanner ¶ added in v2.8.0
type JSONRecordScanner struct {
// contains filtered or unexported fields
}
func NewJSONRecordScanner ¶ added in v2.8.0
func NewJSONRecordScanner(entryProvider io.Reader) *JSONRecordScanner
func (*JSONRecordScanner) Entry ¶ added in v2.8.0
func (s *JSONRecordScanner) Entry() LogRecord
func (*JSONRecordScanner) Scan ¶ added in v2.8.0
func (s *JSONRecordScanner) Scan() error
func (*JSONRecordScanner) ScanAll ¶ added in v2.8.0
func (s *JSONRecordScanner) ScanAll() ([]LogRecord, error)
type LockableBuffer ¶ added in v2.8.0
type LockableBuffer struct {
// contains filtered or unexported fields
}
func (*LockableBuffer) Available ¶ added in v2.8.0
func (b *LockableBuffer) Available() int
func (*LockableBuffer) AvailableBuffer ¶ added in v2.8.0
func (b *LockableBuffer) AvailableBuffer() []byte
func (*LockableBuffer) Bytes ¶ added in v2.8.0
func (b *LockableBuffer) Bytes() []byte
func (*LockableBuffer) Cap ¶ added in v2.8.0
func (b *LockableBuffer) Cap() int
func (*LockableBuffer) Grow ¶ added in v2.8.0
func (b *LockableBuffer) Grow(n int)
func (*LockableBuffer) Len ¶ added in v2.8.0
func (b *LockableBuffer) Len() int
func (*LockableBuffer) Next ¶ added in v2.8.0
func (b *LockableBuffer) Next(n int) []byte
func (*LockableBuffer) Read ¶ added in v2.8.0
func (b *LockableBuffer) Read(p []byte) (n int, err error)
func (*LockableBuffer) ReadByte ¶ added in v2.8.0
func (b *LockableBuffer) ReadByte() (byte, error)
func (*LockableBuffer) ReadBytes ¶ added in v2.8.0
func (b *LockableBuffer) ReadBytes(delim byte) (line []byte, err error)
func (*LockableBuffer) ReadFrom ¶ added in v2.8.0
func (b *LockableBuffer) ReadFrom(r io.Reader) (n int64, err error)
func (*LockableBuffer) ReadRune ¶ added in v2.8.0
func (b *LockableBuffer) ReadRune() (r rune, size int, err error)
func (*LockableBuffer) ReadString ¶ added in v2.8.0
func (b *LockableBuffer) ReadString(delim byte) (line string, err error)
func (*LockableBuffer) Reset ¶ added in v2.8.0
func (b *LockableBuffer) Reset()
func (*LockableBuffer) String ¶ added in v2.8.0
func (b *LockableBuffer) String() string
func (*LockableBuffer) Sync ¶ added in v2.8.0
func (b *LockableBuffer) Sync() error
Sync is a no-op.
func (*LockableBuffer) Truncate ¶ added in v2.8.0
func (b *LockableBuffer) Truncate(n int)
func (*LockableBuffer) UnreadByte ¶ added in v2.8.0
func (b *LockableBuffer) UnreadByte() error
func (*LockableBuffer) UnreadRune ¶ added in v2.8.0
func (b *LockableBuffer) UnreadRune() error
func (*LockableBuffer) Write ¶ added in v2.8.0
func (b *LockableBuffer) Write(p []byte) (n int, err error)
func (*LockableBuffer) WriteByte ¶ added in v2.8.0
func (b *LockableBuffer) WriteByte(c byte) error
func (*LockableBuffer) WriteRune ¶ added in v2.8.0
func (b *LockableBuffer) WriteRune(r rune) (n int, err error)
func (*LockableBuffer) WriteString ¶ added in v2.8.0
func (b *LockableBuffer) WriteString(s string) (n int, err error)
type LogRecord ¶ added in v2.8.0
type LogRecord struct { LevelName string `json:"level_name"` DateTime null.Time `json:"datetime"` Message string `json:"message"` Handler string `json:"handler,omitempty"` Connection string `json:"connection,omitempty"` Account string `json:"account,omitempty"` StreamID string `json:"streamId"` Context map[string]interface{} `json:"context,omitempty"` }
type ReadBuffer ¶
ReadBuffer is implemented by the BufferLogger. Its methods give access to the buffer contents and ability to read buffer as an io.Reader or reset its contents.
type TranslationsExtractor ¶
type TranslationsExtractor struct { TranslationsFS fs.FS TranslationsPath string // contains filtered or unexported fields }
TranslationsExtractor is a tool to load raw translations data from files or from box. It is feasible to be used in tests in order to check translation files correctness. The easiest way to check correctness is to check keys in translations. TranslationsExtractor IS NOT supposed to check correctness of translations - it's just an extractor. Translations can be checked manually, or via external library like https://github.com/google/go-cmp
func NewTranslationsExtractor ¶
func NewTranslationsExtractor(fileNameTemplate string) *TranslationsExtractor
NewTranslationsExtractor constructor. Use "translate.{}.yml" as template if your translations are named like "translate.en.yml".
func (*TranslationsExtractor) GetMapKeys ¶
func (t *TranslationsExtractor) GetMapKeys(data map[string]interface{}) []string
GetMapKeys returns sorted map keys from map[string]interface{} - useful to check keys in several translation files.
func (*TranslationsExtractor) LoadLocale ¶
func (t *TranslationsExtractor) LoadLocale(locale string) (map[string]interface{}, error)
LoadLocale returns translation file data with provided locale.
func (*TranslationsExtractor) LoadLocaleKeys ¶
func (t *TranslationsExtractor) LoadLocaleKeys(locale string) ([]string, error)
LoadLocaleKeys returns only sorted keys from translation file.
type UnmatchedRequestsTestingT ¶
type UnmatchedRequestsTestingT interface { Log(...interface{}) Logf(string, ...interface{}) FailNow() }
UnmatchedRequestsTestingT contains all of *testing.T methods which are needed for AssertNoUnmatchedRequests.