watertestlogger

package module
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2025 License: MIT Imports: 3 Imported by: 0

README

⛲️ Watermill Test Logger

Logger for testing with watermill.

⬇️ Installation

go get github.com/survivorbat/go-watermill-test-logger

📋 Usage

package main

import (
 "github.com/stretchr/testify/require"
 "github.com/ThreeDotsLabs/watermill/message"
)

func TestWatermill(t *testing.T) {
  // This Will fail the test if any error occur, and log to the test instance
  logger := watertestlogger.NewTestAdaptor(t, true, watermill.LogLevelInfo)

  router, err := message.NewRouter(message.RouterConfig{}, logger)
  require.NoError(t, err)

  // [...]
}

🔭 Plans

Not much yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TestLogAdaptor

type TestLogAdaptor struct {
	// UseError will instruct the adaptor to use t.Error when logging fields, causing
	// tests to fail if any error were logged. Exposed to allow users to change the value
	// during a test.
	UseError bool

	// LogLevel is uses to determine what we should log and what we should skip. Exposed to allow users to change the value
	// during a test.
	LogLevel watermill.LogLevel
	// contains filtered or unexported fields
}

TestLogAdaptor implements watermill.LoggerAdapter and can be used to capture logs in test code.

func NewTestAdaptor

func NewTestAdaptor(t testingi.T, useError bool, logLevel watermill.LogLevel) *TestLogAdaptor

NewTestAdaptor instantiates a new adaptor that writes logs to the given test instance. If useError is set to true, it will also cause the test to fail.

func (*TestLogAdaptor) Debug

func (t *TestLogAdaptor) Debug(msg string, fields watermill.LogFields)

Debug implements watermill.LoggerAdapter.

func (*TestLogAdaptor) Error

func (t *TestLogAdaptor) Error(msg string, err error, fields watermill.LogFields)

Error implements watermill.LoggerAdapter.

func (*TestLogAdaptor) Info

func (t *TestLogAdaptor) Info(msg string, fields watermill.LogFields)

Info implements watermill.LoggerAdapter.

func (*TestLogAdaptor) Trace

func (t *TestLogAdaptor) Trace(msg string, fields watermill.LogFields)

Trace implements watermill.LoggerAdapter.

func (*TestLogAdaptor) With

With implements watermill.LoggerAdapter.

Jump to

Keyboard shortcuts

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