-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NewProviderGroup: Handle empty sources correctly (#95)
We were encountering a bug where `NewProviderGroup` was interpreting empty files correctly despite the previous fix. Specifically, the following works with `NewYAML`, # foo.yaml contains: # # foo: # bar: 42 p := NewYAML(File("foo.yaml"), File("empty.yaml"))) fmt.Println(p.Get("foo.bar").Value()) // Output: 42 But the following does not, p1 := NewYAML(File("foo.yaml")) p2 := NewYAML(File("empty.yaml")) p := NewProviderGroup(p1, p2) fmt.Println(p.Get("foo.bar").Value()) // Output: nil It doesn't work because `NewProviderGroup` works by calling `Get(Root)` on the providers and building a new `Provider` with the merged contents. `p2` doesn't know the difference between empty file and `nil` so it returns `nil` for its contents, which the merging logic interprets as unsetting everything at that level. Unfortunately, switching this call site from `NewProviderGroup` to `NewYAML` isn't possible because `NewYAML` applies options like `Permissive` and `Expand` to all files and we don't want to `Expand` on one of the files. To fix this, I made two changes: - YAML providers now have a record of whether they were empty or not. When a `Get` is performed on a`YAML` provider, the resulting `Value` now accurately knows whether it has a value. - `NewProviderGroup` includes the contents of a provider only if its `Value.HasValue` returns true. I added failing test cases for this case. I replicated that test for the null sources case to avoid accidentally breaking it in the future.
- Loading branch information
Showing
4 changed files
with
131 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters