Skip to content

Commit

Permalink
Merge pull request #1194 from igorrius/extend-altscr
Browse files Browse the repository at this point in the history
#1193 Expose constructor of MapInputSource type
  • Loading branch information
rliebz committed Oct 31, 2020
2 parents 5fed9f1 + 7f00501 commit a99b68f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 5 additions & 0 deletions altsrc/map_input_source.go
Expand Up @@ -16,6 +16,11 @@ type MapInputSource struct {
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.
// If so, it tries to traverse the tree by the '.' delimited sections to find
// a nested value for the key.
Expand Down
9 changes: 4 additions & 5 deletions altsrc/map_input_source_test.go
Expand Up @@ -6,14 +6,13 @@ import (
)

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

0 comments on commit a99b68f

Please sign in to comment.