mock

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2022 License: BSD-2-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package mock defines a mock backend for testing.

Example use:

b := New(Config{
	Info: func(context.Context, string) ([]types.Info, error) {
		return nil, errors.New("Oh no")
	}
})
got, err := b.Info(ctx, "foo")

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

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

Backend is a mock backend.

func New

func New(cfg Config) Backend

New creates a new mock backend.

func (Backend) Contains

func (b Backend) Contains(targets []string) bool

func (Backend) Find

func (b Backend) Find(ctx context.Context, request types.FindRequest) (types.Matches, error)

func (Backend) GetServerAddress added in v0.2.0

func (b Backend) GetServerAddress() string

func (Backend) Info

func (b Backend) Info(ctx context.Context, request types.InfoRequest) ([]types.Info, error)

func (Backend) Logger

func (b Backend) Logger() *zap.Logger

Logger returns a no-op logger.

func (Backend) Render

func (b Backend) Render(ctx context.Context, request types.RenderRequest) ([]types.Metric, error)

type Config

type Config struct {
	Find     func(context.Context, types.FindRequest) (types.Matches, error)
	Info     func(context.Context, types.InfoRequest) ([]types.Info, error)
	Render   func(context.Context, types.RenderRequest) ([]types.Metric, error)
	Contains func([]string) bool
}

Config configures a mock Backend. Define ad-hoc functions to return expected values depending on input. If a function is not defined, default to one that returns an empty response and nil error. A mock backend contains all targets by default.

Jump to

Keyboard shortcuts

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