github.com/res-am/buffalo@v0.11.1/route_test.go (about)

     1  package buffalo
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  )
     8  
     9  func Test_App_Routes_without_Root(t *testing.T) {
    10  	r := require.New(t)
    11  
    12  	a := New(Options{})
    13  	r.Nil(a.root)
    14  
    15  	a.GET("/foo", voidHandler)
    16  
    17  	routes := a.Routes()
    18  	r.Len(routes, 1)
    19  	route := routes[0]
    20  	r.Equal("GET", route.Method)
    21  	r.Equal("/foo", route.Path)
    22  	r.NotZero(route.HandlerName)
    23  }
    24  
    25  func Test_App_Routes_with_Root(t *testing.T) {
    26  	r := require.New(t)
    27  
    28  	a := New(Options{})
    29  	r.Nil(a.root)
    30  
    31  	g := a.Group("/api/v1")
    32  	g.GET("/foo", voidHandler)
    33  
    34  	routes := a.Routes()
    35  	r.Len(routes, 1)
    36  	route := routes[0]
    37  	r.Equal("GET", route.Method)
    38  	r.Equal("/api/v1/foo", route.Path)
    39  	r.NotZero(route.HandlerName)
    40  
    41  	r.Equal(a.Routes(), g.Routes())
    42  }
    43  
    44  func Test_App_RouteName(t *testing.T) {
    45  	r := require.New(t)
    46  
    47  	a := New(Options{})
    48  
    49  	cases := map[string]string{
    50  		"cool":                "coolPath",
    51  		"coolPath":            "coolPath",
    52  		"coco_path":           "cocoPath",
    53  		"ouch_something_cool": "ouchSomethingCoolPath",
    54  	}
    55  
    56  	ri := a.GET("/something", voidHandler)
    57  	for k, v := range cases {
    58  		ri.Name(k)
    59  		r.Equal(ri.PathName, v)
    60  	}
    61  
    62  }