Gomega Matchers for Protobufs
gproto
provides Gomega matchers to help write effective assertions against Protobufs.
Based on the EqualProto Matcher gomega issue, a Hyperledger Fabric review comment, and a equal_cmp_matcher.go Gist.
Installation
go get github.com/jt-nti/gproto
Usage
//...
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/jt-nti/gproto"
"google.golang.org/protobuf/types/known/timestamppb"
)
//...
Context("when something something protobuf", func() {
It("should match when the messages are equal", func() {
actual := ×tamppb.Timestamp{
Seconds: 1234567890,
}
expected := ×tamppb.Timestamp{
Seconds: 1234567890,
}
Expect(actual).To(gproto.Equal(expected))
})
It("should not match when the messages are not equal", func() {
actual := ×tamppb.Timestamp{
Seconds: 1234567890,
}
expected := ×tamppb.Timestamp{
Seconds: 9876543210,
}
Expect(actual).ToNot(gproto.Equal(expected))
})
})
//...
TODO
- Add more tests for more complex messages
- Add more matchers based on the following packages: