@@ -64,3 +64,87 @@ func TestGorillaMuxRouter(t *testing.T) {
6464 })
6565 })
6666}
67+
68+ func TestTransformPath (t * testing.T ) {
69+ testCases := []struct {
70+ name string
71+ path string
72+ expectedPath string
73+ }{
74+ {
75+ name : "only /" ,
76+ path : "/" ,
77+ expectedPath : "/" ,
78+ },
79+ {
80+ name : "without params" ,
81+ path : "/foo" ,
82+ expectedPath : "/foo" ,
83+ },
84+ {
85+ name : "without params ending with /" ,
86+ path : "/foo/" ,
87+ expectedPath : "/foo/" ,
88+ },
89+ {
90+ name : "with params" ,
91+ path : "/foo/{par1}" ,
92+ expectedPath : "/foo/{par1}" ,
93+ },
94+ {
95+ name : "with params ending with /" ,
96+ path : "/foo/{par1}/" ,
97+ expectedPath : "/foo/{par1}/" ,
98+ },
99+ {
100+ name : "with multiple params" ,
101+ path : "/{par1}/{par2}/{par3}" ,
102+ expectedPath : "/{par1}/{par2}/{par3}" ,
103+ },
104+ {
105+ name : "with multiple params ending with /" ,
106+ path : "/{par1}/{par2}/{par3}/" ,
107+ expectedPath : "/{par1}/{par2}/{par3}/" ,
108+ },
109+ {
110+ name : "with multiple params in a segment" ,
111+ path : "/foo/{par2}{par3}" ,
112+ expectedPath : "/foo/{par2}{par3}" ,
113+ },
114+ {
115+ name : "with multiple params in a segment ending with /" ,
116+ path : "/foo/{par2}{par3}/" ,
117+ expectedPath : "/foo/{par2}{par3}/" ,
118+ },
119+ {
120+ name : "with regex" ,
121+ path : "/foo/{par1:[0-9]}/{par2:[a-z]}" ,
122+ expectedPath : "/foo/{par1}/{par2}" ,
123+ },
124+ {
125+ name : "with regex ending with /" ,
126+ path : "/foo/{par1:[0-9]}/{par2:[a-z]}/" ,
127+ expectedPath : "/foo/{par1}/{par2}/" ,
128+ },
129+ {
130+ name : "with multiple params in a segment and the regex" ,
131+ path : "/foo/{par2:[0-9]}{par3:a|b}/" ,
132+ expectedPath : "/foo/{par2}{par3}/" ,
133+ },
134+ {
135+ name : "with multiple params in a segment and the regex ending with /" ,
136+ path : "/foo/{par2:[0-9]}{par3:\\ w+}/" ,
137+ expectedPath : "/foo/{par2}{par3}/" ,
138+ },
139+ }
140+
141+ router := NewRouter (mux .NewRouter ())
142+
143+ for _ , test := range testCases {
144+
145+ t .Run (test .name , func (t * testing.T ) {
146+ actual := router .TransformPathToOasPath (test .path )
147+ require .Equal (t , test .expectedPath , actual )
148+ })
149+ }
150+ }
0 commit comments