all: make error messages unstable
Use internal/detrand in the construction of our error messages.
This alters whether there is one or two spaces following the "proto:" prefix.
While it is easy for users to still work around this mutation,
sit at least forces them to write test infrastructure to more fuzzily
match on error strings.
Change-Id: I4ddca717526ee3fc4dbb1e0b36cfca8c6e0df36d
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/194038
Reviewed-by: Herbie Ong <herbie@google.com>
diff --git a/proto/isinit_test.go b/proto/isinit_test.go
index 72dd108..d935d3a 100644
--- a/proto/isinit_test.go
+++ b/proto/isinit_test.go
@@ -6,6 +6,7 @@
import (
"fmt"
+ "strings"
"testing"
"google.golang.org/protobuf/proto"
@@ -20,13 +21,13 @@
}{
{
&testpb.TestRequired{},
- `proto: required field goproto.proto.test.TestRequired.required_field not set`,
+ `goproto.proto.test.TestRequired.required_field`,
},
{
&testpb.TestRequiredForeign{
OptionalMessage: &testpb.TestRequired{},
},
- `proto: required field goproto.proto.test.TestRequired.required_field not set`,
+ `goproto.proto.test.TestRequired.required_field`,
},
{
&testpb.TestRequiredForeign{
@@ -35,7 +36,7 @@
{},
},
},
- `proto: required field goproto.proto.test.TestRequired.required_field not set`,
+ `goproto.proto.test.TestRequired.required_field`,
},
{
&testpb.TestRequiredForeign{
@@ -43,7 +44,7 @@
1: {},
},
},
- `proto: required field goproto.proto.test.TestRequired.required_field not set`,
+ `goproto.proto.test.TestRequired.required_field`,
},
} {
err := proto.IsInitialized(test.m)
@@ -51,9 +52,8 @@
if err != nil {
got = fmt.Sprintf("%q", err)
}
- want := fmt.Sprintf("%q", test.want)
- if got != want {
- t.Errorf("IsInitialized(m):\n got: %v\nwant: %v\nMessage:\n%v", got, want, marshalText(test.m))
+ if !strings.Contains(got, test.want) {
+ t.Errorf("IsInitialized(m):\n got: %v\nwant contains: %v\nMessage:\n%v", got, test.want, marshalText(test.m))
}
}
}