filtertest

package
v0.16.45 Latest Latest
Warning

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

Go to latest
Published: May 12, 2023 License: Apache-2.0, MIT Imports: 4 Imported by: 1

Documentation

Overview

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

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

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.

Example
package main

import (
	"fmt"
	"github.com/zalando/skipper/filters"
	"github.com/zalando/skipper/filters/filtertest"
)

type customFilter struct{}

func (f *customFilter) Request(ctx filters.FilterContext) {
	ctx.StateBag()["filter called"] = true
}

func (f *customFilter) Response(ctx filters.FilterContext) {}

func main() {
	// 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:
	filter.Request(ctx)
	fmt.Printf("%t", ctx.StateBag()["filter called"].(bool))

}
Output:

true

func (*Context) BackendUrl

func (fc *Context) BackendUrl() string

func (*Context) Logger added in v0.16.15

func (fc *Context) Logger() filters.FilterContextLogger

func (*Context) Loopback added in v0.11.113

func (fc *Context) Loopback()

func (*Context) MarkServed

func (fc *Context) MarkServed()

func (*Context) Metrics added in v0.9.119

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

func (*Context) OriginalRequest

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

func (*Context) OriginalResponse

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

func (*Context) OutgoingHost

func (fc *Context) OutgoingHost() string

func (*Context) ParentSpan added in v0.10.153

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

func (*Context) PathParam

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

func (*Context) Request

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

func (*Context) Response

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

func (*Context) ResponseController added in v0.16.23

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

func (*Context) ResponseWriter

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

func (*Context) Serve

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

func (*Context) Served

func (fc *Context) Served() bool

func (*Context) SetOutgoingHost

func (fc *Context) SetOutgoingHost(h string)

func (*Context) Split added in v0.11.113

func (fc *Context) Split() (filters.FilterContext, error)

func (*Context) StateBag

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

func (*Context) Tracer added in v0.9.119

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

type Filter

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.

Example
package main

import (
	"github.com/zalando/skipper/filters/builtin"
	"github.com/zalando/skipper/filters/filtertest"
	"github.com/zalando/skipper/proxy"
	"github.com/zalando/skipper/routing"
	"github.com/zalando/skipper/routing/testdataclient"
	"log"
)

func main() {
	// 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!") -> "https://www.example.org"`)
	if err != nil {
		log.Fatal(err)
	}

	// 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()
}
Output:

func (*Filter) CreateFilter

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

func (*Filter) Name

func (spec *Filter) Name() string

func (*Filter) Request

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

func (*Filter) Response

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

Jump to

Keyboard shortcuts

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