Common isomorphic functionality in one kit.

route_test.go 737B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package isokit
  2. import (
  3. "context"
  4. "reflect"
  5. "testing"
  6. )
  7. func TestNewRoute(t *testing.T) {
  8. handler := func(ctx context.Context) {}
  9. testCases := map[string]struct {
  10. path string
  11. expectedVars []string
  12. }{
  13. "Without vars": {
  14. "/this/is/a/path",
  15. []string(nil),
  16. },
  17. "Single var": {
  18. "/this/{firstVar}/is/a/path",
  19. []string{"firstVar"},
  20. },
  21. "Multiple vars": {
  22. "/this/is/{firstVar}/a/{secondVar}/path",
  23. []string{"firstVar", "secondVar"},
  24. },
  25. }
  26. for title, tc := range testCases {
  27. t.Run(title, func(t *testing.T) {
  28. r := NewRoute(tc.path, handler)
  29. if !reflect.DeepEqual(r.varNames, tc.expectedVars) {
  30. t.Errorf("wrong vars: expected %#v, got %#v", tc.expectedVars, r.varNames)
  31. }
  32. })
  33. }
  34. }