aboutsummaryrefslogtreecommitdiffstats
path: root/library/go/test/assertpb/assert.go
blob: f5420748d2ac978ecd45bc2ff8cb99262a270fb9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package assertpb

import (
	"fmt"

	"github.com/golang/protobuf/proto"
	"github.com/google/go-cmp/cmp"
	"github.com/stretchr/testify/assert"
)

type TestingT interface {
	Errorf(format string, args ...interface{})
	FailNow()
	Helper()
}

func Equal(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool {
	t.Helper()

	if cmp.Equal(expected, actual, cmp.Comparer(proto.Equal)) {
		return true
	}

	diff := cmp.Diff(expected, actual, cmp.Comparer(proto.Equal))
	return assert.Fail(t, fmt.Sprintf("Not equal: \n"+
		"expected: %s\n"+
		"actual  : %s\n"+
		"diff    : %s", expected, actual, diff), msgAndArgs)
}

func Equalf(t TestingT, expected, actual interface{}, msg string, args ...interface{}) bool {
	t.Helper()

	return Equal(t, expected, actual, append([]interface{}{msg}, args...)...)
}