12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- // Copyright The OpenTelemetry Authors
- // SPDX-License-Identifier: Apache-2.0
- package flinkmetricsreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/flinkmetricsreceiver"
- import (
- "errors"
- "fmt"
- "path/filepath"
- "testing"
- "time"
- "github.com/stretchr/testify/require"
- "go.opentelemetry.io/collector/component"
- "go.opentelemetry.io/collector/config/confighttp"
- "go.opentelemetry.io/collector/confmap/confmaptest"
- "go.opentelemetry.io/collector/receiver/scraperhelper"
- "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/flinkmetricsreceiver/internal/metadata"
- )
- func TestValidate(t *testing.T) {
- testCases := []struct {
- desc string
- cfg *Config
- expectedErr error
- }{
- {
- desc: "invalid endpoint",
- cfg: &Config{
- HTTPClientSettings: confighttp.HTTPClientSettings{
- Endpoint: "invalid://endpoint: 12efg",
- },
- ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
- },
- expectedErr: fmt.Errorf("\"endpoint\" must be in the form of <scheme>://<hostname>:<port>: %w", errors.New(`parse "invalid://endpoint: 12efg": invalid port ": 12efg" after host`)),
- },
- {
- desc: "valid config",
- cfg: &Config{
- HTTPClientSettings: confighttp.HTTPClientSettings{
- Endpoint: defaultEndpoint,
- },
- ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
- },
- expectedErr: nil,
- },
- }
- for _, tc := range testCases {
- t.Run(tc.desc, func(t *testing.T) {
- actualErr := tc.cfg.Validate()
- if tc.expectedErr != nil {
- require.EqualError(t, actualErr, tc.expectedErr.Error())
- } else {
- require.NoError(t, actualErr)
- }
- })
- }
- }
- func TestLoadConfig(t *testing.T) {
- cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
- require.NoError(t, err)
- factory := NewFactory()
- cfg := factory.CreateDefaultConfig()
- sub, err := cm.Sub(component.NewIDWithName(metadata.Type, "").String())
- require.NoError(t, err)
- require.NoError(t, component.UnmarshalConfig(sub, cfg))
- expected := factory.CreateDefaultConfig().(*Config)
- expected.Endpoint = "http://localhost:8081"
- expected.CollectionInterval = 10 * time.Second
- require.Equal(t, expected, cfg)
- }
|