mock

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2019 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) 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) Probe

func (b Backend) Probe()

Probe is a no-op.

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