Skip to content
Myr

More unit tests

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Manu Mtz-Almeida · committed by Manu Mtz-Almeida · parent f199a21 · Browse files · 2 files+40 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+40 added−0 removed

  • other:+40 added−0 removed

2 files+40 added−0 removed

modified:gin_test.go+26 added
24 unmodified lines
25 router := New()26 assert.Equal(t, "/", router.BasePath)27 assert.Equal(t, router.engine, router)28 assert.Empty(t, router.Handlers)29}3031func TestAddRoute(t *testing.T) {32 router := New()33 router.addRoute("GET", "/", HandlersChain{func(_ *Context) {}})3435 assert.Len(t, router.trees, 1)36 assert.NotNil(t, router.trees.get("GET"))37 assert.Nil(t, router.trees.get("POST"))3839 router.addRoute("POST", "/", HandlersChain{func(_ *Context) {}})4041 assert.Len(t, router.trees, 2)42 assert.NotNil(t, router.trees.get("GET"))43 assert.NotNil(t, router.trees.get("POST"))4445 router.addRoute("POST", "/post", HandlersChain{func(_ *Context) {}})46 assert.Len(t, router.trees, 2)47}4849func TestAddRouteFails(t *testing.T) {50 router := New()51 assert.Panics(t, func() { router.addRoute("", "/", HandlersChain{func(_ *Context) {}}) })52 assert.Panics(t, func() { router.addRoute("GET", "a", HandlersChain{func(_ *Context) {}}) })53 assert.Panics(t, func() { router.addRoute("GET", "/", HandlersChain{}) })5455 router.addRoute("POST", "/post", HandlersChain{func(_ *Context) {}})56 assert.Panics(t, func() {57 router.addRoute("POST", "/post", HandlersChain{func(_ *Context) {}})58 })59}6061func TestCreateDefaultRouter(t *testing.T) {62 router := Default()
120 unmodified lines
modified:routergroup_test.go+14 added
107 unmodified lines
108 assert.Panics(t, func() {109 router.StaticFile("/path/*param", "favicon.ico")110 })111}112113func TestRouterGroupTooManyHandlers(t *testing.T) {114 router := New()115 handlers1 := make([]HandlerFunc, 40)116 router.Use(handlers1...)117118 handlers2 := make([]HandlerFunc, 26)119 assert.Panics(t, func() {120 router.Use(handlers2...)121 })122 assert.Panics(t, func() {123 router.GET("/", handlers2...)124 })125}