-
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.
Merge values for provider group in the constructor (#48)
ProviderGroup can and should merge values on construction, instead of on value retrieval. To do that we need need apply expand to all nested YAML nodes, instead of only top level ones.
- Loading branch information
Alex
authored
Jul 31, 2017
1 parent
7d6a5c6
commit e1caf0b
Showing
9 changed files
with
75 additions
and
174 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,9 @@ func TestProviderGroup(t *testing.T) { | |
p, err := NewYAMLProviderFromBytes([]byte(`id: test`)) | ||
require.NoError(t, err, "Can't create a YAML provider") | ||
|
||
pg := NewProviderGroup("test-group", p) | ||
pg, err := NewProviderGroup("test-group", p) | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, "test-group", pg.Name()) | ||
assert.Equal(t, "test", pg.Get("id").String()) | ||
} | ||
|
@@ -44,7 +46,9 @@ func TestProviderGroupScope(t *testing.T) { | |
p, err := NewStaticProvider(map[string]interface{}{"hello": map[string]int{"world": 42}}) | ||
require.NoError(t, err, "Can't create a static provider") | ||
|
||
pg := NewProviderGroup("test-group", p) | ||
pg, err := NewProviderGroup("test-group", p) | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, 42, pg.Get("hello").Get("world").Value()) | ||
} | ||
|
||
|
@@ -87,7 +91,9 @@ logging: | |
f, err := NewYAMLProviderFromBytes(fst) | ||
require.NoError(t, err, "Can't create a YAML provider") | ||
|
||
pg := NewProviderGroup("group", s, f) | ||
pg, err := NewProviderGroup("group", s, f) | ||
require.NoError(t, err) | ||
|
||
assert.True(t, pg.Get("logging").Get("enabled").Value().(bool)) | ||
} | ||
|
||
|
@@ -100,23 +106,10 @@ func TestProviderGroup_GetChecksAllProviders(t *testing.T) { | |
s, err := NewStaticProvider(map[string]string{"owner": "[email protected]", "name": "fx"}) | ||
require.NoError(t, err, "Can't create the second provider") | ||
|
||
pg := NewProviderGroup("test-group", f, s) | ||
require.NotNil(t, pg) | ||
pg, err := NewProviderGroup("test-group", f, s) | ||
require.NoError(t, err) | ||
|
||
var svc map[string]string | ||
require.NoError(t, pg.Get(Root).Populate(&svc)) | ||
assert.Equal(t, map[string]string{"name": "fx", "owner": "[email protected]", "desc": "test"}, svc) | ||
} | ||
|
||
func TestProviderGroupMergeFail(t *testing.T) { | ||
t.Parallel() | ||
|
||
m, err := NewStaticProvider(map[string]interface{}{"a": map[string]string{"b": "c"}}) | ||
require.NoError(t, err) | ||
s, err := NewStaticProvider(map[string]interface{}{"a": []string{"b"}}) | ||
require.NoError(t, err) | ||
|
||
g := NewProviderGroup("group", s, m) | ||
v := g.Get("a") | ||
assert.False(t, v.HasValue()) | ||
} |
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