@@ -55,6 +55,22 @@ func testNewRequestBuildersInvalidMetadata(t *testing.T) {
5555 assert .Empty (rb )
5656}
5757
58+ func testNewRequestBuildersInvalidPathValues (t * testing.T ) {
59+ assert := assert .New (t )
60+ rb , err := NewRequestBuilders (Options {
61+ PathValues : []Value {
62+ {
63+ Key : "bad" ,
64+ Header : "xxx" ,
65+ Parameter : "yyy" ,
66+ Variable : "zzz" ,
67+ },
68+ },
69+ })
70+
71+ assert .Equal (ErrVariableNotAllowed , err )
72+ assert .Empty (rb )
73+ }
5874func testNewRequestBuildersSuccess (t * testing.T ) {
5975 testData := []struct {
6076 options Options
@@ -89,16 +105,24 @@ func testNewRequestBuildersSuccess(t *testing.T) {
89105 Header : "X-Missing" ,
90106 },
91107 },
108+ PathValues : []Value {
109+ {
110+ Key : "fromHeader" ,
111+ Header : "X-PathVlaue" ,
112+ },
113+ },
92114 PartnerID : & PartnerID {
93- Claim : "partner-id-claim" ,
94- Metadata : "partner-id-metadata" ,
95- Header : "X-Midt-Partner-ID" ,
115+ Claim : "partner-id-claim" ,
116+ Metadata : "partner-id-metadata" ,
117+ PathValue : "partner-id-pathValue" ,
118+ Header : "X-Midt-Partner-ID" ,
96119 },
97120 },
98121 uri : "/test" ,
99122 header : http.Header {
100123 "X-Claim" : []string {"foo" },
101124 "X-Metadata" : []string {"bar" },
125+ "X-PathVlaue" : []string {"foobar" },
102126 "X-Midt-Partner-ID" : []string {"test" },
103127 },
104128 expected : & Request {
@@ -111,6 +135,10 @@ func testNewRequestBuildersSuccess(t *testing.T) {
111135 "fromHeader" : "bar" ,
112136 "partner-id-metadata" : "test" ,
113137 },
138+ PathValues : map [string ]any {
139+ "fromHeader" : "foobar" ,
140+ "partner-id-pathValue" : "test" ,
141+ },
114142 },
115143 },
116144 {
@@ -135,13 +163,24 @@ func testNewRequestBuildersSuccess(t *testing.T) {
135163 Parameter : "missing" ,
136164 },
137165 },
166+ PathValues : []Value {
167+ {
168+ Key : "fromParameter" ,
169+ Parameter : "pathValue" ,
170+ },
171+ {
172+ Key : "missing" ,
173+ Parameter : "missing" ,
174+ },
175+ },
138176 PartnerID : & PartnerID {
139177 Claim : "partner-id-claim" ,
140178 Metadata : "partner-id-metadata" ,
179+ PathValue : "partner-id-pathValue" ,
141180 Parameter : "pid" ,
142181 },
143182 },
144- uri : "/test?pid=test&claim=foo&metadata=bar" ,
183+ uri : "/test?pid=test&claim=foo&metadata=bar&pathValue=foobar " ,
145184 expected : & Request {
146185 Logger : sallust .Default (),
147186 Claims : map [string ]interface {}{
@@ -152,6 +191,10 @@ func testNewRequestBuildersSuccess(t *testing.T) {
152191 "fromParameter" : "bar" ,
153192 "partner-id-metadata" : "test" ,
154193 },
194+ PathValues : map [string ]any {
195+ "fromParameter" : "foobar" ,
196+ "partner-id-pathValue" : "test" ,
197+ },
155198 },
156199 },
157200 {
@@ -168,17 +211,25 @@ func testNewRequestBuildersSuccess(t *testing.T) {
168211 Variable : "metadata" ,
169212 },
170213 },
214+ PathValues : []Value {
215+ {
216+ Key : "fromVariable" ,
217+ Variable : "pathValues" ,
218+ },
219+ },
171220 PartnerID : & PartnerID {
172221 Claim : "partner-id-claim" ,
173222 Metadata : "partner-id-metadata" ,
223+ PathValue : "partner-id-pathValue" ,
174224 Parameter : "pid" ,
175225 Default : "test" ,
176226 },
177227 },
178228 uri : "/test/foo/bar" ,
179229 urlVariables : map [string ]string {
180- "claim" : "foo" ,
181- "metadata" : "bar" ,
230+ "claim" : "foo" ,
231+ "metadata" : "bar" ,
232+ "pathValues" : "foobar" ,
182233 },
183234 expected : & Request {
184235 Logger : sallust .Default (),
@@ -190,6 +241,10 @@ func testNewRequestBuildersSuccess(t *testing.T) {
190241 "fromVariable" : "bar" ,
191242 "partner-id-metadata" : "test" ,
192243 },
244+ PathValues : map [string ]any {
245+ "fromVariable" : "foobar" ,
246+ "partner-id-pathValue" : "test" ,
247+ },
193248 },
194249 },
195250 {
@@ -206,11 +261,18 @@ func testNewRequestBuildersSuccess(t *testing.T) {
206261 Variable : "metadata" ,
207262 },
208263 },
264+ PathValues : []Value {
265+ {
266+ Key : "fromVariable" ,
267+ Variable : "pathValue" ,
268+ },
269+ },
209270 },
210271 uri : "/test/foo/bar" ,
211272 urlVariables : map [string ]string {
212- "claim" : "foo" ,
213- "metadata" : "bar" ,
273+ "claim" : "foo" ,
274+ "metadata" : "bar" ,
275+ "pathValue" : "foobar" ,
214276 },
215277 expected : & Request {
216278 Logger : sallust .Default (),
@@ -220,6 +282,9 @@ func testNewRequestBuildersSuccess(t *testing.T) {
220282 Metadata : map [string ]interface {}{
221283 "fromVariable" : "bar" ,
222284 },
285+ PathValues : map [string ]any {
286+ "fromVariable" : "foobar" ,
287+ },
223288 },
224289 },
225290 }
@@ -316,6 +381,7 @@ func testNewRequestBuildersInvalidPartnerID(t *testing.T) {
316381func TestNewRequestBuilders (t * testing.T ) {
317382 t .Run ("InvalidClaim" , testNewRequestBuildersInvalidClaim )
318383 t .Run ("InvalidMetadata" , testNewRequestBuildersInvalidMetadata )
384+ t .Run ("InvalidPathValues" , testNewRequestBuildersInvalidPathValues )
319385 t .Run ("MissingVariable" , testNewRequestBuildersMissingVariable )
320386 t .Run ("InvalidPartnerID" , testNewRequestBuildersInvalidPartnerID )
321387 t .Run ("Success" , testNewRequestBuildersSuccess )
@@ -341,9 +407,10 @@ func testBuildRequestSuccess(t *testing.T) {
341407 }),
342408 },
343409 expected : & Request {
344- Logger : sallust .Default (),
345- Claims : map [string ]interface {}{"claim" : []int {1 , 2 , 3 }},
346- Metadata : make (map [string ]interface {}),
410+ Logger : sallust .Default (),
411+ Claims : map [string ]interface {}{"claim" : []int {1 , 2 , 3 }},
412+ Metadata : make (map [string ]interface {}),
413+ PathValues : make (map [string ]interface {}),
347414 },
348415 },
349416 {
@@ -354,9 +421,10 @@ func testBuildRequestSuccess(t *testing.T) {
354421 }),
355422 },
356423 expected : & Request {
357- Logger : sallust .Default (),
358- Claims : make (map [string ]interface {}),
359- Metadata : map [string ]interface {}{"metadata" : - 75.8 },
424+ Logger : sallust .Default (),
425+ Claims : make (map [string ]interface {}),
426+ Metadata : map [string ]interface {}{"metadata" : - 75.8 },
427+ PathValues : make (map [string ]interface {}),
360428 },
361429 },
362430 {
@@ -376,9 +444,10 @@ func testBuildRequestSuccess(t *testing.T) {
376444 }),
377445 },
378446 expected : & Request {
379- Logger : sallust .Default (),
380- Claims : map [string ]interface {}{"claim1" : 238947123 , "claim2" : []byte {1 , 2 , 3 }},
381- Metadata : map [string ]interface {}{"metadata1" : "value1" , "metadata2" : 15.7 },
447+ Logger : sallust .Default (),
448+ Claims : map [string ]interface {}{"claim1" : 238947123 , "claim2" : []byte {1 , 2 , 3 }},
449+ Metadata : map [string ]interface {}{"metadata1" : "value1" , "metadata2" : 15.7 },
450+ PathValues : make (map [string ]interface {}),
382451 },
383452 },
384453 }
@@ -569,9 +638,10 @@ func testDecodeServerRequestSuccess(t *testing.T) {
569638 require .IsType ((* Request )(nil ), v )
570639 assert .Equal (
571640 Request {
572- Logger : sallust .Default (),
573- Claims : map [string ]interface {}{"claim" : "value" },
574- Metadata : make (map [string ]interface {}),
641+ Logger : sallust .Default (),
642+ Claims : map [string ]interface {}{"claim" : "value" },
643+ Metadata : make (map [string ]interface {}),
644+ PathValues : make (map [string ]interface {}),
575645 },
576646 * v .(* Request ),
577647 )
0 commit comments