| 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 | |
| 12 pb "github.com/luci/luci-go/common/tsmon/ts_mon_proto" | 10 pb "github.com/luci/luci-go/common/tsmon/ts_mon_proto" |
| 13 | 11 |
| 14 . "github.com/smartystreets/goconvey/convey" | 12 . "github.com/smartystreets/goconvey/convey" |
| 15 ) | 13 ) |
| 16 | 14 |
| 17 func TestSerialize(t *testing.T) { | 15 func TestSerialize(t *testing.T) { |
| 18 data := []struct { | 16 data := []struct { |
| 19 fields []Field | 17 fields []Field |
| 20 values []interface{} | 18 values []interface{} |
| 21 want []*pb.MetricsField | 19 want []*pb.MetricsField |
| 22 }{ | 20 }{ |
| 23 { | 21 { |
| 24 fields: []Field{String("foo")}, | 22 fields: []Field{String("foo")}, |
| 25 values: makeInterfaceSlice("v"), | 23 values: makeInterfaceSlice("v"), |
| 26 want: []*pb.MetricsField{ | 24 want: []*pb.MetricsField{ |
| 27 { | 25 { |
| 28 » » » » » Name: proto.String("foo"), | 26 » » » » » Name: "foo", |
| 29 » » » » » Type: pb.MetricsField_STRING.Enum
(), | 27 » » » » » Type: pb.MetricsField_STRING, |
| 30 » » » » » StringValue: proto.String("v"), | 28 » » » » » StringValue: "v", |
| 31 }, | 29 }, |
| 32 }, | 30 }, |
| 33 }, | 31 }, |
| 34 { | 32 { |
| 35 fields: []Field{Int("foo")}, | 33 fields: []Field{Int("foo")}, |
| 36 values: makeInterfaceSlice(int64(123)), | 34 values: makeInterfaceSlice(int64(123)), |
| 37 want: []*pb.MetricsField{ | 35 want: []*pb.MetricsField{ |
| 38 { | 36 { |
| 39 » » » » » Name: proto.String("foo"), | 37 » » » » » Name: "foo", |
| 40 » » » » » Type: pb.MetricsField_INT.Enum(), | 38 » » » » » Type: pb.MetricsField_INT, |
| 41 » » » » » IntValue: proto.Int64(123), | 39 » » » » » IntValue: 123, |
| 42 }, | 40 }, |
| 43 }, | 41 }, |
| 44 }, | 42 }, |
| 45 { | 43 { |
| 46 fields: []Field{Bool("foo")}, | 44 fields: []Field{Bool("foo")}, |
| 47 values: makeInterfaceSlice(true), | 45 values: makeInterfaceSlice(true), |
| 48 want: []*pb.MetricsField{ | 46 want: []*pb.MetricsField{ |
| 49 { | 47 { |
| 50 » » » » » Name: proto.String("foo"), | 48 » » » » » Name: "foo", |
| 51 » » » » » Type: pb.MetricsField_BOOL.Enum(), | 49 » » » » » Type: pb.MetricsField_BOOL, |
| 52 » » » » » BoolValue: proto.Bool(true), | 50 » » » » » BoolValue: true, |
| 53 }, | 51 }, |
| 54 }, | 52 }, |
| 55 }, | 53 }, |
| 56 } | 54 } |
| 57 | 55 |
| 58 for i, d := range data { | 56 for i, d := range data { |
| 59 Convey(fmt.Sprintf("%d. Serialize(%v, %v)", i, d.fields, d.value
s), t, func() { | 57 Convey(fmt.Sprintf("%d. Serialize(%v, %v)", i, d.fields, d.value
s), t, func() { |
| 60 got := Serialize(d.fields, d.values) | 58 got := Serialize(d.fields, d.values) |
| 61 So(got, ShouldResemble, d.want) | 59 So(got, ShouldResemble, d.want) |
| 62 }) | 60 }) |
| 63 } | 61 } |
| 64 } | 62 } |
| OLD | NEW |