forked from goffee/core
initial commits 2
This commit is contained in:
parent
5475b7dd26
commit
7f38826b9c
39 changed files with 4525 additions and 0 deletions
126
router_test.go
Normal file
126
router_test.go
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
// Copyright 2021 Harran Ali <harran.m@gmail.com>. All rights reserved.
|
||||
// Copyright (c) 2024 Zeni Kim <zenik@smarteching.com>
|
||||
// Use of this source code is governed by MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewRouter(t *testing.T) {
|
||||
r := NewRouter()
|
||||
|
||||
if fmt.Sprintf("%T", r) != "*core.Router" {
|
||||
t.Error("failed asserting initiation of new router")
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveRouter(t *testing.T) {
|
||||
r := ResolveRouter()
|
||||
if fmt.Sprintf("%T", r) != "*core.Router" {
|
||||
t.Error("failed resolve router variable")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetRequest(t *testing.T) {
|
||||
r := NewRouter()
|
||||
handler := Handler(func(c *Context) *Response {
|
||||
c.GetLogger().Info(TEST_STR)
|
||||
return nil
|
||||
})
|
||||
r.Get("/", handler)
|
||||
|
||||
route := r.GetRoutes()[0]
|
||||
if route.Method != "get" || route.Path != "/" {
|
||||
t.Errorf("failed adding route with get http method")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPostRequest(t *testing.T) {
|
||||
r := NewRouter()
|
||||
handler := Handler(func(c *Context) *Response {
|
||||
c.GetLogger().Info(TEST_STR)
|
||||
return nil
|
||||
})
|
||||
r.Post("/", handler)
|
||||
|
||||
route := r.GetRoutes()[0]
|
||||
if route.Method != "post" || route.Path != "/" {
|
||||
t.Errorf("failed adding route with post http method")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteRequest(t *testing.T) {
|
||||
r := NewRouter()
|
||||
handler := Handler(func(c *Context) *Response {
|
||||
c.GetLogger().Info(TEST_STR)
|
||||
return nil
|
||||
})
|
||||
r.Delete("/", handler)
|
||||
|
||||
route := r.GetRoutes()[0]
|
||||
if route.Method != "delete" || route.Path != "/" {
|
||||
t.Errorf("failed adding route with delete http method")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPutRequest(t *testing.T) {
|
||||
r := NewRouter()
|
||||
handler := Handler(func(c *Context) *Response {
|
||||
c.GetLogger().Info(TEST_STR)
|
||||
return nil
|
||||
})
|
||||
r.Put("/", handler)
|
||||
|
||||
route := r.GetRoutes()[0]
|
||||
if route.Method != "put" || route.Path != "/" {
|
||||
t.Errorf("failed adding route with put http method")
|
||||
}
|
||||
}
|
||||
|
||||
func TestOptionsRequest(t *testing.T) {
|
||||
r := NewRouter()
|
||||
handler := Handler(func(c *Context) *Response {
|
||||
c.GetLogger().Info(TEST_STR)
|
||||
return nil
|
||||
})
|
||||
r.Options("/", handler)
|
||||
|
||||
route := r.GetRoutes()[0]
|
||||
if route.Method != "options" || route.Path != "/" {
|
||||
t.Errorf("failed adding route with options http method")
|
||||
}
|
||||
}
|
||||
|
||||
func TestHeadRequest(t *testing.T) {
|
||||
r := NewRouter()
|
||||
handler := Handler(func(c *Context) *Response {
|
||||
c.GetLogger().Info(TEST_STR)
|
||||
return nil
|
||||
})
|
||||
r.Head("/", handler)
|
||||
|
||||
route := r.GetRoutes()[0]
|
||||
if route.Method != "head" || route.Path != "/" {
|
||||
t.Errorf("failed adding route with head http method")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddMultipleRoutes(t *testing.T) {
|
||||
r := NewRouter()
|
||||
r.Get("/", Handler(func(c *Context) *Response {
|
||||
c.GetLogger().Info(TEST_STR)
|
||||
return nil
|
||||
}))
|
||||
r.Post("/", Handler(func(c *Context) *Response {
|
||||
c.GetLogger().Info(TEST_STR)
|
||||
return nil
|
||||
}))
|
||||
|
||||
if len(r.GetRoutes()) != 2 {
|
||||
t.Errorf("failed getting added routes")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue