Skip to content

Commit

Permalink
updating tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SethHollandsworth committed Mar 22, 2024
1 parent 3a328f2 commit 2274bbf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
31 changes: 14 additions & 17 deletions src/confcom/azext_confcom/os_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,23 +145,20 @@ def map_image_from_tar(image_name: str, tar: TarFile, tar_location: str):
tar_dir = os.path.dirname(tar_location)
info_file = None
info_file_name = "manifest.json"
# if there's more than one image in the tarball, we need to do some more logic
if len(info_file_name) > 0:
# extract just the manifest file and see if any of the RepoTags match the image_name we're searching for
# the manifest.json should have a list of all the image tags
# and what json files they map to to get env vars, startup cmd, etc.
tar.extract(info_file_name, path=tar_dir)
manifest_path = os.path.join(tar_dir, info_file_name)
manifest = load_json_from_file(manifest_path)
# if we match a RepoTag to the image, stop searching
for image in manifest:
if image_name in image.get("RepoTags"):
info_file = image.get("Config")
break
# remove the extracted manifest file to clean up
os.remove(manifest_path)
else:
eprint(f"Tarball at {tar_location} contains no images")

# extract just the manifest file and see if any of the RepoTags match the image_name we're searching for
# the manifest.json should have a list of all the image tags
# and what json files they map to to get env vars, startup cmd, etc.
tar.extract(info_file_name, path=tar_dir)
manifest_path = os.path.join(tar_dir, info_file_name)
manifest = load_json_from_file(manifest_path)
# if we match a RepoTag to the image, stop searching
for image in manifest:
if image_name in image.get("RepoTags"):
info_file = image.get("Config")
break
# remove the extracted manifest file to clean up
os.remove(manifest_path)

if not info_file:
return None
Expand Down
2 changes: 1 addition & 1 deletion src/confcom/azext_confcom/template_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ def get_diff_size(diff: dict) -> int:
if isinstance(diff[key], dict):
size += get_diff_size_helper(diff[key])
else:
size += 10
size += 1
return size

def get_diff_size_helper(diff: dict) -> int:
Expand Down
4 changes: 2 additions & 2 deletions src/confcom/azext_confcom/tests/latest/test_confcom_arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1626,7 +1626,7 @@ def test_incorrect_policy_diff(self):
is_valid, diff = self.aci_policy2.validate_cce_policy()
self.assertFalse(is_valid)
expected_diff = {
"alpine:3.16": {
"aci-test": {
"values_changed": {
"mounts": [
{
Expand Down Expand Up @@ -3579,7 +3579,7 @@ def test_arm_template_with_env_var(self):

# see if the remote image and the local one produce the same output
self.assertEqual(env_var, "PORT=parameters('abc')")
self.assertEqual(regular_image_json[0][config.POLICY_FIELD_CONTAINERS_ID], "alpine:3.16")
self.assertEqual(regular_image_json[0][config.POLICY_FIELD_CONTAINERS_ID], "simple-container")


class PolicyGeneratingSecurityContext(unittest.TestCase):
Expand Down

0 comments on commit 2274bbf

Please sign in to comment.