Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove test_updater_with_simulator.py #1741

Merged
merged 5 commits into from
Jan 7, 2022

Conversation

sechkova
Copy link
Contributor

@sechkova sechkova commented Dec 21, 2021

WIP since it is built on top of two other PRs

Description of the changes being introduced by the pull request:

test_updater_with_simulator.pywas initially added to to demonstrate the usage of RepositorySimulator when testing Updater. Now Updater is tested extensively using simulator in several other test files.

This PR removes the duplicated tests and moves the useful ones to the relevant test file.

Please verify and check that the pull request fulfills the following
requirements
:

  • The code follows the Code Style Guidelines
  • Tests have been added for the bug fix or new feature
  • Docs have been added for the bug fix or new feature

@sechkova
Copy link
Contributor Author

test_not_loading_targets_twice and test_snapshot_rollback_with_local_snapshot_hash_mismatch seemed fit for test_updater_top_level_update.py but since more tests related to cached metadata are on its way, I started thinking if they deserve a separate test file or this one can be renamed to better match its content ...

@coveralls
Copy link

coveralls commented Dec 21, 2021

Pull Request Test Coverage Report for Build 1607257357

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+1.0%) to 98.729%

Totals Coverage Status
Change from base Build 1606187413: 1.0%
Covered Lines: 3933
Relevant Lines: 3954

💛 - Coveralls

Remove TestUpdater.test_refresh from test_updater_with_simulator.
Testing refresh() is now extensively covered in the newly added
test_updater_top_level_update.py.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
Move test_fishy_rolenames to test_updater_delegation_graphs.py
and update the test setup.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
Move test_not_loading_targets_twice to
test_updater_top_level_update.py.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
Key rotations and metadata update are now extesively tested in:
- test_updater_key_rotations.py
- test_updater_top_level_update.py

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
Move the remaining
test_snapshot_rollback_with_local_snapshot_hash_mismatch
to test_updater_top_level_update.py and remove the file.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
@sechkova sechkova force-pushed the remove-updater-with-sim branch from 4263164 to 672df74 Compare December 22, 2021 11:24
@sechkova sechkova changed the title WIP: Remove test_updater_with_simulator.py Remove test_updater_with_simulator.py Dec 22, 2021
@sechkova sechkova marked this pull request as ready for review December 22, 2021 11:52
@sechkova sechkova added this to the Sprint 14 milestone Dec 22, 2021
Copy link
Collaborator

@MVrachev MVrachev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it looks good with only one question.

Comment on lines +506 to +531
@patch.object(builtins, "open", wraps=builtins.open)
def test_not_loading_targets_twice(self, wrapped_open: MagicMock) -> None:
# Do not load targets roles more than once when traversing
# the delegations tree

# Add new delegated targets, update the snapshot
spec_version = ".".join(SPECIFICATION_VERSION)
targets = Targets(1, spec_version, self.sim.safe_expiry, {}, None)
role = DelegatedRole("role1", [], 1, False, ["*"], None)
self.sim.add_delegation("targets", role, targets)
self.sim.update_snapshot()

# Run refresh, top-level roles are loaded
updater = self._run_refresh()
# Clean up calls to open during refresh()
wrapped_open.reset_mock()

# First time looking for "somepath", only 'role1' must be loaded
updater.get_targetinfo("somepath")
wrapped_open.assert_called_once_with(
os.path.join(self.metadata_dir, "role1.json"), "rb"
)
wrapped_open.reset_mock()
# Second call to get_targetinfo, all metadata is already loaded
updater.get_targetinfo("somepath")
wrapped_open.assert_not_called()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if this is the correct file for this test or it should be test_updater_delegation_graphs?
It seems we are actually using and testing delegation roles here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does define a delegation but the point is just to test file opens (so not specifically delegations or top level updates)... If this is the only issue with the PR, I think I'll merge as is and we can improve later

for fname in roles_to_filenames.values():
self.assertTrue(fname in local_metadata)

def test_keys_and_signatures(self) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some tests covering keys and signatures (like test_new_timestamp_fast_foward_recovery, test_root_rotation, etc) , but I'm not sure they follow the exact specific case covered here. I'm fine with deleting it though, if others find it unnecessary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine: this specific test was just me adding an example of how to modify sigs and keys when using the simulator. I think the simulator documentation and the better tests that now exist cover all that better by now.

Copy link
Member

@jku jku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks

@jku jku merged commit 3d4df87 into theupdateframework:develop Jan 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants