Documentation ¶
Overview ¶
Package filtertest implements mock versions of the Filter, Spec and FilterContext interfaces used during tests.
Index ¶
- type Context
- func (fc *Context) BackendUrl() string
- func (fc *Context) MarkServed()
- func (fc *Context) Metrics() filters.Metrics
- func (fc *Context) OriginalRequest() *http.Request
- func (fc *Context) OriginalResponse() *http.Response
- func (fc *Context) OutgoingHost() string
- func (fc *Context) PathParam(key string) string
- func (fc *Context) Request() *http.Request
- func (fc *Context) Response() *http.Response
- func (fc *Context) ResponseWriter() http.ResponseWriter
- func (fc *Context) Serve(resp *http.Response)
- func (fc *Context) Served() bool
- func (fc *Context) SetOutgoingHost(h string)
- func (fc *Context) StateBag() map[string]interface{}
- type Filter
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 }
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 (*Context) MarkServed ¶
func (fc *Context) MarkServed()
func (*Context) OriginalRequest ¶
func (*Context) OriginalResponse ¶
func (*Context) OutgoingHost ¶
func (*Context) ResponseWriter ¶
func (fc *Context) ResponseWriter() http.ResponseWriter
func (*Context) SetOutgoingHost ¶
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 (*Filter) Request ¶
func (f *Filter) Request(ctx filters.FilterContext)
func (*Filter) Response ¶
func (f *Filter) Response(ctx filters.FilterContext)
Click to show internal directories.
Click to hide internal directories.