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

Fix config bug where mockery crashes when package map is nil #730

Merged
merged 7 commits into from
Nov 6, 2023

Conversation

LandonTClipp
Copy link
Collaborator

@LandonTClipp LandonTClipp commented Nov 5, 2023

Description

This PR fixes a number of things related to config parsing.

  1. When the packages map contained a package that pointed to a nil value, mocker would crash because it expected the mapping to be non-empty. The PR changes it so that mockery gracefully handles cases like this by lazily injecting a config map into the package.
  2. When merging in the top-level config with a package-provided config, the old code referenced an existing map structure which caused infinite loops in situations like showconfig, or really in any situation where you wanted to serialized the config using a yaml parser. The fix was to do a deep copy of the configuration whenever merging top-level with package-level config.

Also moving to using gotestsum for test output. This provides a much cleaner overview of the tests that passed/failed.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Version of Golang used when building/testing:

  • 1.11
  • 1.12
  • 1.13
  • 1.14
  • 1.15
  • 1.16
  • 1.17
  • 1.18
  • 1.19
  • 1.20

How Has This Been Tested?

Unit test

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Fixes issue vektra#726.

We needed an additional bit of logic to ensure that if the `config` section
is nil that we default it to being an empty map.
This commit adds a fix where we create a copy of the top-level config map, instead
of using it directly. Previously this situation caused an infinite loop in the
map structure, so creating a copy prevents that from happening.
The test wasn't properly initializing the viper object so the config
wasn't getting decoded into the struct properly.

Also adding more comments to various places to better explain what the
code was doing, as even I, the person who wrote it, was confused as to what
I was doing. How can I expect other people to understand it if I can't?!
Copy link

codecov bot commented Nov 6, 2023

Codecov Report

Attention: 24 lines in your changes are missing coverage. Please review.

Comparison is base (726d76c) 75.44910% compared to head (b648c23) 75.25042%.

Additional details and impacted files
@@                 Coverage Diff                 @@
##              master        #730         +/-   ##
===================================================
- Coverage   75.44910%   75.25042%   -0.19868%     
===================================================
  Files              9           9                 
  Lines           2338        2396         +58     
===================================================
+ Hits            1764        1803         +39     
- Misses           438         455         +17     
- Partials         136         138          +2     
Files Coverage Δ
cmd/showconfig.go 47.05882% <40.00000%> (+0.18381%) ⬆️
pkg/config/config.go 69.79656% <77.41935%> (-0.18629%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

fix usage of predeclared identifier
Subpackages were not correctly inheriting their parent package
configuration.
@LandonTClipp LandonTClipp merged commit deb4860 into vektra:master Nov 6, 2023
4 of 5 checks passed
@LandonTClipp LandonTClipp deleted the issue_726 branch November 6, 2023 04:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant