Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ShouldResemble for proto messages #664

Open
antoniomacri opened this issue Jun 8, 2022 · 1 comment
Open

ShouldResemble for proto messages #664

antoniomacri opened this issue Jun 8, 2022 · 1 comment

Comments

@antoniomacri
Copy link

Comparison of proto Messages performed using ShouldResemble is unreliable.

Consider this code:

package main

import (
	. "github.com/smartystreets/goconvey/convey"
	"google.golang.org/protobuf/types/known/wrapperspb"
	"log"
	"testing"
)

func TestConveyBug(t *testing.T) {
	Convey("Given something", t, func() {
		var x = &wrapperspb.BoolValue{Value: false}
		var y = &wrapperspb.BoolValue{Value: false}
		log.Printf("Receive type %v", x)

		So(x, ShouldResemble, y)
	})
}

The call to Printf causes x.String() to be called. This in turn initializes the state and its atomicMessageInfo field on the proto message. Therefore x has the atomicMessageInfo set, while y doesn't. This causes reflect.DeepEqual to return false.

Another problem stems from the rendering of the diff (#660).

Could a ShouldResembleProto be added for expliciting comparing proto messages? It should call proto.Equal.

@srabraham
Copy link
Contributor

Hey Antonio, note that you can define your own ShouldResembleProto and use that with GoConvey. That's exactly what the Chrome infrastructure team has done, as they're big users of GoConvey and of Protocol Buffers. I'd be curious for @riannucci to chime in, but it might be weird for GoConvey to pull in the protobuf repo as a dependency to make this natively supported.

Have a look at these:
definition of ShouldResembleProto: https://chromium.googlesource.com/infra/luci/luci-go/+/3809e3303d0b/common/testing/assertions/proto_tests.go#37
example usage of that function: https://chromium.googlesource.com/infra/luci/luci-go/+/3809e3303d0b/auth_service/impl/servers/accounts/server_test.go#43

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants