Skip to content

Commit

Permalink
proto: move explicit test as a seed into the fuzz test
Browse files Browse the repository at this point in the history
fuzztest seeds are executed as part of `go test` so there is no need for
an explicit test and having this as a seed in the fuzztest is sufficient
to get test coverage for this case.

Change-Id: Ia4a2d721e544e1a1ad0ad3ef9aa9d0af6bfe2db8
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/567755
Auto-Submit: Lasse Folger <lassefolger@google.com>
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
  • Loading branch information
lfolger authored and gopherbot committed Feb 28, 2024
1 parent 02e13d2 commit 6bec1ef
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions proto/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,6 @@ import (
testfuzzpb "google.golang.org/protobuf/internal/testprotos/editionsfuzztest"
)

func TestUnmarshalInvalidGroupField(t *testing.T) {
in := []byte("\x82\x01\x010")
// Test proto2 proto
proto2Proto := &testfuzzpb.TestAllTypesProto2{}

if err := proto.Unmarshal(in, proto2Proto); err != nil {
t.Error(err)
}
// Test equivalent editions proto
editionsProto := &testfuzzpb.TestAllTypesProto2Editions{}

if err := proto.Unmarshal(in, editionsProto); err != nil {
t.Error(err)
}
}

// compareEquivalentProtos compares equivalent messages m0 and m1, where one is
// typically a Protobuf Editions message and the other isn't. It unmarshals the
// wireBytes into a message of type m0 and one of type m1 and compares the
Expand Down Expand Up @@ -87,13 +71,15 @@ func compareEquivalentProtos(t *testing.T, wireBytes []byte, m0, m1 proto.Messag

func FuzzProto2EditionConversion(f *testing.F) {
f.Add([]byte("Hello World!"))
f.Add([]byte("\x82\x01\x010"))
f.Fuzz(func(t *testing.T, in []byte) {
compareEquivalentProtos(t, in, (*testfuzzpb.TestAllTypesProto2)(nil), (*testfuzzpb.TestAllTypesProto2Editions)(nil))
})
}

func FuzzProto3EditionConversion(f *testing.F) {
f.Add([]byte("Hello World!"))
f.Add([]byte("\x82\x01\x010"))
f.Fuzz(func(t *testing.T, in []byte) {
compareEquivalentProtos(t, in, (*testfuzzpb.TestAllTypesProto3)(nil), (*testfuzzpb.TestAllTypesProto3Editions)(nil))
})
Expand Down

0 comments on commit 6bec1ef

Please sign in to comment.