@@ -294,6 +294,41 @@ func TestHookRequest_Marshal(t *testing.T) {
294294 testJSONMarshal (t , r , want )
295295}
296296
297+ func TestHookRequest_GetHeader (t * testing.T ) {
298+ t .Parallel ()
299+
300+ header := make (map [string ]string )
301+ header ["key1" ] = "value1"
302+ header ["Key+2" ] = "value2"
303+ header ["kEy-3" ] = "value3"
304+ header ["KEY_4" ] = "value4"
305+
306+ r := & HookRequest {
307+ Headers : header ,
308+ }
309+
310+ // Checking positive cases
311+ testPrefixes := []string {"key" , "Key" , "kEy" , "KEY" }
312+ for hdrKey , hdrValue := range header {
313+ for _ , prefix := range testPrefixes {
314+ key := prefix + hdrKey [3 :]
315+ if val := r .GetHeader (key ); val != hdrValue {
316+ t .Errorf ("GetHeader(%q) is not working: %q != %q" , key , val , hdrValue )
317+ }
318+ }
319+ }
320+
321+ // Checking negative case
322+ key := "asd"
323+ if val := r .GetHeader (key ); val != "" {
324+ t .Errorf ("GetHeader(%q) should return empty value: %q != %q" , key , val , "" )
325+ }
326+ key = "kay1"
327+ if val := r .GetHeader (key ); val != "" {
328+ t .Errorf ("GetHeader(%q) should return empty value: %q != %q" , key , val , "" )
329+ }
330+ }
331+
297332func TestHookResponse_Marshal (t * testing.T ) {
298333 t .Parallel ()
299334 testJSONMarshal (t , & HookResponse {}, "{}" )
@@ -320,6 +355,41 @@ func TestHookResponse_Marshal(t *testing.T) {
320355 testJSONMarshal (t , r , want )
321356}
322357
358+ func TestHookResponse_GetHeader (t * testing.T ) {
359+ t .Parallel ()
360+
361+ header := make (map [string ]string )
362+ header ["key1" ] = "value1"
363+ header ["Key+2" ] = "value2"
364+ header ["kEy-3" ] = "value3"
365+ header ["KEY_4" ] = "value4"
366+
367+ r := & HookResponse {
368+ Headers : header ,
369+ }
370+
371+ // Checking positive cases
372+ testPrefixes := []string {"key" , "Key" , "kEy" , "KEY" }
373+ for hdrKey , hdrValue := range header {
374+ for _ , prefix := range testPrefixes {
375+ key := prefix + hdrKey [3 :]
376+ if val := r .GetHeader (key ); val != hdrValue {
377+ t .Errorf ("GetHeader(%q) is not working: %q != %q" , key , val , hdrValue )
378+ }
379+ }
380+ }
381+
382+ // Checking negative case
383+ key := "asd"
384+ if val := r .GetHeader (key ); val != "" {
385+ t .Errorf ("GetHeader(%q) should return empty value: %q != %q" , key , val , "" )
386+ }
387+ key = "kay1"
388+ if val := r .GetHeader (key ); val != "" {
389+ t .Errorf ("GetHeader(%q) should return empty value: %q != %q" , key , val , "" )
390+ }
391+ }
392+
323393func TestHookDelivery_Marshal (t * testing.T ) {
324394 t .Parallel ()
325395 testJSONMarshal (t , & HookDelivery {}, "{}" )
0 commit comments