promtest

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 10, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package promtest provides a mock implementation of a Prometheus HTTP client for testing purposes and some utility functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateSample

func CreateSample(labels map[string]string, value float64, t model.Time) *model.Sample

CreateSample returns a reference to a new model.Sample having labels, value and timestamp passed as arguments.

Types

type PromClient

type PromClient interface {
	Query(context.Context, string, time.Time) (model.Value, v1.Warnings, error)
}

PromClient is Prometheus HTTP client's interface

type PrometheusMockClient

type PrometheusMockClient struct {
	// contains filtered or unexported fields
}

PrometheusMockClient is a test client that returns fake values only for a configurable set of queries. New queries/responses can be added by calling Register(string, model.Value).

func NewPrometheusMockClient

func NewPrometheusMockClient() *PrometheusMockClient

NewPrometheusMockClient creates a mock client to test Prometheus queries.

func (PrometheusMockClient) Query

Query is a mock implementation that returns the model.Value corresponding to the query, if any, or an error.

func (*PrometheusMockClient) Register

func (p *PrometheusMockClient) Register(q string, resp model.Value, err error)

Register maps a query to the expected model.Value that must be returned.

func (*PrometheusMockClient) Unregister

func (p *PrometheusMockClient) Unregister(q string) func()

Unregister removes a mapped query and returns a function to add it back.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL