stubs

package
v3.5.3 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package stubs provides test doubles for tests.

This file contains LoggerStub which can be used in both unit and integration tests. Unlike ports.go, this file has no build tag to ensure availability in all test contexts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LoggerStub

type LoggerStub struct {
	Infos    []string
	Warnings []string
	Errors   []string
	Debugs   []string
	Fatals   []string
}

LoggerStub captures log messages for verification in tests.

Use when you need to verify specific log messages were emitted (e.g., deprecation warnings). For tests that don't need to verify log output, prefer using the real logger:

logger := libZap.InitializeLogger()

Example usage:

func TestFunction_LogsDeprecationWarning(t *testing.T) {
    logger := &stubs.LoggerStub{}
    result := FunctionUnderTest(logger)

    assert.True(t, logger.HasWarning("DEPRECATED"))
    assert.Equal(t, 1, logger.WarningCount())
}

func (*LoggerStub) Debug

func (l *LoggerStub) Debug(args ...any)

Debug captures debug messages.

func (*LoggerStub) Debugf

func (l *LoggerStub) Debugf(format string, args ...any)

Debugf captures formatted debug messages.

func (*LoggerStub) Debugln

func (l *LoggerStub) Debugln(args ...any)

Debugln captures debug messages with newline.

func (*LoggerStub) Error

func (l *LoggerStub) Error(args ...any)

Error captures error messages.

func (*LoggerStub) ErrorCount

func (l *LoggerStub) ErrorCount() int

ErrorCount returns the number of captured errors.

func (*LoggerStub) Errorf

func (l *LoggerStub) Errorf(format string, args ...any)

Errorf captures formatted error messages.

func (*LoggerStub) Errorln

func (l *LoggerStub) Errorln(args ...any)

Errorln captures error messages with newline.

func (*LoggerStub) Fatal

func (l *LoggerStub) Fatal(args ...any)

Fatal captures fatal messages (does NOT exit - safe for tests).

func (*LoggerStub) Fatalf

func (l *LoggerStub) Fatalf(format string, args ...any)

Fatalf captures formatted fatal messages (does NOT exit - safe for tests).

func (*LoggerStub) Fatalln

func (l *LoggerStub) Fatalln(args ...any)

Fatalln captures fatal messages with newline (does NOT exit - safe for tests).

func (*LoggerStub) HasError

func (l *LoggerStub) HasError(substring string) bool

HasError checks if any captured error contains the given substring.

func (*LoggerStub) HasInfo

func (l *LoggerStub) HasInfo(substring string) bool

HasInfo checks if any captured info contains the given substring.

func (*LoggerStub) HasWarning

func (l *LoggerStub) HasWarning(substring string) bool

HasWarning checks if any captured warning contains the given substring.

func (*LoggerStub) Info

func (l *LoggerStub) Info(args ...any)

Info captures info messages.

func (*LoggerStub) InfoCount

func (l *LoggerStub) InfoCount() int

InfoCount returns the number of captured info messages.

func (*LoggerStub) Infof

func (l *LoggerStub) Infof(format string, args ...any)

Infof captures formatted info messages.

func (*LoggerStub) Infoln

func (l *LoggerStub) Infoln(args ...any)

Infoln captures info messages with newline.

func (*LoggerStub) Reset

func (l *LoggerStub) Reset()

Reset clears all captured messages.

func (*LoggerStub) Sync

func (l *LoggerStub) Sync() error

Sync is a no-op for stub.

func (*LoggerStub) Warn

func (l *LoggerStub) Warn(args ...any)

Warn captures warning messages.

func (*LoggerStub) Warnf

func (l *LoggerStub) Warnf(format string, args ...any)

Warnf captures formatted warning messages.

func (*LoggerStub) WarningCount

func (l *LoggerStub) WarningCount() int

WarningCount returns the number of captured warnings.

func (*LoggerStub) Warnln

func (l *LoggerStub) Warnln(args ...any)

Warnln captures warning messages with newline.

func (*LoggerStub) WithDefaultMessageTemplate

func (l *LoggerStub) WithDefaultMessageTemplate(message string) libLog.Logger

WithDefaultMessageTemplate returns self (no-op for stub).

func (*LoggerStub) WithFields

func (l *LoggerStub) WithFields(fields ...any) libLog.Logger

WithFields returns self (no-op for stub).

Jump to

Keyboard shortcuts

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