skipper: Index | Examples | Files

package filtertest

import ""

Package filtertest implements mock versions of the Filter, Spec and FilterContext interfaces used during tests.



Package Files


type Context Uses

type Context struct {
    FResponseWriter     http.ResponseWriter
    FRequest            *http.Request
    FResponse           *http.Response
    FServed             bool
    FServedWithResponse bool
    FParams             map[string]string
    FStateBag           map[string]interface{}
    FBackendUrl         string
    FOutgoingHost       string
    FMetrics            filters.Metrics
    FTracer             opentracing.Tracer

Simple FilterContext implementation.


// create a filter instance:
filter := &customFilter{}

// create a test context:
ctx := &filtertest.Context{FStateBag: make(map[string]interface{})}

// call the request handler method of the filter:
fmt.Printf("%t", ctx.StateBag()["filter called"].(bool))



func (*Context) BackendUrl Uses

func (fc *Context) BackendUrl() string

func (*Context) MarkServed Uses

func (fc *Context) MarkServed()

func (*Context) Metrics Uses

func (fc *Context) Metrics() filters.Metrics

func (*Context) OriginalRequest Uses

func (fc *Context) OriginalRequest() *http.Request

func (*Context) OriginalResponse Uses

func (fc *Context) OriginalResponse() *http.Response

func (*Context) OutgoingHost Uses

func (fc *Context) OutgoingHost() string

func (*Context) ParentSpan Uses

func (fc *Context) ParentSpan() opentracing.Span

func (*Context) PathParam Uses

func (fc *Context) PathParam(key string) string

func (*Context) Request Uses

func (fc *Context) Request() *http.Request

func (*Context) Response Uses

func (fc *Context) Response() *http.Response

func (*Context) ResponseWriter Uses

func (fc *Context) ResponseWriter() http.ResponseWriter

func (*Context) Serve Uses

func (fc *Context) Serve(resp *http.Response)

func (*Context) Served Uses

func (fc *Context) Served() bool

func (*Context) SetOutgoingHost Uses

func (fc *Context) SetOutgoingHost(h string)

func (*Context) StateBag Uses

func (fc *Context) StateBag() map[string]interface{}

func (*Context) Tracer Uses

func (fc *Context) Tracer() opentracing.Tracer

type Filter Uses

type Filter struct {
    FilterName string
    Args       []interface{}

Noop filter, used to verify the filter name and the args in the route. Implements both the Filter and the Spec interfaces.


// create a test filter and add to the registry:
fr := builtin.MakeRegistry()
fr.Register(&filtertest.Filter{FilterName: "testFilter"})

// create a data client, with a predefined route referencing the filter:
dc, err := testdataclient.NewDoc(`Path("/some/path/:param") -> testFilter(3.14, "Hello, world!") -> ""`)
if err != nil {

// create routing object:
rt := routing.New(routing.Options{
    DataClients:    []routing.DataClient{dc},
    FilterRegistry: fr})
defer rt.Close()

// create an http.Handler:
p := proxy.New(rt, proxy.OptionsNone)
defer p.Close()

func (*Filter) CreateFilter Uses

func (spec *Filter) CreateFilter(config []interface{}) (filters.Filter, error)

lint:ignore ST1016 ignore receiver name, because of type reuse

func (*Filter) Name Uses

func (spec *Filter) Name() string

func (*Filter) Request Uses

func (f *Filter) Request(ctx filters.FilterContext)

func (*Filter) Response Uses

func (f *Filter) Response(ctx filters.FilterContext)

Package filtertest imports 3 packages (graph) and is imported by 1 packages. Updated 2019-01-26. Refresh now. Tools for package owners.