Skip to content

Commit

Permalink
Export Provider constructors taking io.Reader (#69)
Browse files Browse the repository at this point in the history
Export the already-existing constructor functions that take io.Reader. This
helps build Providers from sources other than files.
  • Loading branch information
meiliang86 authored and akshayjshah committed Sep 28, 2017
1 parent 3d2ab50 commit 45fa47e
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ rpc:
return "4324", true
}

p, err := newYAMLProviderFromReaderWithExpand(
p, err := NewYAMLProviderFromReaderWithExpand(
lookup,
ioutil.NopCloser(bytes.NewBufferString(rpc)))

Expand Down
2 changes: 1 addition & 1 deletion expand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func TestExpanderFailingTransform(t *testing.T) {
switch s {
case "t3sT":
return "test", nil
// missing "i5_" case
// missing "i5_" case
}

return "NOMATCH", errors.New("No Match")
Expand Down
4 changes: 2 additions & 2 deletions static_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewStaticProvider(data interface{}) (Provider, error) {
return nil, err
}

p, err := newYAMLProviderFromReader(c)
p, err := NewYAMLProviderFromReader(c)
if err != nil {
return nil, err
}
Expand All @@ -58,7 +58,7 @@ func NewStaticProviderWithExpand(
return nil, err
}

p, err := newYAMLProviderFromReaderWithExpand(mapping, reader)
p, err := NewYAMLProviderFromReaderWithExpand(mapping, reader)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion static_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func TestInterpolatedBool(t *testing.T) {
return "", false
}

p, err := newYAMLProviderFromReaderWithExpand(
p, err := NewYAMLProviderFromReaderWithExpand(
f,
ioutil.NopCloser(strings.NewReader("val: ${interpolate:false}")))

Expand Down
12 changes: 6 additions & 6 deletions yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func NewYAMLProviderFromFiles(files ...string) (Provider, error) {
readers[i] = r
}

provider, err := newYAMLProviderFromReader(readers...)
provider, err := NewYAMLProviderFromReader(readers...)

for _, r := range readClosers {
nerr := r.Close()
Expand Down Expand Up @@ -181,7 +181,7 @@ func NewYAMLProviderWithExpand(mapping func(string) (string, bool), files ...str
readers[i] = r
}

provider, err := newYAMLProviderFromReaderWithExpand(mapping,
provider, err := NewYAMLProviderFromReaderWithExpand(mapping,
readers...)

for _, r := range readClosers {
Expand All @@ -196,7 +196,7 @@ func NewYAMLProviderWithExpand(mapping func(string) (string, bool), files ...str

// NewYAMLProviderFromReader creates a configuration provider from a list of io.Readers.
// As above, all the objects are going to be merged and arrays/values overridden in the order of the files.
func newYAMLProviderFromReader(readers ...io.Reader) (Provider, error) {
func NewYAMLProviderFromReader(readers ...io.Reader) (Provider, error) {
p, err := newYAMLProviderCore(readers...)
if err != nil {
return nil, err
Expand All @@ -208,7 +208,7 @@ func newYAMLProviderFromReader(readers ...io.Reader) (Provider, error) {
// NewYAMLProviderFromReaderWithExpand creates a configuration provider from
// a list of `io.Readers and uses the mapping function to expand values
// in the underlying provider.
func newYAMLProviderFromReaderWithExpand(
func NewYAMLProviderFromReaderWithExpand(
mapping func(string) (string, bool),
readers ...io.Reader) (Provider, error) {

Expand All @@ -221,7 +221,7 @@ func newYAMLProviderFromReaderWithExpand(
&expandTransformer{expand: expandFunc})
}

return newYAMLProviderFromReader(ereaders...)
return NewYAMLProviderFromReader(ereaders...)
}

// NewYAMLProviderFromBytes creates a config provider from a byte-backed YAML
Expand All @@ -233,7 +233,7 @@ func NewYAMLProviderFromBytes(yamls ...[]byte) (Provider, error) {
readers[i] = bytes.NewReader(yml)
}

return newYAMLProviderFromReader(readers...)
return NewYAMLProviderFromReader(readers...)
}

func filesToReaders(files ...string) ([]io.ReadCloser, error) {
Expand Down
24 changes: 12 additions & 12 deletions yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ module:
fake:
number: ${FAKE_NUMBER:321}`)

p, err := newYAMLProviderFromReaderWithExpand(f, cfg)
p, err := NewYAMLProviderFromReaderWithExpand(f, cfg)
require.NoError(t, err, "Can't create a YAML provider")
require.Equal(t, "321", p.Get("module.fake.number").String())

Expand All @@ -95,7 +95,7 @@ name: some name here
email: ${EMAIL_ADDRESS}`)

f := func(string) (string, bool) { return "", false }
_, err := newYAMLProviderFromReaderWithExpand(f, cfg)
_, err := NewYAMLProviderFromReaderWithExpand(f, cfg)
require.Error(t, err)
assert.Contains(t, err.Error(), `default is empty for "EMAIL_ADDRESS"`)
}
Expand All @@ -108,7 +108,7 @@ name: some name here
telephone: ${SUPPORT_TEL:}`)

f := func(string) (string, bool) { return "", false }
_, err := newYAMLProviderFromReaderWithExpand(f, cfg)
_, err := NewYAMLProviderFromReaderWithExpand(f, cfg)

require.Error(t, err)
assert.Contains(t, err.Error(), `default is empty for "SUPPORT_TEL" (use "" for empty string)`)
Expand All @@ -122,7 +122,7 @@ func TestYAMLEnvInterpolationWithColon(t *testing.T) {
return "", false
}

p, err := newYAMLProviderFromReaderWithExpand(f, cfg)
p, err := NewYAMLProviderFromReaderWithExpand(f, cfg)
require.NoError(t, err, "Can't create a YAML provider")

require.Equal(t, "this:is:my:value", p.Get("fullValue").String())
Expand All @@ -136,7 +136,7 @@ name: ${APP_NAME:my shiny app}
fullTel: 1-800-LOLZ${TELEPHONE_EXTENSION:""}`)

f := func(string) (string, bool) { return "", false }
p, err := newYAMLProviderFromReaderWithExpand(f, cfg)
p, err := NewYAMLProviderFromReaderWithExpand(f, cfg)
require.NoError(t, err, "Can't create a YAML provider")

require.Equal(t, "my shiny app", p.Get("name").String())
Expand Down Expand Up @@ -221,7 +221,7 @@ func TestNewYAMLProviderFromReader(t *testing.T) {
t.Parallel()

buff := bytes.NewBuffer([]byte(_yamlConfig1))
provider, err := newYAMLProviderFromReader(buff)
provider, err := NewYAMLProviderFromReader(buff)
require.NoError(t, err, "Can't create a YAML provider")

cs := &configStruct{}
Expand Down Expand Up @@ -1199,7 +1199,7 @@ func TestYAMLEnvInterpolationValueMissing(t *testing.T) {
cfg := strings.NewReader(`name:`)

f := func(string) (string, bool) { return "", false }
p, err := newYAMLProviderFromReaderWithExpand(f, cfg)
p, err := NewYAMLProviderFromReaderWithExpand(f, cfg)
require.NoError(t, err, "Can't create a YAML provider")
assert.Equal(t, nil, p.Get("name").Value())
}
Expand All @@ -1214,7 +1214,7 @@ func TestYAMLEnvInterpolationValueConversion(t *testing.T) {
return "3", true
}

p, err := newYAMLProviderFromReaderWithExpand(f, cfg)
p, err := NewYAMLProviderFromReaderWithExpand(f, cfg)
require.NoError(t, err, "Can't create a YAML provider")

assert.Equal(t, "3", p.Get("number").String())
Expand Down Expand Up @@ -1782,7 +1782,7 @@ func TestMergeErrorsFromReaders(t *testing.T) {
dev := strings.NewReader(`a:
b: c`)

_, err := newYAMLProviderFromReader(base, dev)
_, err := NewYAMLProviderFromReader(base, dev)
require.Error(t, err)
assert.Contains(t, err.Error(), "can't merge map")
})
Expand All @@ -1795,7 +1795,7 @@ func TestMergeErrorsFromReaders(t *testing.T) {
dev := strings.NewReader(`a:
b: c`)

_, err := newYAMLProviderFromReaderWithExpand(expand, base, dev)
_, err := NewYAMLProviderFromReaderWithExpand(expand, base, dev)
require.Error(t, err)
assert.Contains(t, err.Error(), "can't merge map")
})
Expand Down Expand Up @@ -1832,7 +1832,7 @@ func TestMergeErrorsFromFiles(t *testing.T) {
d, err := ioutil.ReadFile(dev.Name())
require.NoError(t, err, "Can't read dev file")

_, err = newYAMLProviderFromReader(
_, err = NewYAMLProviderFromReader(
bytes.NewBuffer(b),
bytes.NewBuffer(d))

Expand All @@ -1857,7 +1857,7 @@ func TestMergeErrorsFromFiles(t *testing.T) {

expand := func(string) (string, bool) { return "", false }

_, err = newYAMLProviderFromReaderWithExpand(
_, err = NewYAMLProviderFromReaderWithExpand(
expand,
bytes.NewBuffer(b),
bytes.NewBuffer(d))
Expand Down

0 comments on commit 45fa47e

Please sign in to comment.