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

Apply validation to default values even when values do not come from the configuration #142

Merged
merged 4 commits into from
Jan 29, 2020

Conversation

blakerouse
Copy link
Contributor

@blakerouse blakerouse commented Jan 25, 2020

When unpacking into an object that already has values present but the configuration doesn't contains values for those objects still apply validation to the objects existing values. This is to ensure that even defaults that might already be set in the object that is passed to Unpack adheres to the same validation rules that the configuration must adhere to.

This also contains a fix on how validateRequired would return an ErrEmpty error instead of an ErrRequired. When using the validate:"required" tag the error message should match the tag applied.

Closes #42

@codecov-io
Copy link

codecov-io commented Jan 25, 2020

Codecov Report

Merging #142 into master will increase coverage by 0.31%.
The diff coverage is 89.32%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #142      +/-   ##
==========================================
+ Coverage   78.05%   78.36%   +0.31%     
==========================================
  Files          24       24              
  Lines        2643     2709      +66     
==========================================
+ Hits         2063     2123      +60     
- Misses        428      431       +3     
- Partials      152      155       +3
Impacted Files Coverage Δ
reify.go 69.66% <88.46%> (-0.17%) ⬇️
validator.go 71.55% <88.88%> (+3.77%) ⬆️
util.go 94.28% <91.3%> (+1.6%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4fd3937...a260db1. Read the comment docs.

validator.go Show resolved Hide resolved
…er array and map passed to Unpack for default validation. Factor out a accessField helper that both validation path and reify path can use.
@blakerouse
Copy link
Contributor Author

@urso PR is ready for another review.

util.go Outdated Show resolved Hide resolved
util.go Outdated Show resolved Hide resolved
@blakerouse blakerouse merged commit 19165f5 into elastic:master Jan 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Apply validators to default values
4 participants