Skip to content

Commit

Permalink
Add tests for file config map provider (#4575)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu authored Dec 17, 2021
1 parent f80527e commit 1941cc1
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions config/configmapprovider/file_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package configmapprovider

import (
"context"
"path"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.opentelemetry.io/collector/config"
)

func TestFile_EmptyName(t *testing.T) {
exp := NewFile("")
_, err := exp.Retrieve(context.Background(), nil)
require.Error(t, err)
}

func TestFile_NonExistent(t *testing.T) {
env := NewFile(path.Join("testdata", "non-existent.yaml"))
_, err := env.Retrieve(context.Background(), nil)
assert.Error(t, err)
}

func TestFile_InvalidYaml(t *testing.T) {
env := NewFile(path.Join("testdata", "invalid-yaml.yaml"))
_, err := env.Retrieve(context.Background(), nil)
assert.Error(t, err)
}

func TestFile(t *testing.T) {
env := NewFile(path.Join("testdata", "default-config.yaml"))
ret, err := env.Retrieve(context.Background(), nil)
assert.NoError(t, err)
cfg, err := ret.Get(context.Background())
assert.NoError(t, err)
expectedMap := config.NewMapFromStringMap(map[string]interface{}{
"processors::batch": nil,
"exporters::otlp::endpoint": "localhost:4317",
})
assert.Equal(t, expectedMap, cfg)
assert.NoError(t, ret.Close(context.Background()))
assert.NoError(t, env.Shutdown(context.Background()))
}

0 comments on commit 1941cc1

Please sign in to comment.