File: jsonpb_gogo_test.go

package info (click to toggle)
golang-gogoprotobuf 1.0.0%2Bgit20180330.1ef32a8b-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 15,932 kB
  • sloc: makefile: 462; sh: 23
file content (36 lines) | stat: -rw-r--r-- 841 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package jsonpb_gogo

import (
	"testing"

	"github.com/gogo/protobuf/jsonpb"
)

// customFieldMessage implements protobuf.Message but is not a normal generated message type.
type customFieldMessage struct {
	someField string //this is not a proto field
}

func (m *customFieldMessage) Reset() {
	m.someField = "hello"
}

func (m *customFieldMessage) String() string {
	return m.someField
}

func (m *customFieldMessage) ProtoMessage() {
}

func TestUnmarshalWithJSONPBUnmarshaler(t *testing.T) {
	rawJson := `{}`
	marshaler := &jsonpb.Marshaler{}
	msg := &customFieldMessage{someField: "Ignore me"}
	str, err := marshaler.MarshalToString(msg)
	if err != nil {
		t.Errorf("an unexpected error occurred when marshaling message: %v", err)
	}
	if str != rawJson {
		t.Errorf("marshaled JSON was incorrect: got %s, wanted %s", str, rawJson)
	}
}