Merge pull request #1194 from igorrius/extend-altscr

#1193 Expose constructor of MapInputSource type
This commit is contained in:
Robert Liebowitz 2020-10-31 11:58:16 -04:00 committed by GitHub
commit a99b68f006
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View File

@ -16,6 +16,11 @@ type MapInputSource struct {
valueMap map[interface{}]interface{} valueMap map[interface{}]interface{}
} }
// NewMapInputSource creates a new MapInputSource for implementing custom input sources.
func NewMapInputSource(file string, valueMap map[interface{}]interface{}) *MapInputSource {
return &MapInputSource{file: file, valueMap: valueMap}
}
// nestedVal checks if the name has '.' delimiters. // nestedVal checks if the name has '.' delimiters.
// If so, it tries to traverse the tree by the '.' delimited sections to find // If so, it tries to traverse the tree by the '.' delimited sections to find
// a nested value for the key. // a nested value for the key.

View File

@ -6,14 +6,13 @@ import (
) )
func TestMapDuration(t *testing.T) { func TestMapDuration(t *testing.T) {
inputSource := &MapInputSource{ inputSource := NewMapInputSource(
file: "test", "test",
valueMap: map[interface{}]interface{}{ map[interface{}]interface{}{
"duration_of_duration_type": time.Minute, "duration_of_duration_type": time.Minute,
"duration_of_string_type": "1m", "duration_of_string_type": "1m",
"duration_of_int_type": 1000, "duration_of_int_type": 1000,
}, })
}
d, err := inputSource.Duration("duration_of_duration_type") d, err := inputSource.Duration("duration_of_duration_type")
expect(t, time.Minute, d) expect(t, time.Minute, d)
expect(t, nil, err) expect(t, nil, err)