test

package
v1.67.2 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: MIT Imports: 6 Imported by: 0

README

Package test

Пакет test предоставляет обёртку над testing.T, а также автоматическую инициализацию конфигурации и логгера для использования в юнит- и интеграционных тестах.

Types

Test

Структура Test служит основным контейнером для всех зависимостей, часто используемых в тестах: конфигурация, логгер, контекст testing.T, а также вспомогательные утверждения require.Assertions.

Fields:

id string

Случайно сгенерированный идентификатор теста (hex-строка длиной 8 символов).

cfg *config.Config

Конфигурация, созданная с помощью config.New().

logger log.Logger

Логгер, инициализированный в режиме разработки и с уровнем Debug.

t *testing.T

Ссылка на контекст текущего теста.

assertions *require.Assertions

Обёртка require.New(t) для удобства утверждений.

Methods:

New(t *testing.T) (*Test, *require.Assertions)

Создаёт и возвращает структуру Test, а также объект require.Assertions.

Автоматически выполняет:

  • инициализацию конфигурации и логгера,
  • генерацию короткого идентификатора теста,
  • создание обёртки require.New(t).
(t *Test) Config() *config.Config

Возвращает объект конфигурации, связанный с текущим тестом.

(t *Test) Logger() log.Logger

Возвращает логгер, связанный с текущим тестом.

(t *Test) Assert() *require.Assertions

Возвращает объект require.Assertions для выполнения проверок внутри теста.

(t *Test) Id() string

Возвращает идентификатор текущего теста (4 байта в hex-представлении).

(t *Test) T() *testing.T

Возвращает оригинальный объект *testing.T, переданный в New().

Usage

Example usage in test
package mypkg_test

import (
	"testing"
	"github.com/txix-open/isp-kit/test"
)

func TestSomething(t *testing.T) {
	testCtx, assert := test.New(t)

	cfg := testCtx.Config()
	logger := testCtx.Logger()
	id := testCtx.Id()

	logger.Info("Running test", log.String("id", id))
	assert.NotNil(cfg)
}

Documentation

Overview

Package test provides a test helper that wraps testing.T and automatically initializes configuration and logger for unit and integration tests.

The Test struct serves as a central container for commonly used test dependencies including configuration, logger, testing.T context, and require.Assertions for assertions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Test

type Test struct {
	// contains filtered or unexported fields
}

Test is a test helper that wraps testing.T and provides access to initialized configuration, logger, and assertion utilities.

func New

func New(t *testing.T) (*Test, *require.Assertions)

New creates and returns a Test instance and require.Assertions.

It automatically initializes configuration and logger, generates a unique test identifier, and creates require assertions. The function marks the calling test as a helper.

func (*Test) Assert

func (t *Test) Assert() *require.Assertions

Assert returns the require.Assertions instance for performing assertions within the test.

func (*Test) Config

func (t *Test) Config() *config.Config

Config returns the configuration instance associated with the test.

func (*Test) Id

func (t *Test) Id() string

Id returns the unique identifier for the test as a hexadecimal string.

func (*Test) Logger

func (t *Test) Logger() log.Logger

Logger returns the logger instance associated with the test. The logger is configured in development mode with debug level.

nolint:ireturn

func (*Test) T

func (t *Test) T() *testing.T

T returns the underlying testing.T instance.

Directories

Path Synopsis
Package dbt provides test helpers for database operations using dbx.
Package dbt provides test helpers for database operations using dbx.
Package fake provides utilities for generating fake test data using the faker library.
Package fake provides utilities for generating fake test data using the faker library.
Package grmqt provides test helpers for RabbitMQ operations.
Package grmqt provides test helpers for RabbitMQ operations.
Package grpct provides test helpers for gRPC server and client operations.
Package grpct provides test helpers for gRPC server and client operations.
Package httpt provides test helpers for HTTP server and client operations.
Package httpt provides test helpers for HTTP server and client operations.
Package kafkat provides test helpers for Kafka operations using the franz-go client.
Package kafkat provides test helpers for Kafka operations using the franz-go client.
Package rct provides test helpers for remote configuration validation.
Package rct provides test helpers for remote configuration validation.
Package stompt provides test helpers for STOMP messaging operations (typically used with ActiveMQ).
Package stompt provides test helpers for STOMP messaging operations (typically used with ActiveMQ).

Jump to

Keyboard shortcuts

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