@@ -386,6 +386,158 @@ func TestRunner_testAndSet_concurrent(t *testing.T) {
386386 require .Equal (t , 1 , winCount , "exactly one goroutine should win testAndSet for the same key" )
387387}
388388
389+ func TestOptions_hasMatcherOrFilter (t * testing.T ) {
390+ tests := []struct {
391+ name string
392+ options Options
393+ expected bool
394+ }{
395+ {
396+ name : "no matchers or filters" ,
397+ options : Options {},
398+ expected : false ,
399+ },
400+ {
401+ name : "match status code" ,
402+ options : Options {OutputMatchStatusCode : "200" },
403+ expected : true ,
404+ },
405+ {
406+ name : "filter status code" ,
407+ options : Options {OutputFilterStatusCode : "403,401" },
408+ expected : true ,
409+ },
410+ {
411+ name : "match string" ,
412+ options : Options {OutputMatchString : []string {"admin" }},
413+ expected : true ,
414+ },
415+ {
416+ name : "filter string" ,
417+ options : Options {OutputFilterString : []string {"error" }},
418+ expected : true ,
419+ },
420+ {
421+ name : "match content length" ,
422+ options : Options {OutputMatchContentLength : "100" },
423+ expected : true ,
424+ },
425+ {
426+ name : "filter content length" ,
427+ options : Options {OutputFilterContentLength : "0" },
428+ expected : true ,
429+ },
430+ {
431+ name : "match regex" ,
432+ options : Options {OutputMatchRegex : []string {"admin.*panel" }},
433+ expected : true ,
434+ },
435+ {
436+ name : "filter regex" ,
437+ options : Options {OutputFilterRegex : []string {"error" }},
438+ expected : true ,
439+ },
440+ {
441+ name : "match lines count" ,
442+ options : Options {OutputMatchLinesCount : "50" },
443+ expected : true ,
444+ },
445+ {
446+ name : "filter lines count" ,
447+ options : Options {OutputFilterLinesCount : "0" },
448+ expected : true ,
449+ },
450+ {
451+ name : "match words count" ,
452+ options : Options {OutputMatchWordsCount : "100" },
453+ expected : true ,
454+ },
455+ {
456+ name : "filter words count" ,
457+ options : Options {OutputFilterWordsCount : "0" },
458+ expected : true ,
459+ },
460+ {
461+ name : "match favicon" ,
462+ options : Options {OutputMatchFavicon : []string {"1494302000" }},
463+ expected : true ,
464+ },
465+ {
466+ name : "filter favicon" ,
467+ options : Options {OutputFilterFavicon : []string {"1494302000" }},
468+ expected : true ,
469+ },
470+ {
471+ name : "match cdn" ,
472+ options : Options {OutputMatchCdn : []string {"cloudflare" }},
473+ expected : true ,
474+ },
475+ {
476+ name : "filter cdn" ,
477+ options : Options {OutputFilterCdn : []string {"cloudflare" }},
478+ expected : true ,
479+ },
480+ {
481+ name : "match condition" ,
482+ options : Options {OutputMatchCondition : "status_code == 200" },
483+ expected : true ,
484+ },
485+ {
486+ name : "filter condition" ,
487+ options : Options {OutputFilterCondition : "status_code == 403" },
488+ expected : true ,
489+ },
490+ {
491+ name : "match response time" ,
492+ options : Options {OutputMatchResponseTime : "< 1" },
493+ expected : true ,
494+ },
495+ {
496+ name : "filter response time" ,
497+ options : Options {OutputFilterResponseTime : "> 5" },
498+ expected : true ,
499+ },
500+ {
501+ name : "filter page type" ,
502+ options : Options {OutputFilterPageType : []string {"error" }},
503+ expected : true ,
504+ },
505+ }
506+
507+ for _ , tc := range tests {
508+ t .Run (tc .name , func (t * testing.T ) {
509+ opts := tc .options
510+ err := opts .ValidateOptions ()
511+ require .Nil (t , err )
512+ require .Equal (t , tc .expected , opts .HasMatcherOrFilter (),
513+ "HasMatcherOrFilter() should be %v for %s" , tc .expected , tc .name )
514+ })
515+ }
516+ }
517+
518+ func TestStoreResponse_withoutMatchersStoresAll (t * testing.T ) {
519+ dir := t .TempDir ()
520+ opts := & Options {
521+ StoreResponse : true ,
522+ StoreResponseDir : dir ,
523+ }
524+ err := opts .ValidateOptions ()
525+ require .Nil (t , err )
526+ require .False (t , opts .HasMatcherOrFilter ())
527+ }
528+
529+ func TestStoreResponse_withMatcherSetsFlag (t * testing.T ) {
530+ dir := t .TempDir ()
531+ opts := & Options {
532+ StoreResponse : true ,
533+ StoreResponseDir : dir ,
534+ OutputMatchStatusCode : "200" ,
535+ }
536+ err := opts .ValidateOptions ()
537+ require .Nil (t , err )
538+ require .True (t , opts .HasMatcherOrFilter ())
539+ }
540+
389541func TestRunner_duplicate (t * testing.T ) {
390542 const (
391543 pageA = "HTTP/1.1 200 OK\r \n Content-Type: text/html\r \n \r \n <html><head><title>Welcome</title></head><body>Hello world default page content here</body></html>"
0 commit comments