Ejemplo n.º 1
0
func TestJSONBuiltinEncoderFields(t *testing.T) {
	var m runtime.JSONBuiltin
	for _, fixt := range builtinFieldFixtures {
		var buf bytes.Buffer
		enc := m.NewEncoder(&buf)
		if err := enc.Encode(fixt.data); err != nil {
			t.Errorf("enc.Encode(%#v) failed with %v; want success", fixt.data, err)
		}

		if got, want := buf.String(), fixt.json+"\n"; got != want {
			t.Errorf("got = %q; want %q; data = %#v", got, want, fixt.data)
		}
	}
}
Ejemplo n.º 2
0
func TestJSONBuiltinEncoder(t *testing.T) {
	var m runtime.JSONBuiltin
	msg := examplepb.SimpleMessage{
		Id: "foo",
	}

	var buf bytes.Buffer
	enc := m.NewEncoder(&buf)
	if err := enc.Encode(&msg); err != nil {
		t.Errorf("enc.Encode(%v) failed with %v; want success", &msg, err)
	}

	var got examplepb.SimpleMessage
	if err := json.Unmarshal(buf.Bytes(), &got); err != nil {
		t.Errorf("json.Unmarshal(%q, &got) failed with %v; want success", buf.String(), err)
	}
	if want := msg; !reflect.DeepEqual(got, want) {
		t.Errorf("got = %v; want %v", &got, &want)
	}
}