Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandr Samylkin committed May 12, 2017
1 parent 18e810f commit ef30a68
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ func TestLoader_LoadFromTestEnvironment(t *testing.T) {
withBase(t, f, "value: base")
}

func TestLoader_LoadNotInterpolatedFiles(t *testing.T) {
func TestLoader_DefaultLoadOfStaticConfigFiles(t *testing.T) {
t.Parallel()
f := func(dir string) {
l := NewLoader()
Expand Down
26 changes: 15 additions & 11 deletions config/static_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package config
import (
"bytes"
"gopkg.in/yaml.v2"
"io"
"io/ioutil"
)

Expand All @@ -33,23 +34,17 @@ type staticProvider struct {
// NewStaticProvider should only be used in tests to isolate config from your environment
// It is not race free, because underlying objects can be accessed with Value().
func NewStaticProvider(data interface{}) Provider {
b, err := yaml.Marshal(data)
if err != nil {
panic(err)
return staticProvider{
Provider: NewYAMLProviderFromReader(toReadCloser(data)),
}

return staticProvider{Provider: NewYAMLProviderFromBytes(b)}
}

// NewStaticProviderWithExpand returns a static provider with values replaced by a mapping function.
func NewStaticProviderWithExpand(data interface{}, mapping func(string) (string, bool)) Provider {
b, err := yaml.Marshal(data)
if err != nil {
panic(err)
}

r := ioutil.NopCloser(bytes.NewBuffer(b))
return staticProvider{Provider: NewYAMLProviderFromReaderWithExpand(mapping, r)}
return staticProvider{
Provider: NewYAMLProviderFromReaderWithExpand(mapping, toReadCloser(data)),
}
}

// StaticProvider returns function to create StaticProvider during configuration initialization
Expand All @@ -62,3 +57,12 @@ func StaticProvider(data interface{}) ProviderFunc {
func (staticProvider) Name() string {
return "static"
}

func toReadCloser(data interface{}) io.ReadCloser {
b, err := yaml.Marshal(data)
if err != nil {
panic(err)
}

return ioutil.NopCloser(bytes.NewBuffer(b))
}

0 comments on commit ef30a68

Please sign in to comment.