| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- package web
- import (
- "testing"
- "github.com/stretchr/testify/assert"
- )
- func TestNewServer_routes(t *testing.T) {
- s := NewServer()
- routes := s.router.Routes()
- checkedRoutes := make(map[string]bool)
- tests := []struct {
- path string
- method string
- handler string
- }{
- {path: "/ping", method: "GET", handler: "github.com/ajswis/go-pkparse-server/web.ping"},
- {path: "/parse", method: "POST", handler: "github.com/ajswis/go-pkparse-server/web.(*Server).parse-fm"},
- }
- for _, tt := range tests {
- var ran bool
- for _, route := range routes {
- if route.Path == tt.path {
- t.Run(tt.path, func(t *testing.T) {
- assert.Equal(t, tt.path, route.Path)
- assert.Equal(t, tt.method, route.Method)
- assert.Equal(t, tt.handler, route.Handler)
- })
- ran = true
- checkedRoutes[route.Path] = true
- break
- }
- }
- if !ran {
- assert.Failf(t, "Unknown route", "Don't know about %s", tt.path)
- }
- }
- for _, route := range routes {
- if !checkedRoutes[route.Path] {
- assert.Failf(t, "Unchecked route", "Didn't check %s", route.Path)
- }
- }
- }
|