(t *testing.T)
| 23 | } |
| 24 | |
| 25 | func TestHandlerName(t *testing.T) { |
| 26 | myNameFuncVar := func(c *Context) error { |
| 27 | return nil |
| 28 | } |
| 29 | |
| 30 | tmp := NameStruct{} |
| 31 | |
| 32 | var testCases = []struct { |
| 33 | name string |
| 34 | whenHandlerFunc HandlerFunc |
| 35 | expect string |
| 36 | }{ |
| 37 | { |
| 38 | name: "ok, func as anonymous func", |
| 39 | whenHandlerFunc: func(c *Context) error { |
| 40 | return nil |
| 41 | }, |
| 42 | expect: "github.com/labstack/echo/v5.TestHandlerName.func2", |
| 43 | }, |
| 44 | { |
| 45 | name: "ok, func as named package variable", |
| 46 | whenHandlerFunc: myNamedHandler, |
| 47 | expect: "github.com/labstack/echo/v5.init.func4", |
| 48 | }, |
| 49 | { |
| 50 | name: "ok, func as named function variable", |
| 51 | whenHandlerFunc: myNameFuncVar, |
| 52 | expect: "github.com/labstack/echo/v5.TestHandlerName.func1", |
| 53 | }, |
| 54 | { |
| 55 | name: "ok, func as struct method", |
| 56 | whenHandlerFunc: tmp.getUsers, |
| 57 | expect: "github.com/labstack/echo/v5.(*NameStruct).getUsers-fm", |
| 58 | }, |
| 59 | } |
| 60 | |
| 61 | for _, tc := range testCases { |
| 62 | t.Run(tc.name, func(t *testing.T) { |
| 63 | name := HandlerName(tc.whenHandlerFunc) |
| 64 | assert.Equal(t, tc.expect, name) |
| 65 | }) |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | func TestHandlerName_differentFuncSameName(t *testing.T) { |
| 70 | handlerCreator := func(name string) HandlerFunc { |
nothing calls this directly
no test coverage detected
searching dependent graphs…