testing

package
v0.60.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package testing provides comprehensive testing utilities for the go-bricks framework.

This package contains mocks and fixtures that enable developers to write effective unit and integration tests for applications built with go-bricks.

Mocks

The mocks subpackage provides testify-based mock implementations for all major framework interfaces:

  • Database operations (database.Interface, database.Statement, database.Tx)
  • Messaging operations (messaging.Client, messaging.AMQPClient, messaging.RegistryInterface)

Fixtures

The fixtures subpackage provides helper functions and pre-configured mocks for common testing scenarios:

  • Database fixtures with common behaviors (healthy, failing, with data)
  • Messaging fixtures for simulating message flows
  • SQL result builders for consistent test data

Usage

Import the specific subpackages you need:

import (
	"github.com/gaborage/go-bricks/testing/mocks"
	"github.com/gaborage/go-bricks/testing/fixtures"
)

For comprehensive examples and usage patterns, see the go-bricks-demo-project repository (https://github.com/gaborage/go-bricks-demo-project) and TESTING.md documentation.

Index

Constants

View Source
const (
	// TestLoggerLevelDebug is the debug log level used in most tests
	TestLoggerLevelDebug = "debug"
	// TestLoggerLevelError is the error log level for tests requiring minimal output
	TestLoggerLevelError = "error"
	// TestLoggerLevelDisabled completely disables logging in tests
	TestLoggerLevelDisabled = "disabled"
)

Logger Constants These constants define common logger configurations used across test files to avoid duplicating logger initialization strings.

View Source
const (
	TestServiceName  = "test-service"
	TestCacheName    = "test-cache"
	TestKeyName      = "test-key"
	TestValueDefault = "test-value"
)

Service and Component Names Common service/component name constants available for test configurations.

View Source
const (
	TestQueueName    = "test-queue"
	TestExchangeName = "test-exchange"
	TestRoutingKey   = "test-routing-key"
	TestConsumerTag  = "test-consumer"
)

Messaging Constants Common queue, exchange, and routing key names for messaging tests.

View Source
const (
	TestTableUsers      = "users"
	TestTableProducts   = "products"
	TestTableOrders     = "orders"
	TestUsername        = "testuser"
	TestDatabaseName    = "testdb"
	TestHostLocalhost   = "localhost"
	TestPasswordDefault = "testpass"
	TestStatusActive    = "active"
	TestStatusInactive  = "inactive"
	TestSelectQuery     = "SELECT"
	TestInsertQuery     = "INSERT"
	TestUpdateQuery     = "UPDATE"
	TestDeleteQuery     = "DELETE"
)

Database Constants Common database-related test strings (table names, queries, connection strings).

View Source
const (
	TestEmailAlice = "alice@example.com"
	TestEmailBob   = "bob@example.com"
	TestNameAlice  = "Alice"
	TestNameBob    = "Bob"
)

Test User Data Common test user data constants available for test suites.

View Source
const (
	TestTenantOne    = "tenant-1"
	TestTenantTwo    = "tenant-2"
	TestTenantThree  = "tenant-3"
	TestTenantAcme   = "acme"
	TestTenantGlobex = "globex"
)

Multi-Tenant Constants Common tenant identifiers for multi-tenant testing.

View Source
const (
	TestTracerName = "test"
	TestMeterName  = "test-meter"
	TestSpanName   = "test-span"
)

OpenTelemetry Constants Common names for tracing, metrics, and observability tests.

View Source
const (
	// TestShortDelay is a short delay for goroutine synchronization (100ms)
	TestShortDelay = 100 * time.Millisecond
	// TestMediumDelay is a medium delay for async operations (300ms)
	TestMediumDelay = 300 * time.Millisecond
	// TestLongDelay is a longer delay for slow operations (1 second)
	TestLongDelay = 1 * time.Second
	// TestCleanupWaitPeriod is the wait time for cleanup operations (300ms)
	TestCleanupWaitPeriod = 300 * time.Millisecond
	// TestEventuallyTimeout is the timeout for require.Eventually assertions (500ms)
	TestEventuallyTimeout = 500 * time.Millisecond
	// TestEventuallyTick is the polling interval for require.Eventually (50ms)
	TestEventuallyTick = 50 * time.Millisecond
)

Time Duration Constants Common time duration constants available for test synchronization and timeouts.

View Source
const (
	TestPortRedis      = 6379
	TestPortHTTP       = 8080
	TestPortPostgreSQL = 5432
)

Port Numbers Common port numbers for test services.

View Source
const (
	TestVarcharSize           = 100
	TestBytesPerKB            = 1024
	TestBenchmarkLargePayload = 100 * 1024 // 100KB
	TestBenchmarkSmallPayload = 256        // 256 bytes
)

Size Constants Common size values for buffers, payloads, and varchar lengths.

Variables

This section is empty.

Functions

func FakePassword added in v0.60.0

func FakePassword(label string) string

FakePassword composes a synthetic password from a label. It is a test fixture only — the value is deterministic and published in this repository, so it must never stand in for a real credential. The label keeps values distinct where a test rotates one; every result is well past config.MinDatabasePasswordLength, under which migration's redactPassword suppresses Flyway output wholesale.

func PEMFixture added in v0.60.0

func PEMFixture(blockType string) []byte

PEMFixture returns the smallest well-formed PEM block of the given type, with a body that decodes to "foo". Byte-identical to the equivalent literal.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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