Skip to content

Commit 6a8ce75

Browse files
committed
Add integration tests for Iris
Signed-off-by: Xabier Larrakoetxea <me@slok.dev>
1 parent 5ca56f4 commit 6a8ce75

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

test/integration/integration_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/gorilla/mux"
1616
"github.com/julienschmidt/httprouter"
1717
"github.com/justinas/alice"
18+
"github.com/kataras/iris/v12"
1819
"github.com/labstack/echo/v4"
1920
"github.com/prometheus/client_golang/prometheus"
2021
"github.com/prometheus/client_golang/prometheus/promhttp"
@@ -33,6 +34,7 @@ import (
3334
gojimiddleware "github.com/slok/go-http-metrics/middleware/goji"
3435
gorestfulmiddleware "github.com/slok/go-http-metrics/middleware/gorestful"
3536
httproutermiddleware "github.com/slok/go-http-metrics/middleware/httprouter"
37+
irismiddleware "github.com/slok/go-http-metrics/middleware/iris"
3638
negronimiddleware "github.com/slok/go-http-metrics/middleware/negroni"
3739
stdmiddleware "github.com/slok/go-http-metrics/middleware/std"
3840
)
@@ -82,6 +84,7 @@ func TestMiddlewarePrometheus(t *testing.T) {
8284
"Alice": {server: prepareHandlerAlice},
8385
"Gorilla": {server: prepareHandlerGorilla},
8486
"Fasthttp": {server: prepareHandlerFastHTTP},
87+
"Iris": {server: prepareHandlerIris},
8588
}
8689

8790
for name, test := range tests {
@@ -382,3 +385,23 @@ func prepareHandlerFastHTTP(m middleware.Middleware, hc []handlerConfig) server
382385

383386
return netListenerServer{ln: ln}
384387
}
388+
389+
func prepareHandlerIris(m middleware.Middleware, hc []handlerConfig) server {
390+
// Setup server and middleware.
391+
app := iris.New()
392+
app.Use(irismiddleware.Handler("", m))
393+
394+
// Set handlers.
395+
for _, h := range hc {
396+
h := h
397+
app.Handle(h.Method, h.Path, iris.Handler(func(ctx iris.Context) {
398+
time.Sleep(h.SleepDuration)
399+
ctx.StatusCode(h.Code)
400+
ctx.WriteString(h.ReturnData) // nolint: errcheck
401+
}))
402+
}
403+
404+
app.Build() // nolint: errcheck
405+
406+
return testServer{server: httptest.NewServer(app)}
407+
}

0 commit comments

Comments
 (0)