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

ngtests: Test fetch target #1728

Merged
merged 4 commits into from
Dec 22, 2021

Conversation

sechkova
Copy link
Contributor

Fixes #1642

Description of the changes being introduced by the pull request:

Adds tests for 'Fetch target' from 'Detailed client workflow' and target files storing/loading from cache.

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

@coveralls
Copy link

coveralls commented Dec 14, 2021

Pull Request Test Coverage Report for Build 1606548701

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 97.702%

Totals Coverage Status
Change from base Build 1606187413: 0.0%
Covered Lines: 4095
Relevant Lines: 4175

💛 - Coveralls

Copy link
Collaborator

@kairoaraujo kairoaraujo left a comment

Choose a reason for hiding this comment

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

I have just a small suggestion.

tests/test_updater_fetch_target.py Show resolved Hide resolved
tests/test_updater_fetch_target.py Show resolved Hide resolved
tests/test_updater_fetch_target.py Show resolved Hide resolved
tests/test_updater_fetch_target.py Show resolved Hide resolved
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. I think the cache-miss case should test that we successfully overwrite the "incorrect" file as well. Other comments are just nits.

It feels like three test cases is not a lot... but I can't think of what else to add so 🤷

Would using delegated targets give us any useful test coverage? the actual delegation lookups are tested elsewhere so maybe not?

self.temp_dir.cleanup()

def _init_updater(self) -> Updater:
"""Creates a new updater and runs refresh."""
Copy link
Member

Choose a reason for hiding this comment

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

does not run refresh

return updater

targets: utils.DataSet = {
"standard case": ("targetpath", b"content", "targetpath"),
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 it would be good to add at least a comment about the contents of this tuple (or make it into a namedtuple or dataclass). Understanding what each "targetpath" means currently requires reading code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a data class for target files in another PR before this one and I was planning to use it but it is not yet merged so in other words I got tangled in my own PRs ...

Copy link
Contributor Author

@sechkova sechkova Dec 21, 2021

Choose a reason for hiding this comment

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

I added a dataclass TestTarget in test_updater_fetch_target.py too which is slightly different than the one in test_updater_delegation_graphs.py . I realise the same name is not great but I was wondering should I rename one of the classes or we should try making the dataclasses reusable between test files. d1bc201

Comment on lines 152 to 174
# Newer content is detected, old cached version is not used
updater = self._init_updater()
info = updater.get_targetinfo(targetpath)
assert info is not None
self.assertIsNone(updater.find_cached_target(info))
Copy link
Member

Choose a reason for hiding this comment

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

please continue with download_target and verifying that

  • find_cached_target() now returns the path
  • cached files now has the new content

Add a new test file and class for testing target files
fetching.
Move test_targets from test_updater_with_simulator.py to
tests/test_updater_fetch_targets.py.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
Remove parts of the test case which are covered in other
tests, this way making its purpose clearer.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
Add test cases covering downloading and loading from cache
targets with non-matching hash and length.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
Use a dataclass for a better representation of
the target files in the test data set.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
@sechkova
Copy link
Contributor Author

The cache miss test is improved and I agree defining a dataclass does improve readability I am not sure about the naming though, see my comment above.

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 to me!

@kairoaraujo
Copy link
Collaborator

LGTM

@sechkova sechkova merged commit e752193 into theupdateframework:develop Dec 22, 2021
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.

ngtests: add tests for fetching targets
4 participants