2019-04-05 20:31:40 +00:00
|
|
|
// Copyright 2019 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style.
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package proto_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2019-05-14 06:55:40 +00:00
|
|
|
"google.golang.org/protobuf/proto"
|
2019-04-05 20:31:40 +00:00
|
|
|
|
2019-05-14 06:55:40 +00:00
|
|
|
testpb "google.golang.org/protobuf/internal/testprotos/test"
|
2019-04-05 20:31:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestIsInitializedErrors(t *testing.T) {
|
|
|
|
for _, test := range []struct {
|
|
|
|
m proto.Message
|
|
|
|
want string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
&testpb.TestRequired{},
|
2019-07-09 18:40:49 +00:00
|
|
|
`proto: required field goproto.proto.test.TestRequired.required_field not set`,
|
2019-04-05 20:31:40 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&testpb.TestRequiredForeign{
|
|
|
|
OptionalMessage: &testpb.TestRequired{},
|
|
|
|
},
|
2019-07-09 18:40:49 +00:00
|
|
|
`proto: required field goproto.proto.test.TestRequired.required_field not set`,
|
2019-04-05 20:31:40 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&testpb.TestRequiredForeign{
|
|
|
|
RepeatedMessage: []*testpb.TestRequired{
|
2019-07-10 23:17:16 +00:00
|
|
|
{RequiredField: proto.Int32(1)},
|
2019-04-05 20:31:40 +00:00
|
|
|
{},
|
|
|
|
},
|
|
|
|
},
|
2019-07-09 18:40:49 +00:00
|
|
|
`proto: required field goproto.proto.test.TestRequired.required_field not set`,
|
2019-04-05 20:31:40 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
&testpb.TestRequiredForeign{
|
|
|
|
MapMessage: map[int32]*testpb.TestRequired{
|
|
|
|
1: {},
|
|
|
|
},
|
|
|
|
},
|
2019-07-09 18:40:49 +00:00
|
|
|
`proto: required field goproto.proto.test.TestRequired.required_field not set`,
|
2019-04-05 20:31:40 +00:00
|
|
|
},
|
|
|
|
} {
|
|
|
|
err := proto.IsInitialized(test.m)
|
|
|
|
got := "<nil>"
|
|
|
|
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))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|