(opts LuaOptions, test *testContext)
| 930 | } |
| 931 | |
| 932 | func runFilter(opts LuaOptions, test *testContext) (filters.FilterContext, error) { |
| 933 | scr, err := newFilter(opts, test.script, test.params...) |
| 934 | if err != nil { |
| 935 | return nil, err |
| 936 | } |
| 937 | url := "http://www.example.com/foo/bar" |
| 938 | if test.url != "" { |
| 939 | url = test.url |
| 940 | } |
| 941 | req, _ := http.NewRequest("GET", url, nil) |
| 942 | if test.requestHeader != nil { |
| 943 | req.Header = test.requestHeader.Clone() |
| 944 | } |
| 945 | fc := &filtertest.Context{ |
| 946 | FParams: test.pathParams, |
| 947 | FStateBag: make(map[string]interface{}), |
| 948 | FRequest: req, |
| 949 | FOutgoingHost: "www.example.com", |
| 950 | } |
| 951 | scr.Request(fc) |
| 952 | |
| 953 | body := "Hello world" |
| 954 | fc.FResponse = &http.Response{ |
| 955 | Status: "200 OK", |
| 956 | StatusCode: 200, |
| 957 | Proto: "HTTP/1.1", |
| 958 | ProtoMajor: 1, |
| 959 | ProtoMinor: 1, |
| 960 | Body: io.NopCloser(bytes.NewBufferString(body)), |
| 961 | ContentLength: int64(len(body)), |
| 962 | Request: req, |
| 963 | Header: make(http.Header), |
| 964 | } |
| 965 | if test.responseHeader != nil { |
| 966 | fc.Response().Header = test.responseHeader.Clone() |
| 967 | } |
| 968 | |
| 969 | scr.Response(fc) |
| 970 | |
| 971 | return fc, nil |
| 972 | } |
| 973 | |
| 974 | func runExample(ctx *testContext) { |
| 975 | runExampleWithOptions(LuaOptions{}, ctx) |
no test coverage detected
searching dependent graphs…