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