3131import java .util .Map ;
3232
3333import static java .util .Collections .singletonList ;
34+ import static java .util .Collections .singletonMap ;
3435import static org .hamcrest .Matchers .containsString ;
3536import static org .hamcrest .Matchers .equalTo ;
3637import static org .hamcrest .Matchers .instanceOf ;
@@ -403,11 +404,24 @@ public void testAddingDoWithWarningWithoutSkipWarnings() {
403404 DoSection doSection = new DoSection (new XContentLocation (lineNumber , 0 ));
404405 doSection .setExpectedWarningHeaders (singletonList ("foo" ));
405406 doSection .setApiCallSection (new ApiCallSection ("test" ));
406- ClientYamlTestSuite testSuite = createTestSuite (doSection );
407+ ClientYamlTestSuite testSuite = createTestSuite (SkipSection . EMPTY , doSection );
407408 Exception e = expectThrows (IllegalArgumentException .class , testSuite ::validate );
408- assertEquals ("api/name:\n attempted to add a [do] with a [warnings] section without a corresponding " +
409+ assertThat ( e . getMessage (), containsString ("api/name:\n attempted to add a [do] with a [warnings] section without a corresponding " +
409410 "[\" skip\" : \" features\" : \" warnings\" ] so runners that do not support the [warnings] section can skip the test " +
410- "at line [" + lineNumber + "]" , e .getMessage ());
411+ "at line [" + lineNumber + "]" ));
412+ }
413+
414+ public void testAddingDoWithHeaderWithoutSkipHeaders () {
415+ int lineNumber = between (1 , 10000 );
416+ DoSection doSection = new DoSection (new XContentLocation (lineNumber , 0 ));
417+ ApiCallSection apiCallSection = new ApiCallSection ("test" );
418+ apiCallSection .addHeaders (Collections .singletonMap ("header" , "value" ));
419+ doSection .setApiCallSection (apiCallSection );
420+ ClientYamlTestSuite testSuite = createTestSuite (SkipSection .EMPTY , doSection );
421+ Exception e = expectThrows (IllegalArgumentException .class , testSuite ::validate );
422+ assertThat (e .getMessage (), containsString ("api/name:\n attempted to add a [do] with a [headers] section without a corresponding " +
423+ "[\" skip\" : \" features\" : \" headers\" ] so runners that do not support the [headers] section can skip the test at line ["
424+ + lineNumber + "]" ));
411425 }
412426
413427 public void testAddingDoWithNodeSelectorWithoutSkipNodeSelector () {
@@ -416,11 +430,11 @@ public void testAddingDoWithNodeSelectorWithoutSkipNodeSelector() {
416430 ApiCallSection apiCall = new ApiCallSection ("test" );
417431 apiCall .setNodeSelector (NodeSelector .SKIP_DEDICATED_MASTERS );
418432 doSection .setApiCallSection (apiCall );
419- ClientYamlTestSuite testSuite = createTestSuite (doSection );
433+ ClientYamlTestSuite testSuite = createTestSuite (SkipSection . EMPTY , doSection );
420434 Exception e = expectThrows (IllegalArgumentException .class , testSuite ::validate );
421- assertEquals ( "api/name:\n attempted to add a [do] with a [node_selector] section without a corresponding"
422- + " [\" skip\" : \" features\" : \" node_selector\" ] so runners that do not support the [node_selector] section can skip the test at"
423- + " line [" + lineNumber + "]" , e . getMessage ( ));
435+ assertThat ( e . getMessage (), containsString ( "api/name:\n attempted to add a [do] with a [node_selector] section without a " +
436+ "corresponding [\" skip\" : \" features\" : \" node_selector\" ] so runners that do not support the [node_selector] section can " +
437+ "skip the test at line [" + lineNumber + "]" ));
424438 }
425439
426440 public void testAddingContainsWithoutSkipContains () {
@@ -429,11 +443,11 @@ public void testAddingContainsWithoutSkipContains() {
429443 new XContentLocation (lineNumber , 0 ),
430444 randomAlphaOfLength (randomIntBetween (3 , 30 )),
431445 randomDouble ());
432- ClientYamlTestSuite testSuite = createTestSuite (containsAssertion );
446+ ClientYamlTestSuite testSuite = createTestSuite (SkipSection . EMPTY , containsAssertion );
433447 Exception e = expectThrows (IllegalArgumentException .class , testSuite ::validate );
434- assertEquals ("api/name:\n attempted to add a [contains] assertion without a corresponding " +
448+ assertThat ( e . getMessage (), containsString ("api/name:\n attempted to add a [contains] assertion without a corresponding " +
435449 "[\" skip\" : \" features\" : \" contains\" ] so runners that do not support the [contains] assertion " +
436- "can skip the test at line [" + lineNumber + "]" , e . getMessage ( ));
450+ "can skip the test at line [" + lineNumber + "]" ));
437451 }
438452
439453 public void testMultipleValidationErrors () {
@@ -477,44 +491,13 @@ public void testMultipleValidationErrors() {
477491 e .getMessage ());
478492 }
479493
480- private static ClientYamlTestSuite createTestSuite (ExecutableSection executableSection ) {
481- final SetupSection setupSection ;
482- final TeardownSection teardownSection ;
483- final ClientYamlTestSection clientYamlTestSection ;
484- switch (randomIntBetween (0 , 2 )) {
485- case 0 :
486- setupSection = new SetupSection (SkipSection .EMPTY , Collections .singletonList (executableSection ));
487- teardownSection = TeardownSection .EMPTY ;
488- clientYamlTestSection = new ClientYamlTestSection (new XContentLocation (0 , 0 ), "test" ,
489- SkipSection .EMPTY , Collections .emptyList ());
490- break ;
491- case 1 :
492- setupSection = SetupSection .EMPTY ;
493- teardownSection = new TeardownSection (SkipSection .EMPTY , Collections .singletonList (executableSection ));
494- clientYamlTestSection = new ClientYamlTestSection (new XContentLocation (0 , 0 ), "test" ,
495- SkipSection .EMPTY , Collections .emptyList ());
496- break ;
497- case 2 :
498- setupSection = SetupSection .EMPTY ;
499- teardownSection = TeardownSection .EMPTY ;
500- clientYamlTestSection = new ClientYamlTestSection (new XContentLocation (0 , 0 ), "test" ,
501- SkipSection .EMPTY , Collections .singletonList (executableSection ));
502- break ;
503- default :
504- throw new UnsupportedOperationException ();
505- }
506-
507- return new ClientYamlTestSuite ("api" , "name" , setupSection , teardownSection ,
508- Collections .singletonList (clientYamlTestSection ));
509- }
510-
511494 public void testAddingDoWithWarningWithSkip () {
512495 int lineNumber = between (1 , 10000 );
513496 DoSection doSection = new DoSection (new XContentLocation (lineNumber , 0 ));
514497 doSection .setExpectedWarningHeaders (singletonList ("foo" ));
515498 doSection .setApiCallSection (new ApiCallSection ("test" ));
516499 SkipSection skipSection = new SkipSection (null , singletonList ("warnings" ), null );
517- createTestSuiteAndValidate (skipSection , doSection );
500+ createTestSuite (skipSection , doSection ). validate ( );
518501 }
519502
520503 public void testAddingDoWithNodeSelectorWithSkip () {
@@ -524,7 +507,17 @@ public void testAddingDoWithNodeSelectorWithSkip() {
524507 ApiCallSection apiCall = new ApiCallSection ("test" );
525508 apiCall .setNodeSelector (NodeSelector .SKIP_DEDICATED_MASTERS );
526509 doSection .setApiCallSection (apiCall );
527- createTestSuiteAndValidate (skipSection , doSection );
510+ createTestSuite (skipSection , doSection ).validate ();
511+ }
512+
513+ public void testAddingDoWithHeadersWithSkip () {
514+ int lineNumber = between (1 , 10000 );
515+ SkipSection skipSection = new SkipSection (null , singletonList ("headers" ), null );
516+ DoSection doSection = new DoSection (new XContentLocation (lineNumber , 0 ));
517+ ApiCallSection apiCallSection = new ApiCallSection ("test" );
518+ apiCallSection .addHeaders (singletonMap ("foo" , "bar" ));
519+ doSection .setApiCallSection (apiCallSection );
520+ createTestSuite (skipSection , doSection ).validate ();
528521 }
529522
530523 public void testAddingContainsWithSkip () {
@@ -534,10 +527,10 @@ public void testAddingContainsWithSkip() {
534527 new XContentLocation (lineNumber , 0 ),
535528 randomAlphaOfLength (randomIntBetween (3 , 30 )),
536529 randomDouble ());
537- createTestSuiteAndValidate (skipSection , containsAssertion );
530+ createTestSuite (skipSection , containsAssertion ). validate ( );
538531 }
539532
540- private static void createTestSuiteAndValidate (SkipSection skipSection , ExecutableSection executableSection ) {
533+ private static ClientYamlTestSuite createTestSuite (SkipSection skipSection , ExecutableSection executableSection ) {
541534 final SetupSection setupSection ;
542535 final TeardownSection teardownSection ;
543536 final ClientYamlTestSection clientYamlTestSection ;
@@ -571,13 +564,11 @@ private static void createTestSuiteAndValidate(SkipSection skipSection, Executab
571564 teardownSection = new TeardownSection (skipSection , Collections .singletonList (executableSection ));
572565 clientYamlTestSection = new ClientYamlTestSection (new XContentLocation (0 , 0 ), "test" ,
573566 SkipSection .EMPTY , randomBoolean () ? Collections .emptyList () : Collections .singletonList (executableSection ));
574-
575567 break ;
576568 default :
577569 throw new UnsupportedOperationException ();
578570 }
579- ClientYamlTestSuite clientYamlTestSuite = new ClientYamlTestSuite ("api" , "name" , setupSection , teardownSection ,
571+ return new ClientYamlTestSuite ("api" , "name" , setupSection , teardownSection ,
580572 Collections .singletonList (clientYamlTestSection ));
581- clientYamlTestSuite .validate ();
582573 }
583574}
0 commit comments