assert.go 814 B

1234567891011121314151617181920212223242526272829303132333435
  1. package assertpb
  2. import (
  3. "fmt"
  4. "github.com/golang/protobuf/proto"
  5. "github.com/google/go-cmp/cmp"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. type TestingT interface {
  9. Errorf(format string, args ...interface{})
  10. FailNow()
  11. Helper()
  12. }
  13. func Equal(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool {
  14. t.Helper()
  15. if cmp.Equal(expected, actual, cmp.Comparer(proto.Equal)) {
  16. return true
  17. }
  18. diff := cmp.Diff(expected, actual, cmp.Comparer(proto.Equal))
  19. return assert.Fail(t, fmt.Sprintf("Not equal: \n"+
  20. "expected: %s\n"+
  21. "actual : %s\n"+
  22. "diff : %s", expected, actual, diff), msgAndArgs)
  23. }
  24. func Equalf(t TestingT, expected, actual interface{}, msg string, args ...interface{}) bool {
  25. t.Helper()
  26. return Equal(t, expected, actual, append([]interface{}{msg}, args...)...)
  27. }