123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- // Copyright The OpenTelemetry Authors
- // SPDX-License-Identifier: Apache-2.0
- package riakreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/riakreceiver"
- import (
- "fmt"
- "testing"
- "github.com/stretchr/testify/require"
- "go.opentelemetry.io/collector/config/confighttp"
- "go.opentelemetry.io/collector/receiver/scraperhelper"
- "go.uber.org/multierr"
- "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/riakreceiver/internal/metadata"
- )
- func TestValidate(t *testing.T) {
- testCases := []struct {
- desc string
- cfg *Config
- expectedErr error
- }{
- {
- desc: "missing username, password, and invalid endpoint",
- cfg: &Config{
- HTTPClientSettings: confighttp.HTTPClientSettings{
- Endpoint: "invalid://endpoint: 12efg",
- },
- ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
- },
- expectedErr: multierr.Combine(
- errMissingUsername,
- errMissingPassword,
- fmt.Errorf("%w: %s", errInvalidEndpoint, `parse "invalid://endpoint: 12efg": invalid port ": 12efg" after host`),
- ),
- },
- {
- desc: "missing password and invalid endpoint",
- cfg: &Config{
- Username: "otelu",
- HTTPClientSettings: confighttp.HTTPClientSettings{
- Endpoint: "invalid://endpoint: 12efg",
- },
- ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
- },
- expectedErr: multierr.Combine(
- errMissingPassword,
- fmt.Errorf("%w: %s", errInvalidEndpoint, `parse "invalid://endpoint: 12efg": invalid port ": 12efg" after host`),
- ),
- },
- {
- desc: "missing username and invalid endpoint",
- cfg: &Config{
- Password: "otelp",
- HTTPClientSettings: confighttp.HTTPClientSettings{
- Endpoint: "invalid://endpoint: 12efg",
- },
- ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
- },
- expectedErr: multierr.Combine(
- errMissingUsername,
- fmt.Errorf("%w: %s", errInvalidEndpoint, `parse "invalid://endpoint: 12efg": invalid port ": 12efg" after host`),
- ),
- },
- {
- desc: "invalid endpoint",
- cfg: &Config{
- Username: "otelu",
- Password: "otelp",
- HTTPClientSettings: confighttp.HTTPClientSettings{
- Endpoint: "invalid://endpoint: 12efg",
- },
- ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
- },
- expectedErr: multierr.Combine(
- fmt.Errorf("%w: %s", errInvalidEndpoint, `parse "invalid://endpoint: 12efg": invalid port ": 12efg" after host`),
- ),
- },
- {
- desc: "valid config",
- cfg: &Config{
- Username: "otelu",
- Password: "otelp",
- 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)
- }
- })
- }
- }
|