Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jsonpb: update tests to reflect new jsonpb behavior #401

Merged
merged 1 commit into from
May 30, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions runtime/marshal_jsonpb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ import (

func TestJSONPbMarshal(t *testing.T) {
msg := examplepb.ABitOfEverything{
Uuid: "6EC2446F-7E89-4127-B3E6-5C05E6BECBA7",
SingleNested: &examplepb.ABitOfEverything_Nested{},
RepeatedStringValue: []string{},
MappedStringValue: map[string]string{},
MappedNestedValue: map[string]*examplepb.ABitOfEverything_Nested{},
RepeatedEnumValue: []examplepb.NumericEnum{},
TimestampValue: &timestamp.Timestamp{},
Uuid: "6EC2446F-7E89-4127-B3E6-5C05E6BECBA7",
Nested: []*examplepb.ABitOfEverything_Nested{
{
Name: "foo",
Expand All @@ -37,7 +43,7 @@ func TestJSONPbMarshal(t *testing.T) {
},
}

for _, spec := range []struct {
for i, spec := range []struct {
enumsAsInts, emitDefaults bool
indent string
origName bool
Expand Down Expand Up @@ -105,7 +111,7 @@ func TestJSONPbMarshal(t *testing.T) {
t.Errorf("jsonpb.UnmarshalString(%q, &got) failed with %v; want success; spec=%v", string(buf), err, spec)
}
if want := msg; !reflect.DeepEqual(got, want) {
t.Errorf("got = %v; want %v; spec=%v", &got, &want, spec)
t.Errorf("case %d: got = %v; want %v; spec=%v", i, &got, &want, spec)
}
if spec.verifier != nil {
spec.verifier(string(buf))
Expand Down Expand Up @@ -143,7 +149,7 @@ func TestJSONPbUnmarshal(t *testing.T) {
m runtime.JSONPb
got examplepb.ABitOfEverything
)
for _, data := range []string{
for i, data := range []string{
`{
"uuid": "6EC2446F-7E89-4127-B3E6-5C05E6BECBA7",
"nested": [
Expand Down Expand Up @@ -185,7 +191,7 @@ func TestJSONPbUnmarshal(t *testing.T) {
}`,
} {
if err := m.Unmarshal([]byte(data), &got); err != nil {
t.Errorf("m.Unmarshal(%q, &got) failed with %v; want success", data, err)
t.Errorf("case %d: m.Unmarshal(%q, &got) failed with %v; want success", i, data, err)
}

want := examplepb.ABitOfEverything{
Expand All @@ -208,7 +214,7 @@ func TestJSONPbUnmarshal(t *testing.T) {
}

if !reflect.DeepEqual(got, want) {
t.Errorf("got = %v; want = %v", &got, &want)
t.Errorf("case %d: got = %v; want = %v", i, &got, &want)
}
}
}
Expand All @@ -232,7 +238,13 @@ func TestJSONPbUnmarshalFields(t *testing.T) {

func TestJSONPbEncoder(t *testing.T) {
msg := examplepb.ABitOfEverything{
Uuid: "6EC2446F-7E89-4127-B3E6-5C05E6BECBA7",
SingleNested: &examplepb.ABitOfEverything_Nested{},
RepeatedStringValue: []string{},
MappedStringValue: map[string]string{},
MappedNestedValue: map[string]*examplepb.ABitOfEverything_Nested{},
RepeatedEnumValue: []examplepb.NumericEnum{},
TimestampValue: &timestamp.Timestamp{},
Uuid: "6EC2446F-7E89-4127-B3E6-5C05E6BECBA7",
Nested: []*examplepb.ABitOfEverything_Nested{
{
Name: "foo",
Expand All @@ -249,7 +261,7 @@ func TestJSONPbEncoder(t *testing.T) {
},
}

for _, spec := range []struct {
for i, spec := range []struct {
enumsAsInts, emitDefaults bool
indent string
origName bool
Expand Down Expand Up @@ -319,7 +331,7 @@ func TestJSONPbEncoder(t *testing.T) {
t.Errorf("jsonpb.UnmarshalString(%q, &got) failed with %v; want success; spec=%v", buf.String(), err, spec)
}
if want := msg; !reflect.DeepEqual(got, want) {
t.Errorf("got = %v; want %v; spec=%v", &got, &want, spec)
t.Errorf("case %d: got = %v; want %v; spec=%v", i, &got, &want, spec)
}
if spec.verifier != nil {
spec.verifier(buf.String())
Expand Down