cmpmock

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2024 License: MIT Imports: 5 Imported by: 0

README

cmpmock

Go Reference MIT License test reviewdog

Readable & Flexible matcher for https://go.uber.org/mock

Description

cmpmock provides a simple custom matcher. it is be able to modify behavior with github.com/google/go-cmp/cmp/cmpopts.

import "github.com/google/go-cmp/cmp"

func DiffEq(v interface{}, opts ...cmp.Option) gomock.Matcher

If DiffEq is set no opts, default behavior ignores a time differences of less than a second.

Readable ouput

Default output

expected call at /Users/tmc/go/src/github.com/tmc/cmpmock/_example/repo_test.go:26 doesn't match the argument at index 1.
Got: &{John Due Tokyo 2021-04-23 02:46:58.145696 +0900 JST m=+0.000595005}
Want: is equal to &{John Due Tokyo 2021-04-23 02:46:48.145646 +0900 JST m=-9.999455563}

use cmpmock.DiffEq

expected call at /Users/tmc/go/src/github.com/tmc/cmpmock/_example/repo_test.go:27 doesn't match the argument at index 1.
Got: &{John Due Tokyo 2021-04-23 02:46:33.290458 +0900 JST m=+0.001035665}
Want: diff(-got +want) is   &_example.User{
 	Name:     "John Due",
 	Address:  "Tokyo",
- 	CreateAt: s"2021-04-23 02:46:33.290458 +0900 JST m=+0.001035665",
+ 	CreateAt: s"2021-04-23 02:46:23.290383 +0900 JST m=-9.999039004",
}

Usage

type UserRepo interface {
  Save(context.Context, *User) error
}

wantUser := &User{}
mrepo := mock.NewMockUserRepo(ctrl)
mrepo.EXPECT().Save(ctx, cmpmock.DiffEq(wantUser)).Return(nil)

Installation

$ go get -u github.com/tmc/cmpmock

License

MIT

Author

Yocihiro Shimizu(@tmc)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DiffEq

func DiffEq(v interface{}, opts ...cmp.Option) gomock.Matcher

DiffEq is a simple custom matcher. it is be able to modify behavior with `github.com/google/go-cmp/cmp/cmpopts`. If `DiffEq` is set no `opts`, default behavior ignores a time differences of less than a second.

Types

This section is empty.

Directories

Path Synopsis
mock_example
Package mock_example is a generated GoMock package.
Package mock_example is a generated GoMock package.

Jump to

Keyboard shortcuts

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