forked from krakend/krakend-cel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxy_benchmark_test.go
48 lines (42 loc) · 1.12 KB
/
proxy_benchmark_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package cel
import (
"bytes"
"context"
"strconv"
"testing"
"github.com/devopsfaith/krakend-cel/internal"
"github.com/devopsfaith/krakend/config"
"github.com/devopsfaith/krakend/logging"
"github.com/devopsfaith/krakend/proxy"
)
func BenchmarkProxyFactory_reqParams_int(b *testing.B) {
buff := bytes.NewBuffer(make([]byte, 1024))
logger, err := logging.NewLogger("ERROR", buff, "pref")
if err != nil {
b.Error("building the logger:", err.Error())
return
}
expectedResponse := &proxy.Response{Data: map[string]interface{}{"ok": true}, IsComplete: true}
prxy, err := ProxyFactory(logger, dummyProxyFactory(expectedResponse)).New(&config.EndpointConfig{
Endpoint: "/",
ExtraConfig: config.ExtraConfig{
internal.Namespace: []internal.InterpretableDefinition{
{CheckExpression: "int(req_params.Id) % 2 == 0"},
},
},
})
if err != nil {
b.Error(err)
return
}
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
prxy(context.Background(), &proxy.Request{
Method: "GET",
Path: "/some-path",
Params: map[string]string{"Id": strconv.Itoa(i)},
Headers: map[string][]string{},
})
}
}