| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be 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" | |
| 14 "github.com/luci/luci-go/common/tsmon/store" | |
| 15 "github.com/luci/luci-go/common/tsmon/target" | |
| 16 "github.com/luci/luci-go/common/tsmon/types" | 12 "github.com/luci/luci-go/common/tsmon/types" |
| 17 "golang.org/x/net/context" | 13 "golang.org/x/net/context" |
| 18 | 14 |
| 19 . "github.com/smartystreets/goconvey/convey" | 15 . "github.com/smartystreets/goconvey/convey" |
| 20 ) | 16 ) |
| 21 | 17 |
| 22 func makeContext() context.Context { | 18 func makeContext() context.Context { |
| 23 » return tsmon.WithState(context.Background(), &tsmon.State{ | 19 » ret, _ := tsmon.WithDummyInMemory(context.Background()) |
| 24 » » S: store.NewInMemory(&target.Task{ServiceName: p
roto.String("default target")}), | 20 » return ret |
| 25 » » M: monitor.NewNilMonitor(), | |
| 26 » » RegisteredMetrics: map[string]types.Metric{}, | |
| 27 » }) | |
| 28 } | 21 } |
| 29 | 22 |
| 30 func TestMetrics(t *testing.T) { | 23 func TestMetrics(t *testing.T) { |
| 31 Convey("Int", t, func() { | 24 Convey("Int", t, func() { |
| 32 c := makeContext() | 25 c := makeContext() |
| 33 m := NewIntIn(c, "foo", "description", types.MetricMetadata{}) | 26 m := NewIntIn(c, "foo", "description", types.MetricMetadata{}) |
| 34 | 27 |
| 35 v, err := m.Get(c) | 28 v, err := m.Get(c) |
| 36 So(v, ShouldEqual, 0) | 29 So(v, ShouldEqual, 0) |
| 37 So(err, ShouldBeNil) | 30 So(err, ShouldBeNil) |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 So(v.Bucketer().GrowthFactor(), ShouldEqual, 0) | 220 So(v.Bucketer().GrowthFactor(), ShouldEqual, 0) |
| 228 So(v.Bucketer().Width(), ShouldEqual, 10) | 221 So(v.Bucketer().Width(), ShouldEqual, 10) |
| 229 So(v.Bucketer().NumFiniteBuckets(), ShouldEqual, 20) | 222 So(v.Bucketer().NumFiniteBuckets(), ShouldEqual, 20) |
| 230 So(v.Sum(), ShouldEqual, 15) | 223 So(v.Sum(), ShouldEqual, 15) |
| 231 So(v.Count(), ShouldEqual, 1) | 224 So(v.Count(), ShouldEqual, 1) |
| 232 So(err, ShouldBeNil) | 225 So(err, ShouldBeNil) |
| 233 | 226 |
| 234 So(func() { NewNonCumulativeDistributionIn(c, "foo", "descriptio
n", types.MetricMetadata{}, m.Bucketer()) }, ShouldPanic) | 227 So(func() { NewNonCumulativeDistributionIn(c, "foo", "descriptio
n", types.MetricMetadata{}, m.Bucketer()) }, ShouldPanic) |
| 235 }) | 228 }) |
| 236 } | 229 } |
| OLD | NEW |