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

Zip files for test cases #442

Open
Hritik14 opened this issue Apr 18, 2021 · 5 comments
Open

Zip files for test cases #442

Hritik14 opened this issue Apr 18, 2021 · 5 comments

Comments

@Hritik14
Copy link
Collaborator

Currently the following importers are using zip files in their unit tests.

  • rust
  • npm

It needs to be discussed if they are required.

@Hritik14 Hritik14 mentioned this issue Apr 18, 2021
6 tasks
@sbs2001
Copy link
Collaborator

sbs2001 commented Apr 19, 2021

Did you "grepped" for them in the tests ?

Those are used to simulate git repos in the tests. If you don't zip them then git will emit weird things.

@Hritik14
Copy link
Collaborator Author

I was using the same technique to simulate a git repo in the Mozilla importer though @pombredanne suggests to avoid zips.
I've implemented something like the following for now,

        cls.mock_file_changes = (
            {
                os.path.join(TEST_DATA, "mfsa2005-29.md"),
                os.path.join(TEST_DATA, "mfsa2014-30.md"),
                os.path.join(TEST_DATA, "mfsa2021-01.yml"),
                os.path.join(TEST_DATA, "mfsa2021-06.yml"),
                os.path.join(TEST_DATA, "mfsa2021-04.yml"),
            },
            set(),
        )
...
...
        with patch(
            "vulnerabilities.importers.MozillaDataSource.file_changes",
            return_value=self.mock_file_changes,
        ):
            with patch(
                "vulnerabilities.importers.MozillaDataSource._ensure_repository"
            ):
                runner.run()

@pombredanne
Copy link
Member

OK, so using a zip or tar for a special case of a git repo makes sense, but not for plain text test files.

@Hritik14
Copy link
Collaborator Author

@pombredanne the tests for git repo are handled by test cases for GitDataSource along the lines https://github.com/nexB/vulnerablecode/blob/09839b9198aaf970761c21f758a0bc138458fed9/vulnerabilities/tests/test_data_source.py#L98
So, do we really need to duplicate this test ? Files in git can be put as is then use the proposed python mock above to eliminate git specific tests.

@Hritik14
Copy link
Collaborator Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants