| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 package field | 4 package field |
| 5 | 5 |
| 6 import ( | 6 import ( |
| 7 "fmt" | 7 "fmt" |
| 8 "testing" | 8 "testing" |
| 9 | 9 |
| 10 "github.com/golang/protobuf/proto" |
| 11 |
| 10 pb "github.com/luci/luci-go/common/tsmon/ts_mon_proto" | 12 pb "github.com/luci/luci-go/common/tsmon/ts_mon_proto" |
| 11 | 13 |
| 12 . "github.com/smartystreets/goconvey/convey" | 14 . "github.com/smartystreets/goconvey/convey" |
| 13 ) | 15 ) |
| 14 | 16 |
| 15 func TestSerialize(t *testing.T) { | 17 func TestSerialize(t *testing.T) { |
| 16 data := []struct { | 18 data := []struct { |
| 17 fields []Field | 19 fields []Field |
| 18 values []interface{} | 20 values []interface{} |
| 19 want []*pb.MetricsField | 21 want []*pb.MetricsField |
| 20 }{ | 22 }{ |
| 21 { | 23 { |
| 22 fields: []Field{String("foo")}, | 24 fields: []Field{String("foo")}, |
| 23 values: makeInterfaceSlice("v"), | 25 values: makeInterfaceSlice("v"), |
| 24 want: []*pb.MetricsField{ | 26 want: []*pb.MetricsField{ |
| 25 { | 27 { |
| 26 » » » » » Name: "foo", | 28 » » » » » Name: proto.String("foo"), |
| 27 » » » » » Type: pb.MetricsField_STRING, | 29 » » » » » Type: pb.MetricsField_STRING.Enum
(), |
| 28 » » » » » StringValue: "v", | 30 » » » » » StringValue: proto.String("v"), |
| 29 }, | 31 }, |
| 30 }, | 32 }, |
| 31 }, | 33 }, |
| 32 { | 34 { |
| 33 fields: []Field{Int("foo")}, | 35 fields: []Field{Int("foo")}, |
| 34 values: makeInterfaceSlice(int64(123)), | 36 values: makeInterfaceSlice(int64(123)), |
| 35 want: []*pb.MetricsField{ | 37 want: []*pb.MetricsField{ |
| 36 { | 38 { |
| 37 » » » » » Name: "foo", | 39 » » » » » Name: proto.String("foo"), |
| 38 » » » » » Type: pb.MetricsField_INT, | 40 » » » » » Type: pb.MetricsField_INT.Enum(), |
| 39 » » » » » IntValue: 123, | 41 » » » » » IntValue: proto.Int64(123), |
| 40 }, | 42 }, |
| 41 }, | 43 }, |
| 42 }, | 44 }, |
| 43 { | 45 { |
| 44 fields: []Field{Bool("foo")}, | 46 fields: []Field{Bool("foo")}, |
| 45 values: makeInterfaceSlice(true), | 47 values: makeInterfaceSlice(true), |
| 46 want: []*pb.MetricsField{ | 48 want: []*pb.MetricsField{ |
| 47 { | 49 { |
| 48 » » » » » Name: "foo", | 50 » » » » » Name: proto.String("foo"), |
| 49 » » » » » Type: pb.MetricsField_BOOL, | 51 » » » » » Type: pb.MetricsField_BOOL.Enum(), |
| 50 » » » » » BoolValue: true, | 52 » » » » » BoolValue: proto.Bool(true), |
| 51 }, | 53 }, |
| 52 }, | 54 }, |
| 53 }, | 55 }, |
| 54 } | 56 } |
| 55 | 57 |
| 56 for i, d := range data { | 58 for i, d := range data { |
| 57 Convey(fmt.Sprintf("%d. Serialize(%v, %v)", i, d.fields, d.value
s), t, func() { | 59 Convey(fmt.Sprintf("%d. Serialize(%v, %v)", i, d.fields, d.value
s), t, func() { |
| 58 got := Serialize(d.fields, d.values) | 60 got := Serialize(d.fields, d.values) |
| 59 So(got, ShouldResemble, d.want) | 61 So(got, ShouldResemble, d.want) |
| 60 }) | 62 }) |
| 61 } | 63 } |
| 62 } | 64 } |
| OLD | NEW |