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

Refactor tests. #114

Merged
merged 1 commit into from
Jan 3, 2023
Merged

Refactor tests. #114

merged 1 commit into from
Jan 3, 2023

Conversation

htorianik
Copy link
Contributor

Refactor unit tests to make the code prettier and make fail messages more informative by utilizing nose2 tests generators feature

Test fail output before

You can't see the failed file

FAIL: test_load_terraform_from_cache (test.unit.test_load.TestLoad) [terraform-config/route_table.tf]
Test parsing a set of hcl2 files from a cached parser file
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/htorianik/amplify/current/python-hcl2/test/unit/test_load.py", line 53, in _load_test_files
    self.assertDictEqual(hcl2_dict, json_dict, f"failed comparing {file_path}")
AssertionError: {'res[287 chars]': {'count': '${var.tgw_name == "" ? 0 : var.n[179 chars]}}}]} != {'res[287 chars]': {'hello': 'world', 'count': '${var.tgw_name[197 chars]}}}]}
Diff is 1045 characters long. Set self.maxDiff to None to see it. : failed comparing terraform-config/route_table.tf

Test fail output after

You can see the failed file

FAIL: test_load_terraform_from_cache:6
'route_table.tf' (test.unit.test_load.TestLoad)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/htorianik/amplify/current/python-hcl2/test/unit/test_load.py", line 46, in check_terraform
    self.assertDictEqual(hcl2_dict, json_dict, f"failed comparing {hcl_path_str}")
AssertionError: {'res[287 chars]': {'count': '${var.tgw_name == "" ? 0 : var.n[179 chars]}}}]} != {'res[287 chars]': {'hello': 'world', 'count': '${var.tgw_name[197 chars]}}}]}
Diff is 1045 characters long. Set self.maxDiff to None to see it. : failed comparing route_table.tf

Success test output before

test_load_terraform (test.unit.test_load.TestLoad)
Test parsing a set of hcl2 files and force recreating the parser file ... ok
test_load_terraform_from_cache (test.unit.test_load.TestLoad)
Test parsing a set of hcl2 files from a cached parser file ... ok

Success test output after

test_load_terraform:1
'cloudwatch.tf' (test.unit.test_load.TestLoad) ... ok
test_load_terraform:2
'iam.tf' (test.unit.test_load.TestLoad) ... ok
test_load_terraform:3
'variables.tf' (test.unit.test_load.TestLoad) ... ok
test_load_terraform:4
's3.tf' (test.unit.test_load.TestLoad) ... ok
test_load_terraform:5
'locals_embedded_function.tf' (test.unit.test_load.TestLoad) ... ok
test_load_terraform:6
'route_table.tf' (test.unit.test_load.TestLoad) ... ok
test_load_terraform:7
'locals_embedded_multi_function_nested.tf' (test.unit.test_load.TestLoad) ... ok
test_load_terraform:8
'data_sources.tf' (test.unit.test_load.TestLoad) ... ok
test_load_terraform:9
'locals_embedded_interpolation.tf' (test.unit.test_load.TestLoad) ... ok
test_load_terraform:10
'vars.auto.tfvars' (test.unit.test_load.TestLoad) ... ok
test_load_terraform:11
'backend.tf' (test.unit.test_load.TestLoad) ... ok
test_load_terraform_from_cache:1
'cloudwatch.tf' (test.unit.test_load.TestLoad) ... ok
test_load_terraform_from_cache:2
'iam.tf' (test.unit.test_load.TestLoad) ... ok
test_load_terraform_from_cache:3
'variables.tf' (test.unit.test_load.TestLoad) ... ok
test_load_terraform_from_cache:4
's3.tf' (test.unit.test_load.TestLoad) ... ok
test_load_terraform_from_cache:5
'locals_embedded_function.tf' (test.unit.test_load.TestLoad) ... ok
test_load_terraform_from_cache:6
'route_table.tf' (test.unit.test_load.TestLoad) ... ok
test_load_terraform_from_cache:7
'locals_embedded_multi_function_nested.tf' (test.unit.test_load.TestLoad) ... ok
test_load_terraform_from_cache:8
'data_sources.tf' (test.unit.test_load.TestLoad) ... ok
test_load_terraform_from_cache:9
'locals_embedded_interpolation.tf' (test.unit.test_load.TestLoad) ... ok
test_load_terraform_from_cache:10
'vars.auto.tfvars' (test.unit.test_load.TestLoad) ... ok
test_load_terraform_from_cache:11
'backend.tf' (test.unit.test_load.TestLoad) ... ok

@htorianik htorianik requested a review from a team January 3, 2023 13:30
@htorianik htorianik merged commit 31c1f07 into master Jan 3, 2023
@htorianik htorianik deleted the refactor-unit-tests branch January 3, 2023 13:37
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