Documentation ¶
Index ¶
- func Counter(t testingT, n string, m interface{}) bool
- func Gauge(t testingT, n string, m interface{}) bool
- func Histogram(t testingT, n string, m interface{}) bool
- func Minimum(expected float64) expectation
- func NewCounter(name string) metrics.Counter
- func NewGauge(name string) metrics.Gauge
- func NewHistogram(name string, buckets int) metrics.Histogram
- func NewMetric(m xmetrics.Metric) (interface{}, error)
- func Value(expected float64) expectation
- type LVKey
- type Labeled
- type Provider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Counter ¶
Counter is an expectation that a certain metric is a counter. It must implement the go-kit metrics.Counter interface.
func Gauge ¶
Gauge is an expectation that a certain metric is a gauge. It must implement the go-kit metrics.Gauge interface.
func Histogram ¶
Histogram is an expectation that a certain metric is a histogram. It must implement the go-kit metrics.Histogram interface.
func Minimum ¶
func Minimum(expected float64) expectation
Minimum returns an expectation for a metric to be at least a certain value. The metric in question must implement xmetrics.Valuer, as with the Value expectation.
func NewCounter ¶
func NewMetric ¶
NewMetric creates the appropriate go-kit metrics/generic metric from the supplied descriptor. Both summaries and histograms result in *generic.Histogram instances. If the returned error is nil, the returned metric will always be one of the metrics/generic types.
Only the metric Name is used. Namespace and subsystem are not applied by this factory function.
func Value ¶
func Value(expected float64) expectation
Value returns an expectation for a metric to be of a certain value. The metric in question must implement xmetrics.Valuer, which both counter and gauge do. This assertion does not constrain the type of metric beyond simply exposing a value. Use another expectation to assert that a metric is of a more specific type.
Types ¶
type LVKey ¶
type LVKey string
LVKey represents a canonicalized key for a set of label/value pairs.
type Labeled ¶
type Labeled interface { // Get returns the nested metric associated with a set of label/value pairs, creating one if no such metric exists. // If the given key represents the root key, this same instance is returned. Get(LVKey) interface{} }
Labeled provides access to a metric's labeled "children".
type Provider ¶
type Provider interface { provider.Provider // Expect associates an expectation with a metric. The optional list of labels and values will // examine any nested metric instead of the root metric. This method uses a Fluent Builder style: // // provider.Expect("counter")(xmetricstest.Counter, xmetricstest.Value(1.0)). // Expect("not_found", "code", "404")(xmetricstest.Counter) // // The returned closure is used to attach expectations to the metric identified by the name and // optional label/value pairs. Expect(string, ...string) func(...expectation) Provider // Assert executes an assertion against this provider immediately, without adding it to the // set of expectations asserted via AssertExpectations. Assert(testingT, string, ...string) func(...expectation) bool // AssertExpectations verifies all expectations. It returns true if and only if all // expectations pass or if there were no expectations set. AssertExpectations(testingT) bool }
Provider is a testing implementation of go-kit's provider.Provider. Additionally, it provides assertion and expectation functionality.
func NewProvider ¶
NewProvider returns a testing Provider instance, using a similar merging algorithm as used by xmetrics.NewRegistry. Namespace and subsystem are not used to determine metric uniqueness, which is normally fine since an application tends to use one pair of (namespace, subsystem) for all its metrics.
The returned object may be used as a go-kit provider.Provider for testing application code. Additionally, it may also be used to set expectations and do assertions on the recorded metrics. At this time, label values *are not supported*.
If this function is unable to merge configuration into a Provider, it panics. The Provider will be usable if no options or modules are passed. Passing configuration is only necessary if the actual production configuration is being tested.