server_test.go 1.1 KB

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