teq

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 4 Imported by: 0

README

✅ Gomock Testify Equality

teq is a gomock matcher that uses testify/assert to perform matches, providing testify output for use in gomock.

⚠️ This library was originally called go-mockassert, now it's shorter

⬇️ Installation

go get github.com/survivorbat/go-teq

📋 Usage

package main

import (
 "testing"

 "go.uber.org/mock/gomock"
 "github.com/stretchr/testify/require"
 "github.com/survivorbat/go-teq"
)

func TestExample(t *testing.T) {
  t.Parallel()
  // Arrange
  ctrl := gomock.NewController(t)

  testMock := NewMockTestInterface(ctrl)

  expected := &TestType{Name: "foo"}

  // Expect
  testMock.EXPECT().CreateTestType(gomock.Any(), teq.Eq(t, expected))

  // Act
  err := testMock.CreateTestType(t.Context())

  // Assert
  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 AssertFunc

type AssertFunc func(assert.TestingT, any, any, ...any) bool

AssertFunc matches the signature of assert.equal and similar functions

type Config

type Config struct {
	// AssertFunc can swap assert.Equal with other similar assertions
	AssertFunc AssertFunc
}

Config allows customisation for the behaviour of Matcher

type Matcher

type Matcher struct {
	T          *testing.T
	AssertFunc AssertFunc
	Expected   any
}

Matcher implements gomock.Matcher and uses Expected to assert with actual.

func Eq

func Eq(t *testing.T, expected any, opts ...Option) *Matcher

Eq ensures gomock will use testify to verify equality of the actual and the expected call.

func (*Matcher) Matches

func (m *Matcher) Matches(actual any) bool

Matches checks whether the expected value matches the actual

func (*Matcher) String

func (m *Matcher) String() string

String returns the type name that the matcher was created for

type Option

type Option func(*Config)

Option are used as input to the New method to customise behaviour

func ExportedValues

func ExportedValues() Option

ExportedValues sets the assertion function as assert.EqualExportedValues

func Values

func Values() Option

Values sets the assertion function as assert.EqualValues

Jump to

Keyboard shortcuts

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