server_test.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package web
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. func TestNewServer_routes(t *testing.T) {
  7. s := NewServer()
  8. routes := s.router.Routes()
  9. checkedRoutes := make(map[string]bool)
  10. tests := []struct {
  11. path string
  12. method string
  13. handler string
  14. }{
  15. {path: "/ping", method: "GET", handler: "github.com/ajswis/go-pkparse-server/web.ping"},
  16. {path: "/parse", method: "POST", handler: "github.com/ajswis/go-pkparse-server/web.(*Server).parse-fm"},
  17. }
  18. for _, tt := range tests {
  19. var ran bool
  20. for _, route := range routes {
  21. if route.Path == tt.path {
  22. t.Run(tt.path, func(t *testing.T) {
  23. assert.Equal(t, tt.path, route.Path)
  24. assert.Equal(t, tt.method, route.Method)
  25. assert.Equal(t, tt.handler, route.Handler)
  26. })
  27. ran = true
  28. checkedRoutes[route.Path] = true
  29. break
  30. }
  31. }
  32. if !ran {
  33. assert.Failf(t, "Unknown route", "Don't know about %s", tt.path)
  34. }
  35. }
  36. for _, route := range routes {
  37. if !checkedRoutes[route.Path] {
  38. assert.Failf(t, "Unchecked route", "Didn't check %s", route.Path)
  39. }
  40. }
  41. }