Skip to content

Commit

Permalink
Merge pull request #4 from DataDog/jprobinson/add-proto-support
Browse files Browse the repository at this point in the history
Adding support for Protobufs generated with v2 tooling
  • Loading branch information
jprobinson committed Sep 14, 2023
2 parents 181cea6 + d3f048e commit 7aa8226
Show file tree
Hide file tree
Showing 7 changed files with 899 additions and 54 deletions.
140 changes: 140 additions & 0 deletions assert/assertion_proto_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package assert

import (
"testing"

"github.com/stretchr/testify/internal/testproto"
)

func TestProtoObjectsAreEqual(t *testing.T) {
tests := []struct {
name string
givenExp interface{}
givenAct interface{}

want bool
}{
{
name: "proto v2 structs equal",
givenExp: &testproto.MessageV2{Field1: "hi"},
givenAct: &testproto.MessageV2{Field1: "hi"},

want: true,
},
{
name: "proto v2 structs not equal",
givenExp: &testproto.MessageV2{Field1: "hi"},
givenAct: &testproto.MessageV2{Field1: "hello"},

want: false,
},
{
name: "proto v2 struct slices equal",
givenExp: []*testproto.MessageV2{
{Field1: "hi"},
{Field1: "hello"},
{Field1: "howdy"},
{Field1: "bonjour"},
},
givenAct: []*testproto.MessageV2{
{Field1: "hi"},
{Field1: "hello"},
{Field1: "howdy"},
{Field1: "bonjour"},
},

want: true,
},
{
name: "proto v2 struct slices not equal",
givenExp: []*testproto.MessageV2{
{Field1: "hi"},
},
givenAct: []*testproto.MessageV2{
{Field1: "hi"},
{Field1: "hello"},
},

want: false,
},
{
name: "proto v1 structs",
givenExp: &testproto.MessageV1{Field1: "hi"},
givenAct: &testproto.MessageV1{Field1: "hi"},

want: true,
},
{
name: "proto v1 struct slices equal",
givenExp: []*testproto.MessageV1{
{Field1: "hi"},
},
givenAct: []*testproto.MessageV1{
{Field1: "hi"},
},

want: true,
},
{
name: "proto v1 struct slices not equal",
givenExp: []*testproto.MessageV1{
{Field1: "hi"},
},
givenAct: []*testproto.MessageV1{
{Field1: "hi"},
{Field1: "hello"},
},

want: false,
},
{
name: "proto gogo structs equal",
givenExp: &testproto.MessageGoGo{Field1: "hi"},
givenAct: &testproto.MessageGoGo{Field1: "hi"},

want: true,
},
{
name: "proto gogo structs not equal",
givenExp: &testproto.MessageGoGo{Field1: "hi"},
givenAct: &testproto.MessageGoGo{Field1: "hello"},

want: false,
},
{
name: "proto gogo struct slices equal",
givenExp: []*testproto.MessageGoGo{
{Field1: "hi"},
},
givenAct: []*testproto.MessageGoGo{
{Field1: "hi"},
},

want: true,
},
{
name: "proto gogo struct slices not equal",
givenExp: []*testproto.MessageGoGo{
{Field1: "hi"},
{Field1: "howdy"},
},
givenAct: []*testproto.MessageGoGo{
{Field1: "hi"},
{Field1: "hello"},
},

want: false,
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got := ObjectsAreEqual(test.givenExp, test.givenAct)
if got != test.want {
t.Errorf("wanted %t, got %t.\n\nExpected:\n%#v\n\nActual:\n%#v\n",
test.want, got, test.givenExp, test.givenAct)
}
})
}

}

0 comments on commit 7aa8226

Please sign in to comment.