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

Improve Unit Testing #152

Merged
merged 13 commits into from
Mar 15, 2024
Merged

Improve Unit Testing #152

merged 13 commits into from
Mar 15, 2024

Conversation

jordlay
Copy link
Collaborator

@jordlay jordlay commented Feb 28, 2024


This PR includes:

  • fixing existing broken tests such as artifact, bicep and definition folder builder
  • adding processor testing
  • adding arm template input testing
  • adding structure for testing of generate config, publish, inputs and definition_folder
  • adding mocks to be shared across tests
  • removal of old tests
  • NOTE: build is going to be tested with integration tests, and diffing the output folders of the tests.

This checklist is used to make sure that common guidelines for a pull request are followed.

Related command

General Guidelines

  • Have you run azdev style <YOUR_EXT> locally? (pip install azdev required)
  • Have you run python scripts/ci/test_index.py -q locally? (pip install wheel==0.30.0 required)

For new extensions:

About Extension Publish

There is a pipeline to automatically build, upload and publish extension wheels.
Once your pull request is merged into main branch, a new pull request will be created to update src/index.json automatically.
You only need to update the version information in file setup.py and historical information in file HISTORY.rst in your PR but do not modify src/index.json.

)]

# Testing each individial part of artifact are equal
self.assertEqual(artifact_details[0][0].artifact_name, mock_artifact[0].artifact_name)
Copy link

@atindall9041 atindall9041 Mar 7, 2024

Choose a reason for hiding this comment

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

this makes me think a class for the return type of get_artifact_details might be useful. You might even reduce the amount of code by not needing to document the current Tuple(list,list) in each get_artifact_details implementation, and it would make these assertions easier to understand

read_data='{"$schema": "#", "resources": { } }'))
def test_get_schema_no_parameters(self):
"""Test getting the schema for the ARM template input when no parameters are found."""
# Assert logger warning when no parameters in file
Copy link

@atindall9041 atindall9041 Mar 8, 2024

Choose a reason for hiding this comment

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

is this really the only error case for ArmTemplateInput?
(I'm kind of surprised it's so relaxed about its inputs that the worst thing that could possibly happen results in a warning log)

Copy link
Collaborator

Choose a reason for hiding this comment

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

There is also an error case if template_path does not exist, in which case the open will raise an error (we which are not handling - bad thing but not really part of your story.)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I didn't see you add the test for this error

@patrykkulik-microsoft
Copy link
Collaborator

have you run style and linting?

read_data='{"$schema": "#", "resources": { } }'))
def test_get_schema_no_parameters(self):
"""Test getting the schema for the ARM template input when no parameters are found."""
# Assert logger warning when no parameters in file
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is also an error case if template_path does not exist, in which case the open will raise an error (we which are not handling - bad thing but not really part of your story.)

@@ -82,12 +68,20 @@ def test_get_schema_with_params(self):
'required': [],
'type': 'object'
}
print("SCHEMA", schema)
self.assertEqual(schema, expected_schema)

@patch("builtins.open", mock_open(
read_data='{"$schema": "#", "resources": { } }'))
Copy link
Collaborator

Choose a reason for hiding this comment

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

what about this patch open? We should be able to solve it the same was as the previous one

@patrykkulik-microsoft patrykkulik-microsoft merged commit a73a246 into main Mar 15, 2024
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.

3 participants