Forráskód Böngészése

proto: robustify tests that compare error messages (#500)

For now, use fmt.Sprintf to get the proper type name that is
agnostic to the package that the type is defined in.
However, in the future, we should avoid such brittle testing
and have more distinguishable errors.
Joe Tsai 8 éve
szülő
commit
57af8637f0
2 módosított fájl, 5 hozzáadás és 4 törlés
  1. 2 2
      proto/extensions_test.go
  2. 3 2
      proto/text_parser_test.go

+ 2 - 2
proto/extensions_test.go

@@ -97,7 +97,7 @@ func TestGetExtensionForIncompleteDesc(t *testing.T) {
 		Name:          "a.c",
 		Name:          "a.c",
 		Tag:           "bytes,123456790,opt",
 		Tag:           "bytes,123456790,opt",
 	}
 	}
-	ext2 := []byte{0,1,2,3,4,5,6,7}
+	ext2 := []byte{0, 1, 2, 3, 4, 5, 6, 7}
 	if err := proto.SetExtension(msg, extdesc2, ext2); err != nil {
 	if err := proto.SetExtension(msg, extdesc2, ext2); err != nil {
 		t.Fatalf("Could not set ext2: %s", err)
 		t.Fatalf("Could not set ext2: %s", err)
 	}
 	}
@@ -479,7 +479,7 @@ func TestNilExtension(t *testing.T) {
 	}
 	}
 	if err := proto.SetExtension(msg, pb.E_Ext_More, (*pb.Ext)(nil)); err == nil {
 	if err := proto.SetExtension(msg, pb.E_Ext_More, (*pb.Ext)(nil)); err == nil {
 		t.Error("expected SetExtension to fail due to a nil extension")
 		t.Error("expected SetExtension to fail due to a nil extension")
-	} else if want := "proto: SetExtension called with nil value of type *test_proto.Ext"; err.Error() != want {
+	} else if want := fmt.Sprintf("proto: SetExtension called with nil value of type %T", new(pb.Ext)); err.Error() != want {
 		t.Errorf("expected error %v, got %v", want, err)
 		t.Errorf("expected error %v, got %v", want, err)
 	}
 	}
 	// Note: if the behavior of Marshal is ever changed to ignore nil extensions, update
 	// Note: if the behavior of Marshal is ever changed to ignore nil extensions, update

+ 3 - 2
proto/text_parser_test.go

@@ -32,6 +32,7 @@
 package proto_test
 package proto_test
 
 
 import (
 import (
+	"fmt"
 	"math"
 	"math"
 	"testing"
 	"testing"
 
 
@@ -362,7 +363,7 @@ var unMarshalTextTests = []UnmarshalTextTest{
 	// Missing required field
 	// Missing required field
 	{
 	{
 		in:  `name: "Pawel"`,
 		in:  `name: "Pawel"`,
-		err: `proto: required field "test_proto.MyMessage.count" not set`,
+		err: fmt.Sprintf(`proto: required field "%T.count" not set`, MyMessage{}),
 		out: &MyMessage{
 		out: &MyMessage{
 			Name: String("Pawel"),
 			Name: String("Pawel"),
 		},
 		},
@@ -371,7 +372,7 @@ var unMarshalTextTests = []UnmarshalTextTest{
 	// Missing required field in a required submessage
 	// Missing required field in a required submessage
 	{
 	{
 		in:  `count: 42 we_must_go_deeper < leo_finally_won_an_oscar <> >`,
 		in:  `count: 42 we_must_go_deeper < leo_finally_won_an_oscar <> >`,
-		err: `proto: required field "test_proto.InnerMessage.host" not set`,
+		err: fmt.Sprintf(`proto: required field "%T.host" not set`, InnerMessage{}),
 		out: &MyMessage{
 		out: &MyMessage{
 			Count:          Int32(42),
 			Count:          Int32(42),
 			WeMustGoDeeper: &RequiredInnerMessage{LeoFinallyWonAnOscar: &InnerMessage{}},
 			WeMustGoDeeper: &RequiredInnerMessage{LeoFinallyWonAnOscar: &InnerMessage{}},