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 ¶
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 ¶
func (p PrometheusMockClient) Query(ctx context.Context, q string, t time.Time) (model.Value, v1.Warnings, error)
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.