uber-go / config

Configuration for Go applications

Home Page:https://godoc.org/go.uber.org/config

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Report merge error during provider group construction

opened this issue · comments

Provider group should report merge errors on construction, not when trying to retrieve a value via Get method, because we need to define invalid Values then and show how users can work with them.

The difficulty here is to flatten maps, e.g. if we have base.yaml:

series:
  episodes:
    s01e01: Pilot

and test.yaml:

series.episodes:
- Pilot

The provider should fail to merge these files together because base.yaml has series.episodes key defined as a map and test.yaml defines it as a slice. This test should pass:

func TestProviderGroup_ConstructorMergeError(t *testing.T) {
	t.Parallel()

	f, err := NewStaticProvider(map[string]interface{}{
		"series": map[string]interface{}{
			"episodes": map[string]string{"s01e01": "Pilot"},
		}})

	require.NoError(t, err, "Can't create the first provider")

	s, err := NewStaticProvider(map[string]interface{}{
		"series.episodes": []interface{}{"Pilot"},
	})
	require.NoError(t, err, "Can't create the second provider")

	_, err := NewProviderGroup("test-group", f, s)
	assert.Error(t, err)
}

Fixed in v1.2.0.