| 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 | 4 |
| 5 package metric | 5 package metric |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "testing" | 8 "testing" |
| 9 | 9 |
| 10 "github.com/golang/protobuf/proto" |
| 10 "github.com/luci/luci-go/common/tsmon" | 11 "github.com/luci/luci-go/common/tsmon" |
| 11 "github.com/luci/luci-go/common/tsmon/distribution" | 12 "github.com/luci/luci-go/common/tsmon/distribution" |
| 12 "github.com/luci/luci-go/common/tsmon/monitor" | 13 "github.com/luci/luci-go/common/tsmon/monitor" |
| 13 "github.com/luci/luci-go/common/tsmon/store" | 14 "github.com/luci/luci-go/common/tsmon/store" |
| 14 "github.com/luci/luci-go/common/tsmon/target" | 15 "github.com/luci/luci-go/common/tsmon/target" |
| 15 "github.com/luci/luci-go/common/tsmon/types" | 16 "github.com/luci/luci-go/common/tsmon/types" |
| 16 "golang.org/x/net/context" | 17 "golang.org/x/net/context" |
| 17 | 18 |
| 18 . "github.com/smartystreets/goconvey/convey" | 19 . "github.com/smartystreets/goconvey/convey" |
| 19 ) | 20 ) |
| 20 | 21 |
| 21 func makeContext() context.Context { | 22 func makeContext() context.Context { |
| 22 return tsmon.WithState(context.Background(), &tsmon.State{ | 23 return tsmon.WithState(context.Background(), &tsmon.State{ |
| 23 » » S: store.NewInMemory(&target.Task{ServiceName: "
default target"}), | 24 » » S: store.NewInMemory(&target.Task{ServiceName: p
roto.String("default target")}), |
| 24 M: monitor.NewNilMonitor(), | 25 M: monitor.NewNilMonitor(), |
| 25 RegisteredMetrics: map[string]types.Metric{}, | 26 RegisteredMetrics: map[string]types.Metric{}, |
| 26 }) | 27 }) |
| 27 } | 28 } |
| 28 | 29 |
| 29 func TestMetrics(t *testing.T) { | 30 func TestMetrics(t *testing.T) { |
| 30 Convey("Int", t, func() { | 31 Convey("Int", t, func() { |
| 31 c := makeContext() | 32 c := makeContext() |
| 32 m := NewIntIn(c, "foo", "description") | 33 m := NewIntIn(c, "foo", "description") |
| 33 | 34 |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 So(v.Bucketer().GrowthFactor(), ShouldEqual, 0) | 227 So(v.Bucketer().GrowthFactor(), ShouldEqual, 0) |
| 227 So(v.Bucketer().Width(), ShouldEqual, 10) | 228 So(v.Bucketer().Width(), ShouldEqual, 10) |
| 228 So(v.Bucketer().NumFiniteBuckets(), ShouldEqual, 20) | 229 So(v.Bucketer().NumFiniteBuckets(), ShouldEqual, 20) |
| 229 So(v.Sum(), ShouldEqual, 15) | 230 So(v.Sum(), ShouldEqual, 15) |
| 230 So(v.Count(), ShouldEqual, 1) | 231 So(v.Count(), ShouldEqual, 1) |
| 231 So(err, ShouldBeNil) | 232 So(err, ShouldBeNil) |
| 232 | 233 |
| 233 So(func() { NewNonCumulativeDistributionIn(c, "foo", "descriptio
n", m.Bucketer()) }, ShouldPanic) | 234 So(func() { NewNonCumulativeDistributionIn(c, "foo", "descriptio
n", m.Bucketer()) }, ShouldPanic) |
| 234 }) | 235 }) |
| 235 } | 236 } |
| OLD | NEW |