These are chat archives for gin-gonic/gin

22nd
Nov 2016
Matt Reyer
@winduptoy
Nov 22 2016 14:04

Hi there, I've got a question about testing my gin routes. Let's say I wanted to write a test that checks to make sure that specific routes require my authentication middleware.

func TestAuthRequiredRoutes(t *testing.T) {

    r := Router: gin.Default()
    initRoutes(r)

    var handlerName string = getFunctionName(somepackage.MyAuthFunction) // Uses reflection to get the string name of the function

    for _, route := range r.Routes() {
        t.Log(route.Method, route.Path, route.Handler)
    }
}

In the example above, route.Handler is simply a single string that is the last gin.Handlerfunc in the stack. Is there a way to access all middewares in use for a particular route, so that I may test to see if it includes a specific function?