13
13
from functools import cached_property
14
14
from pathlib import Path
15
15
from textwrap import dedent
16
- from typing import ClassVar , List , Optional , Set
16
+ from typing import Any , ClassVar , Dict , List , Optional , Set
17
17
18
18
import requests # type: ignore
19
19
import semver
@@ -445,7 +445,7 @@ async def _run(self, current_acceptance_tests_result: StepResult) -> StepResult:
445
445
446
446
447
447
class LiveTestSuite (Enum ):
448
- ALL = "all "
448
+ ALL = "live "
449
449
REGRESSION = "regression"
450
450
VALIDATION = "validation"
451
451
@@ -557,13 +557,10 @@ def __init__(self, context: ConnectorContext) -> None:
557
557
self .connector_image = context .docker_image .split (":" )[0 ]
558
558
options = self .context .run_step_options .step_params .get (CONNECTOR_TEST_STEP_ID .CONNECTOR_LIVE_TESTS , {})
559
559
560
- self .connection_id = self .context .run_step_options .get_item_or_default (options , "connection-id" , None )
561
- self .pr_url = self .context .run_step_options .get_item_or_default (options , "pr-url" , None )
560
+ self .test_suite = self .context .run_step_options .get_item_or_default (options , "test-suite" , LiveTestSuite .REGRESSION .value )
561
+ self .connection_id = self ._get_connection_id (options )
562
+ self .pr_url = self ._get_pr_url (options )
562
563
563
- if not self .connection_id and self .pr_url :
564
- raise ValueError ("`connection-id` and `pr-url` are required to run live tests." )
565
-
566
- self .test_suite = self .context .run_step_options .get_item_or_default (options , "test-suite" , LiveTestSuite .ALL .value )
567
564
self .test_dir = self .test_suite_to_dir [LiveTestSuite (self .test_suite )]
568
565
self .control_version = self .context .run_step_options .get_item_or_default (options , "control-version" , None )
569
566
self .target_version = self .context .run_step_options .get_item_or_default (options , "target-version" , "dev" )
@@ -573,6 +570,26 @@ def __init__(self, context: ConnectorContext) -> None:
573
570
self .connection_subset = self .context .run_step_options .get_item_or_default (options , "connection-subset" , "sandboxes" )
574
571
self .run_id = os .getenv ("GITHUB_RUN_ID" ) or str (int (time .time ()))
575
572
573
+ def _get_connection_id (self , options : Dict [str , List [Any ]]) -> Optional [str ]:
574
+ if self .context .is_pr :
575
+ connection_id = self ._get_connection_from_test_connections ()
576
+ self .logger .info (
577
+ f"Context is { self .context .ci_context } ; got connection_id={ connection_id } from metadata.yaml liveTests testConnections."
578
+ )
579
+ else :
580
+ connection_id = self .context .run_step_options .get_item_or_default (options , "connection-id" , None )
581
+ self .logger .info (f"Context is { self .context .ci_context } ; got connection_id={ connection_id } from input options." )
582
+ return connection_id
583
+
584
+ def _get_pr_url (self , options : Dict [str , List [Any ]]) -> Optional [str ]:
585
+ if self .context .is_pr :
586
+ pull_request = self .context .pull_request .url if self .context .pull_request else None
587
+ self .logger .info (f"Context is { self .context .ci_context } ; got pull_request={ pull_request } from context." )
588
+ else :
589
+ pull_request = self .context .run_step_options .get_item_or_default (options , "pr-url" , None )
590
+ self .logger .info (f"Context is { self .context .ci_context } ; got pull_request={ pull_request } from input options." )
591
+ return pull_request
592
+
576
593
def _validate_job_can_run (self ) -> None :
577
594
connector_type = self .context .connector .metadata .get ("connectorType" )
578
595
connector_subtype = self .context .connector .metadata .get ("connectorSubtype" )
@@ -582,6 +599,30 @@ def _validate_job_can_run(self) -> None:
582
599
self .connection_subset == "sandboxes"
583
600
), f"Live tests for database sources may only be run against sandbox connections, got `connection_subset={ self .connection_subset } `."
584
601
602
+ assert self .connection_id , "`connection-id` is required to run live tests."
603
+ assert self .pr_url , "`pr_url` is required to run live tests."
604
+
605
+ if self .context .is_pr :
606
+ connection_id_is_valid = False
607
+ for test_suite in self .context .connector .metadata .get ("connectorTestSuitesOptions" , []):
608
+ if test_suite ["suite" ] == "liveTests" :
609
+ assert self .connection_id in [
610
+ option ["id" ] for option in test_suite .get ("testConnections" , [])
611
+ ], f"Connection ID { self .connection_id } was not in the list of valid test connections."
612
+ connection_id_is_valid = True
613
+ break
614
+ assert connection_id_is_valid , f"Connection ID { self .connection_id } is not a valid sandbox connection ID."
615
+
616
+ def _get_connection_from_test_connections (self ) -> Optional [str ]:
617
+ for test_suite in self .context .connector .metadata .get ("connectorTestSuitesOptions" , []):
618
+ if test_suite ["suite" ] == "liveTests" :
619
+ for option in test_suite .get ("testConnections" , []):
620
+ connection_id = option ["id" ]
621
+ connection_name = option ["name" ]
622
+ self .logger .info (f"Using connection name={ connection_name } ; id={ connection_id } " )
623
+ return connection_id
624
+ return None
625
+
585
626
async def _run (self , connector_under_test_container : Container ) -> StepResult :
586
627
"""Run the regression test suite.
587
628
@@ -594,9 +635,10 @@ async def _run(self, connector_under_test_container: Container) -> StepResult:
594
635
try :
595
636
self ._validate_job_can_run ()
596
637
except AssertionError as exc :
638
+ self .logger .info (f"Skipping live tests for { self .context .connector .technical_name } due to validation error { str (exc )} ." )
597
639
return StepResult (
598
640
step = self ,
599
- status = StepStatus .FAILURE ,
641
+ status = StepStatus .SKIPPED ,
600
642
exc_info = exc ,
601
643
)
602
644
@@ -624,6 +666,7 @@ async def _run(self, connector_under_test_container: Container) -> StepResult:
624
666
stdout = stdout ,
625
667
output = container ,
626
668
report = regression_test_report ,
669
+ consider_in_overall_status = False if self .context .is_pr else True ,
627
670
)
628
671
629
672
async def _build_test_container (self , target_container_id : str ) -> Container :
0 commit comments