daily pastebin goal
7%
SHARE
TWEET

Untitled

a guest Jun 8th, 2018 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package regression
  2.  
  3. import (
  4.     "bytes"
  5.     "testing"
  6.  
  7.     "github.com/golang/protobuf/jsonpb"
  8.     proto "github.com/golang/protobuf/proto"
  9.     google_protobuf4 "github.com/golang/protobuf/ptypes/struct"
  10. )
  11.  
  12. type Filter struct {
  13.     Name         string                   `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
  14.     Config       *google_protobuf4.Struct `protobuf:"bytes,2,opt,name=config" json:"config,omitempty"`
  15.     DeprecatedV1 *Filter_DeprecatedV1     `protobuf:"bytes,3,opt,name=deprecated_v1,json=deprecatedV1" json:"deprecated_v1,omitempty"`
  16. }
  17.  
  18. func (m *Filter) Reset()                    { *m = Filter{} }
  19. func (m *Filter) String() string            { return proto.CompactTextString(m) }
  20. func (*Filter) ProtoMessage()               {}
  21. func (*Filter) Descriptor() ([]byte, []int) { return nil, nil }
  22.  
  23. type Filter_DeprecatedV1 struct {
  24.     Type string `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"`
  25. }
  26.  
  27. func (m *Filter_DeprecatedV1) Reset()                    { *m = Filter_DeprecatedV1{} }
  28. func (m *Filter_DeprecatedV1) String() string            { return proto.CompactTextString(m) }
  29. func (*Filter_DeprecatedV1) ProtoMessage()               {}
  30. func (*Filter_DeprecatedV1) Descriptor() ([]byte, []int) { return nil, nil }
  31.  
  32. var wantBytes = []byte(`{
  33.     "name": "envoy.tcp_proxy",
  34.     "config": {
  35.         "value": {
  36.             "stat_prefix": "outbound|tcp|80",
  37.             "route_config": {
  38.                 "routes": [
  39.                     {
  40.                         "destination_ip_list": [
  41.                             "172.21.199.101/32"
  42.                         ],
  43.                         "cluster": "outbound|80||heapster.kube-system.svc.cluster.local"
  44.                     }
  45.                 ]
  46.             }
  47.         },
  48.         "deprecated_v1": true
  49.     }
  50. }`)
  51.  
  52. func TestExtraWhiteSpace(t *testing.T) {
  53.     filter := Filter{}
  54.     jsonum := &jsonpb.Unmarshaler{}
  55.     jsonum.Unmarshal(bytes.NewReader(wantBytes), &filter)
  56.  
  57.     jsonm := &jsonpb.Marshaler{Indent: "    "}
  58.     got := &bytes.Buffer{}
  59.     jsonm.Marshal(got, &filter)
  60.  
  61.     // Not sure how you want to actually compare, I would usually use something like testify to get a diff
  62.     if string(wantBytes) != got.String() {
  63.         t.Errorf("Output didn't match input\nOutput:\n%v\nInput:\n%v", got.String(), string(wantBytes))
  64.     }
  65. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top