MCPcopy
hub / github.com/gorilla/mux / TestGetVarNames

Function TestGetVarNames

mux_test.go:2882–2914  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2880}
2881
2882func TestGetVarNames(t *testing.T) {
2883 r := NewRouter()
2884
2885 route := r.Host("{domain}").
2886 Path("/{group}/{item_id}").
2887 Queries("some_data1", "{some_data1}").
2888 Queries("some_data2_and_3", "{some_data2}.{some_data3}")
2889
2890 // Order of vars in the slice is not guaranteed, so just check for existence
2891 expected := map[string]bool{
2892 "domain": true,
2893 "group": true,
2894 "item_id": true,
2895 "some_data1": true,
2896 "some_data2": true,
2897 "some_data3": true,
2898 }
2899
2900 varNames, err := route.GetVarNames()
2901 if err != nil {
2902 t.Fatal(err)
2903 }
2904
2905 if len(varNames) != len(expected) {
2906 t.Fatalf("expected %d names, got %d", len(expected), len(varNames))
2907 }
2908
2909 for _, varName := range varNames {
2910 if !expected[varName] {
2911 t.Fatalf("got unexpected %s", varName)
2912 }
2913 }
2914}
2915
2916// mapToPairs converts a string map to a slice of string pairs
2917func mapToPairs(m map[string]string) []string {

Callers

nothing calls this directly

Calls 5

HostMethod · 0.95
NewRouterFunction · 0.85
GetVarNamesMethod · 0.80
QueriesMethod · 0.45
PathMethod · 0.45

Tested by

no test coverage detected