test

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package test contains utility and helper methods for testing plugins

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrorHandler is a plugin.Handler and always returns an error
	ErrorHandler = HandlerFunc(func(_ context.Context, req, res *dhcpv4.DHCPv4) error {
		return errors.New("simulated error")
	})

	// NoOpHandler is a No-Operation plugin.Handler
	NoOpHandler = HandlerFunc(func(_ context.Context, req, res *dhcpv4.DHCPv4) error {
		return nil
	})
)

Functions

func CreateTestBed

func CreateTestBed(t *testing.T, input string) *caddy.Controller

CreateTestBed creates a new caddy.Controller that is configured for testing the setup and configuration of plugins. It creates a dummy server block in the context of "dhcpv4" server type so plugins can safely assume dhcpserver.GetConfig(ctrl) will return a valid configuration. The server block itself is configured to serve on 127.0.0.1/8

Types

type GetFunc

type GetFunc func(string) string

GetFunc is called when Replacer.Get is called

type HandlerFunc

type HandlerFunc func(ctx context.Context, req, res *dhcpv4.DHCPv4) error

HandlerFunc implements plugin.Handler

func (HandlerFunc) Name

func (fn HandlerFunc) Name() string

Name implements plugin.Handler

func (HandlerFunc) ServeDHCP

func (fn HandlerFunc) ServeDHCP(ctx context.Context, req, res *dhcpv4.DHCPv4) error

ServeDHCP implements plugin.Handler

type ReplaceFunc

type ReplaceFunc func(string) string

ReplaceFunc is called when Replacer.Replace is called

type Replacer

type Replacer struct {
	Getter   GetFunc
	Setter   SetFunc
	Replacer ReplaceFunc
}

Replacer implements the replacer.Replacer interface

func WithReplacer

func WithReplacer(ctx context.Context) (context.Context, *Replacer)

WithReplacer returns a context that has a test replacer assigned

func (*Replacer) Get

func (r *Replacer) Get(key string) string

Get implements replacer.Replacer

func (*Replacer) Replace

func (r *Replacer) Replace(input string) string

Replace implements replacer.Replacer

func (*Replacer) Set

func (r *Replacer) Set(key string, v replacer.Value)

Set implemes replacer.Replacer

type SetFunc

type SetFunc func(string, replacer.Value)

SetFunc is called when Replacer.Set is called

Jump to

Keyboard shortcuts

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