Skip to content

Commit

Permalink
Increased test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
kjohn-msft committed Oct 31, 2023
1 parent 606c3ff commit b4e5242
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/core/tests/Test_CoreMain.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ def test_operation_success_for_autopatching_request(self):
argument_composer.maintenance_run_id = str(maintenance_run_id)
argument_composer.health_store_id = str("2020.09.28")
runtime = RuntimeCompositor(argument_composer.get_composed_arguments(), True, Constants.ZYPPER)
Constants.MAX_FILE_OPERATION_RETRY_COUNT = 2 # to retain retry coverage in at least one test
Constants.MAX_IMDS_CONNECTION_RETRY_COUNT = 2 # to retain retry coverage in at least one test
runtime.set_legacy_test_type('SuccessInstallPath')
CoreMain(argument_composer.get_composed_arguments())

Expand Down
20 changes: 18 additions & 2 deletions src/core/tests/Test_PatchInstaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,30 @@ def test_patch_installer_for_azgps_coordinated(self):
# Path change
runtime.set_legacy_test_type('HappyPath')
self.assertTrue(runtime.patch_installer.start_installation())
self.assertEqual(runtime.execution_config.max_patch_publish_date,"20240401T000000Z")
self.assertEqual(runtime.execution_config.max_patch_publish_date, "20240401T000000Z")
self.assertEqual(runtime.package_manager.max_patch_publish_date,"20240401T000000Z") # supported and conditions met
runtime.stop()

argument_composer.maximum_duration = "PT30M"
runtime = RuntimeCompositor(argument_composer.get_composed_arguments(), True, Constants.APT)
runtime.set_legacy_test_type('HappyPath')
self.assertFalse(runtime.patch_installer.start_installation())
self.assertFalse(runtime.patch_installer.start_installation()) # failure is in unrelated patch installation batch processing
self.assertEqual(runtime.execution_config.max_patch_publish_date, "20240401T000000Z")
self.assertEqual(runtime.package_manager.max_patch_publish_date, "") # reason: not enough time to use
runtime.stop()

runtime = RuntimeCompositor(argument_composer.get_composed_arguments(), True, Constants.YUM)
runtime.set_legacy_test_type('HappyPath')
self.assertTrue(runtime.patch_installer.start_installation())
self.assertEqual(runtime.execution_config.max_patch_publish_date, "20240401T000000Z")
self.assertEqual(runtime.package_manager.max_patch_publish_date, "") # unsupported in Yum
runtime.stop()

runtime = RuntimeCompositor(argument_composer.get_composed_arguments(), True, Constants.ZYPPER)
runtime.set_legacy_test_type('HappyPath')
self.assertFalse(runtime.patch_installer.start_installation()) # failure is in unrelated patch installation batch processing
self.assertEqual(runtime.execution_config.max_patch_publish_date, "20240401T000000Z")
self.assertEqual(runtime.package_manager.max_patch_publish_date, "") # unsupported in Zypper
runtime.stop()

def test_mark_status_completed_esm_required(self):
Expand Down
11 changes: 4 additions & 7 deletions src/core/tests/library/LegacyEnvLayerExtensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,10 @@ def run_command_output(self, cmd, no_output=False, chk_err=True):
"Ubuntu:16.10/yakkety-updates, Ubuntu:16.10/yakkety-security [amd64]) []\n"
elif cmd.find("grep -hR security /etc/apt/sources.list") > -1 or cmd.find("grep -hR \"\" /etc/apt/sources.list") > -1:
code = 0
output = "deb-src http://azure.archive.ubuntu.com/ubuntu/ jammy-security main restricted\n" + \
"deb-src http://azure.archive.ubuntu.com/ubuntu/ jammy-security universe\n" + \
"deb-src http://azure.archive.ubuntu.com/ubuntu/ jammy-security multiverse"
output = ("deb-src http://azure.archive.ubuntu.com/ubuntu/ jammy-security main restricted\n"
"deb-src http://azure.archive.ubuntu.com/ubuntu/ jammy-security universe\n"
"deb-src http://azure.archive.ubuntu.com/ubuntu/ jammy-security multiverse\n"
"deb-src https://snapshot.ubuntu.com/ubuntu/20240301T000000Z jammy-security universe")
self.write_to_file(os.path.join(self.temp_folder_path, "temp2.list"), output)
elif cmd.find("--only-upgrade true -s install") > -1 or cmd.find("apt-get -y --only-upgrade true upgrade") > -1:
code = 0
Expand Down Expand Up @@ -532,10 +533,6 @@ def run_command_output(self, cmd, no_output=False, chk_err=True):
output = " bash | 4.3-14ubuntu1.3 | http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages\n" + \
" bash | 4.3-14ubuntu1.2 | http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages\n" + \
" bash | 4.3-14ubuntu1 | http://us.archive.ubuntu.com/ubuntu xenial/main amd64 Packages"
elif cmd.find('sudo grep -hR security /etc/apt/sources.list /etc/apt/sources.list.d/ >') > -1:
self.write_to_file(os.path.join(self.temp_folder_path, "temp2.list"), "test temp file 2")
code = 0
output = "tmp file created"
elif cmd.find('sudo apt-get install ubuntu-advantage-tools -y') > -1:
code = 0
elif cmd.find('pro security-status --format=json') > -1:
Expand Down
2 changes: 2 additions & 0 deletions src/core/tests/library/RuntimeCompositor.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ def reconfigure_env_layer_to_legacy_mode(self):
self.env_layer.platform = self.legacy_env_layer_extensions.LegacyPlatform()
self.env_layer.set_legacy_test_mode()
self.env_layer.run_command_output = self.legacy_env_layer_extensions.run_command_output
if os.name == 'nt':
self.env_layer.etc_environment_file_path = os.getcwd()

def reconfigure_reboot_manager(self):
self.reboot_manager.start_reboot = self.start_reboot
Expand Down

0 comments on commit b4e5242

Please sign in to comment.