Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package regression
- import (
- "bytes"
- "testing"
- "github.com/golang/protobuf/jsonpb"
- proto "github.com/golang/protobuf/proto"
- google_protobuf4 "github.com/golang/protobuf/ptypes/struct"
- )
- type Filter struct {
- Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
- Config *google_protobuf4.Struct `protobuf:"bytes,2,opt,name=config" json:"config,omitempty"`
- DeprecatedV1 *Filter_DeprecatedV1 `protobuf:"bytes,3,opt,name=deprecated_v1,json=deprecatedV1" json:"deprecated_v1,omitempty"`
- }
- func (m *Filter) Reset() { *m = Filter{} }
- func (m *Filter) String() string { return proto.CompactTextString(m) }
- func (*Filter) ProtoMessage() {}
- func (*Filter) Descriptor() ([]byte, []int) { return nil, nil }
- type Filter_DeprecatedV1 struct {
- Type string `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"`
- }
- func (m *Filter_DeprecatedV1) Reset() { *m = Filter_DeprecatedV1{} }
- func (m *Filter_DeprecatedV1) String() string { return proto.CompactTextString(m) }
- func (*Filter_DeprecatedV1) ProtoMessage() {}
- func (*Filter_DeprecatedV1) Descriptor() ([]byte, []int) { return nil, nil }
- var wantBytes = []byte(`{
- "name": "envoy.tcp_proxy",
- "config": {
- "value": {
- "stat_prefix": "outbound|tcp|80",
- "route_config": {
- "routes": [
- {
- "destination_ip_list": [
- "172.21.199.101/32"
- ],
- "cluster": "outbound|80||heapster.kube-system.svc.cluster.local"
- }
- ]
- }
- },
- "deprecated_v1": true
- }
- }`)
- func TestExtraWhiteSpace(t *testing.T) {
- filter := Filter{}
- jsonum := &jsonpb.Unmarshaler{}
- jsonum.Unmarshal(bytes.NewReader(wantBytes), &filter)
- jsonm := &jsonpb.Marshaler{Indent: " "}
- got := &bytes.Buffer{}
- jsonm.Marshal(got, &filter)
- // Not sure how you want to actually compare, I would usually use something like testify to get a diff
- if string(wantBytes) != got.String() {
- t.Errorf("Output didn't match input\nOutput:\n%v\nInput:\n%v", got.String(), string(wantBytes))
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement