verify that copyRouteConf copies fields as expected.
(t *testing.T)
| 2691 | |
| 2692 | // verify that copyRouteConf copies fields as expected. |
| 2693 | func Test_copyRouteConf(t *testing.T) { |
| 2694 | var ( |
| 2695 | m MatcherFunc = func(*http.Request, *RouteMatch) bool { |
| 2696 | return true |
| 2697 | } |
| 2698 | b BuildVarsFunc = func(i map[string]string) map[string]string { |
| 2699 | return i |
| 2700 | } |
| 2701 | r, _ = newRouteRegexp("hi", regexpTypeHost, routeRegexpOptions{}) |
| 2702 | ) |
| 2703 | |
| 2704 | tests := []struct { |
| 2705 | name string |
| 2706 | args routeConf |
| 2707 | want routeConf |
| 2708 | }{ |
| 2709 | { |
| 2710 | "empty", |
| 2711 | routeConf{}, |
| 2712 | routeConf{}, |
| 2713 | }, |
| 2714 | { |
| 2715 | "full", |
| 2716 | routeConf{ |
| 2717 | useEncodedPath: true, |
| 2718 | strictSlash: true, |
| 2719 | skipClean: true, |
| 2720 | regexp: routeRegexpGroup{host: r, path: r, queries: []*routeRegexp{r}}, |
| 2721 | matchers: []matcher{m}, |
| 2722 | buildScheme: "https", |
| 2723 | buildVarsFunc: b, |
| 2724 | }, |
| 2725 | routeConf{ |
| 2726 | useEncodedPath: true, |
| 2727 | strictSlash: true, |
| 2728 | skipClean: true, |
| 2729 | regexp: routeRegexpGroup{host: r, path: r, queries: []*routeRegexp{r}}, |
| 2730 | matchers: []matcher{m}, |
| 2731 | buildScheme: "https", |
| 2732 | buildVarsFunc: b, |
| 2733 | }, |
| 2734 | }, |
| 2735 | } |
| 2736 | |
| 2737 | for _, tt := range tests { |
| 2738 | t.Run(tt.name, func(t *testing.T) { |
| 2739 | // special case some incomparable fields of routeConf before delegating to reflect.DeepEqual |
| 2740 | got := copyRouteConf(tt.args) |
| 2741 | |
| 2742 | // funcs not comparable, just compare length of slices |
| 2743 | if len(got.matchers) != len(tt.want.matchers) { |
| 2744 | t.Errorf("matchers different lengths: %v %v", len(got.matchers), len(tt.want.matchers)) |
| 2745 | } |
| 2746 | got.matchers, tt.want.matchers = nil, nil |
| 2747 | |
| 2748 | // deep equal treats nil slice differently to empty slice so check for zero len first |
| 2749 | { |
| 2750 | bothZero := len(got.regexp.queries) == 0 && len(tt.want.regexp.queries) == 0 |
nothing calls this directly
no test coverage detected