Skip to content

Commit

Permalink
Deprecate confmap.Received.AsMap in favor of confmap.Received.AsConf
Browse files Browse the repository at this point in the history
Followup after #5237 when I forgot to change the name of this func accordingly to the new Conf name.

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu committed Jun 3, 2022
1 parent e0cf05e commit 475aefe
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- Package `filemapprovider` -> `fileprovider`
- Package `overwritepropertiesmapconverter` -> `overwritepropertiesconverter`
- Deprecate `component.ExtensionDefaultConfigFunc` in favor of `component.ExtensionCreateDefaultConfigFunc` (#5451)
- Deprecate `confmap.Received.AsMap` in favor of `confmap.Received.AsConf` (#5465)

### 💡 Enhancements 💡

Expand Down
2 changes: 1 addition & 1 deletion confmap/confmaptest/configtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ func LoadConf(fileName string) (*confmap.Conf, error) {
if err != nil {
return nil, err
}
return ret.AsMap()
return ret.AsConf()
}
9 changes: 7 additions & 2 deletions confmap/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,13 @@ func NewRetrieved(rawConf map[string]interface{}, opts ...RetrievedOption) (Retr
return Retrieved{conf: NewFromStringMap(rawConf), closeFunc: set.closeFunc}, nil
}

// AsMap returns the retrieved configuration parsed as a Map.
func (r Retrieved) AsMap() (*Conf, error) {
// Deprecated: [v0.53.0] Use AsConf.
func (r *Retrieved) AsMap() (*Conf, error) {
return r.AsConf()
}

// AsConf returns the retrieved configuration parsed as a Conf.
func (r Retrieved) AsConf() (*Conf, error) {
return r.conf, nil
}

Expand Down
2 changes: 1 addition & 1 deletion confmap/provider/envprovider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestEnv(t *testing.T) {
env := New()
ret, err := env.Retrieve(context.Background(), envSchemePrefix+envName, nil)
require.NoError(t, err)
retMap, err := ret.AsMap()
retMap, err := ret.AsConf()
assert.NoError(t, err)
expectedMap := confmap.NewFromStringMap(map[string]interface{}{
"processors::batch": nil,
Expand Down
4 changes: 2 additions & 2 deletions confmap/provider/fileprovider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestRelativePath(t *testing.T) {
fp := New()
ret, err := fp.Retrieve(context.Background(), fileSchemePrefix+filepath.Join("testdata", "default-config.yaml"), nil)
require.NoError(t, err)
retMap, err := ret.AsMap()
retMap, err := ret.AsConf()
assert.NoError(t, err)
expectedMap := confmap.NewFromStringMap(map[string]interface{}{
"processors::batch": nil,
Expand All @@ -78,7 +78,7 @@ func TestAbsolutePath(t *testing.T) {
fp := New()
ret, err := fp.Retrieve(context.Background(), fileSchemePrefix+absolutePath(t, filepath.Join("testdata", "default-config.yaml")), nil)
require.NoError(t, err)
retMap, err := ret.AsMap()
retMap, err := ret.AsConf()
assert.NoError(t, err)
expectedMap := confmap.NewFromStringMap(map[string]interface{}{
"processors::batch": nil,
Expand Down
4 changes: 2 additions & 2 deletions confmap/provider/internal/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
func TestNewRetrievedFromYAML(t *testing.T) {
ret, err := NewRetrievedFromYAML([]byte{})
require.NoError(t, err)
retMap, err := ret.AsMap()
retMap, err := ret.AsConf()
require.NoError(t, err)
assert.Equal(t, confmap.New(), retMap)
assert.NoError(t, ret.Close(context.Background()))
Expand All @@ -38,7 +38,7 @@ func TestNewRetrievedFromYAMLWithOptions(t *testing.T) {
want := errors.New("my error")
ret, err := NewRetrievedFromYAML([]byte{}, confmap.WithRetrievedClose(func(context.Context) error { return want }))
require.NoError(t, err)
retMap, err := ret.AsMap()
retMap, err := ret.AsConf()
require.NoError(t, err)
assert.Equal(t, confmap.New(), retMap)
assert.Equal(t, want, ret.Close(context.Background()))
Expand Down
10 changes: 5 additions & 5 deletions confmap/provider/yamlprovider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestOneValue(t *testing.T) {
sp := New()
ret, err := sp.Retrieve(context.Background(), "yaml:processors::batch::timeout: 2s", nil)
assert.NoError(t, err)
retMap, err := ret.AsMap()
retMap, err := ret.AsConf()
assert.NoError(t, err)
assert.Equal(t, map[string]interface{}{
"processors": map[string]interface{}{
Expand All @@ -55,7 +55,7 @@ func TestNamedComponent(t *testing.T) {
sp := New()
ret, err := sp.Retrieve(context.Background(), "yaml:processors::batch/foo::timeout: 3s", nil)
assert.NoError(t, err)
retMap, err := ret.AsMap()
retMap, err := ret.AsConf()
assert.NoError(t, err)
assert.Equal(t, map[string]interface{}{
"processors": map[string]interface{}{
Expand All @@ -71,7 +71,7 @@ func TestMapEntry(t *testing.T) {
sp := New()
ret, err := sp.Retrieve(context.Background(), "yaml:processors: {batch/foo::timeout: 3s, batch::timeout: 2s}", nil)
assert.NoError(t, err)
retMap, err := ret.AsMap()
retMap, err := ret.AsConf()
assert.NoError(t, err)
assert.Equal(t, map[string]interface{}{
"processors": map[string]interface{}{
Expand All @@ -90,7 +90,7 @@ func TestNewLine(t *testing.T) {
sp := New()
ret, err := sp.Retrieve(context.Background(), "yaml:processors::batch/foo::timeout: 3s\nprocessors::batch::timeout: 2s", nil)
assert.NoError(t, err)
retMap, err := ret.AsMap()
retMap, err := ret.AsConf()
assert.NoError(t, err)
assert.Equal(t, map[string]interface{}{
"processors": map[string]interface{}{
Expand All @@ -109,7 +109,7 @@ func TestDotSeparator(t *testing.T) {
sp := New()
ret, err := sp.Retrieve(context.Background(), "yaml:processors.batch.timeout: 4s", nil)
assert.NoError(t, err)
retMap, err := ret.AsMap()
retMap, err := ret.AsConf()
assert.NoError(t, err)
assert.Equal(t, map[string]interface{}{"processors.batch.timeout": "4s"}, retMap.ToStringMap())
assert.NoError(t, sp.Shutdown(context.Background()))
Expand Down
4 changes: 2 additions & 2 deletions confmap/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
func TestNewRetrieved(t *testing.T) {
ret, err := NewRetrieved(nil)
require.NoError(t, err)
retMap, err := ret.AsMap()
retMap, err := ret.AsConf()
require.NoError(t, err)
assert.Equal(t, New(), retMap)
assert.NoError(t, ret.Close(context.Background()))
Expand All @@ -36,7 +36,7 @@ func TestNewRetrievedWithOptions(t *testing.T) {
want := errors.New("my error")
ret, err := NewRetrieved(nil, WithRetrievedClose(func(context.Context) error { return want }))
require.NoError(t, err)
retMap, err := ret.AsMap()
retMap, err := ret.AsConf()
require.NoError(t, err)
assert.Equal(t, New(), retMap)
assert.Equal(t, want, ret.Close(context.Background()))
Expand Down
2 changes: 1 addition & 1 deletion confmap/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (mr *Resolver) Resolve(ctx context.Context) (*Conf, error) {
if err != nil {
return nil, err
}
retCfgMap, err := ret.AsMap()
retCfgMap, err := ret.AsConf()
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 475aefe

Please sign in to comment.