Skip to content

Commit

Permalink
[chore] Update tests to include scraper settings (#24653)
Browse files Browse the repository at this point in the history
**Description:** 

With the most recent changes in
open-telemetry/opentelemetry-collector#7951
caused a bunch of tests to fail on upgrade.

This just adds in the scraper settings where needed.
  • Loading branch information
MovieStoreGuy authored Jul 28, 2023
1 parent b44a1ba commit 158ee0e
Show file tree
Hide file tree
Showing 17 changed files with 194 additions and 78 deletions.
38 changes: 25 additions & 13 deletions receiver/aerospikereceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/confmap/confmaptest"
"go.opentelemetry.io/collector/receiver/scraperhelper"

"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/aerospikereceiver/internal/metadata"
)
Expand All @@ -25,67 +26,76 @@ func TestValidate(t *testing.T) {
{
name: "blank endpoint",
config: &Config{
Endpoint: "",
Endpoint: "",
ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
},
expected: errEmptyEndpoint,
},
{
name: "missing port",
config: &Config{
Endpoint: "localhost",
Endpoint: "localhost",
ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
},
expected: errBadEndpoint,
},
{
name: "bad endpoint",
config: &Config{
Endpoint: "x;;ef;s;d:::ss:23423423423423423",
Endpoint: "x;;ef;s;d:::ss:23423423423423423",
ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
},
expected: errBadEndpoint,
},
{
name: "missing host",
config: &Config{
Endpoint: ":3001",
Endpoint: ":3001",
ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
},
expected: errBadEndpoint,
},
{
name: "negative port",
config: &Config{
Endpoint: "localhost:-2",
Endpoint: "localhost:-2",
ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
},
expected: errBadPort,
},
{
name: "bad port",
config: &Config{
Endpoint: "localhost:9999999999999999999",
Endpoint: "localhost:9999999999999999999",
ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
},
expected: errBadPort,
},
{
name: "negative timeout",
config: &Config{
Endpoint: "localhost:3000",
Timeout: -1 * time.Second,
Endpoint: "localhost:3000",
Timeout: -1 * time.Second,
ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
},
expected: errNegativeTimeout,
},
{
name: "password but no username",
config: &Config{
Endpoint: "localhost:3000",
Username: "",
Password: "secret",
Endpoint: "localhost:3000",
Username: "",
Password: "secret",
ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
},
expected: errEmptyUsername,
},
{
name: "username but no password",
config: &Config{
Endpoint: "localhost:3000",
Username: "ro_user",
Endpoint: "localhost:3000",
Username: "ro_user",
ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
},
expected: errEmptyPassword,
},
Expand All @@ -100,6 +110,7 @@ func TestValidate(t *testing.T) {
CAFile: "BADCAFILE",
},
},
ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
},
expected: errFailedTLSLoad,
},
Expand All @@ -112,6 +123,7 @@ func TestValidate(t *testing.T) {
Insecure: false,
TLSSetting: configtls.TLSSetting{},
},
ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
},
expected: errEmptyEndpointTLSName,
},
Expand Down
10 changes: 8 additions & 2 deletions receiver/apachesparkreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (

"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/receiver/scraperhelper"

"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/apachesparkreceiver/internal/metadata"
)

func TestValidate(t *testing.T) {
Expand All @@ -17,8 +20,10 @@ func TestValidate(t *testing.T) {
expectedErr error
}{
{
desc: "default config",
cfg: &Config{},
desc: "default config",
cfg: &Config{
ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
},
expectedErr: nil,
},
{
Expand All @@ -27,6 +32,7 @@ func TestValidate(t *testing.T) {
HTTPClientSettings: confighttp.HTTPClientSettings{
Endpoint: "invalid://endpoint 12efg",
},
ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
},
expectedErr: errInvalidEndpoint,
},
Expand Down
7 changes: 6 additions & 1 deletion receiver/bigipreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/confmap/confmaptest"
"go.opentelemetry.io/collector/receiver/scraperhelper"
"go.uber.org/multierr"

"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/bigipreceiver/internal/metadata"
Expand All @@ -33,6 +34,7 @@ func TestValidate(t *testing.T) {
HTTPClientSettings: confighttp.HTTPClientSettings{
Endpoint: "invalid://endpoint: 12efg",
},
ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
},
expectedErr: multierr.Combine(
errMissingUsername,
Expand All @@ -46,7 +48,7 @@ func TestValidate(t *testing.T) {
Username: "otelu",
HTTPClientSettings: confighttp.HTTPClientSettings{
Endpoint: "invalid://endpoint: 12efg",
},
}, ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
},
expectedErr: multierr.Combine(
errMissingPassword,
Expand All @@ -60,6 +62,7 @@ func TestValidate(t *testing.T) {
HTTPClientSettings: confighttp.HTTPClientSettings{
Endpoint: "invalid://endpoint: 12efg",
},
ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
},
expectedErr: multierr.Combine(
errMissingUsername,
Expand All @@ -74,6 +77,7 @@ func TestValidate(t *testing.T) {
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`),
Expand All @@ -87,6 +91,7 @@ func TestValidate(t *testing.T) {
HTTPClientSettings: confighttp.HTTPClientSettings{
Endpoint: defaultEndpoint,
},
ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
},
expectedErr: nil,
},
Expand Down
10 changes: 8 additions & 2 deletions receiver/couchdbreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/confmap/confmaptest"
"go.opentelemetry.io/collector/receiver/scraperhelper"
"go.uber.org/multierr"

"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/couchdbreceiver/internal/metadata"
Expand All @@ -30,6 +31,7 @@ func TestValidate(t *testing.T) {
HTTPClientSettings: confighttp.HTTPClientSettings{
Endpoint: "http://localhost :5984",
},
ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
},
expectedErr: multierr.Combine(
errMissingUsername,
Expand All @@ -43,7 +45,8 @@ func TestValidate(t *testing.T) {
HTTPClientSettings: confighttp.HTTPClientSettings{
Endpoint: "http://localhost :5984",
},
Username: "otelu",
ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
Username: "otelu",
},
expectedErr: multierr.Combine(
errMissingPassword,
Expand All @@ -56,7 +59,8 @@ func TestValidate(t *testing.T) {
HTTPClientSettings: confighttp.HTTPClientSettings{
Endpoint: "http://localhost :5984",
},
Password: "otelp",
ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
Password: "otelp",
},
expectedErr: multierr.Combine(
errMissingUsername,
Expand All @@ -71,6 +75,7 @@ func TestValidate(t *testing.T) {
HTTPClientSettings: confighttp.HTTPClientSettings{
Endpoint: "http://localhost :5984",
},
ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
},
expectedErr: fmt.Errorf(errInvalidEndpoint.Error(), "parse \"http://localhost :5984\": invalid character \" \" in host name"),
},
Expand All @@ -82,6 +87,7 @@ func TestValidate(t *testing.T) {
HTTPClientSettings: confighttp.HTTPClientSettings{
Endpoint: "http://localhost:5984",
},
ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
},
expectedErr: nil,
},
Expand Down
5 changes: 1 addition & 4 deletions receiver/dockerstatsreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,9 @@ func TestLoadConfig(t *testing.T) {
}

func TestValidateErrors(t *testing.T) {
cfg := &Config{}
cfg := &Config{ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type)}
assert.Equal(t, "endpoint must be specified", component.ValidateConfig(cfg).Error())

cfg = &Config{Endpoint: "someEndpoint"}
assert.Equal(t, "collection_interval must be a positive duration", component.ValidateConfig(cfg).Error())

cfg = &Config{ScraperControllerSettings: scraperhelper.ScraperControllerSettings{CollectionInterval: 1 * time.Second}, Endpoint: "someEndpoint", DockerAPIVersion: 1.21}
assert.Equal(t, "api_version must be at least 1.22", component.ValidateConfig(cfg).Error())
}
17 changes: 13 additions & 4 deletions receiver/filestatsreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/receiver/scraperhelper"

"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/filestatsreceiver/internal/metadata"
)

func Test_Config_Validate(t *testing.T) {
Expand All @@ -17,13 +20,19 @@ func Test_Config_Validate(t *testing.T) {
wantErr error
}{
{
name: "valid",
cfg: &Config{Include: "/var/log/*.log"},
name: "valid",
cfg: &Config{
Include: "/var/log/*.log",
ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
},
wantErr: nil,
},
{
name: "missing include pattern",
cfg: &Config{Include: ""},
name: "missing include pattern",
cfg: &Config{
Include: "",
ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
},
wantErr: errors.New("include must not be empty"),
},
}
Expand Down
3 changes: 3 additions & 0 deletions receiver/flinkmetricsreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"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"
)
Expand All @@ -30,6 +31,7 @@ func TestValidate(t *testing.T) {
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`)),
},
Expand All @@ -39,6 +41,7 @@ func TestValidate(t *testing.T) {
HTTPClientSettings: confighttp.HTTPClientSettings{
Endpoint: defaultEndpoint,
},
ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
},
expectedErr: nil,
},
Expand Down
8 changes: 8 additions & 0 deletions receiver/httpcheckreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import (

"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/httpcheckreceiver/internal/metadata"
)

func TestValidate(t *testing.T) {
Expand All @@ -26,6 +29,7 @@ func TestValidate(t *testing.T) {
HTTPClientSettings: confighttp.HTTPClientSettings{},
},
},
ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
},
expectedErr: multierr.Combine(
errMissingEndpoint,
Expand All @@ -41,6 +45,7 @@ func TestValidate(t *testing.T) {
},
},
},
ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
},
expectedErr: multierr.Combine(
fmt.Errorf("%w: %s", errInvalidEndpoint, `parse "invalid://endpoint: 12efg": invalid port ": 12efg" after host`),
Expand All @@ -61,6 +66,7 @@ func TestValidate(t *testing.T) {
},
},
},
ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
},
expectedErr: multierr.Combine(
fmt.Errorf("%w: %s", errInvalidEndpoint, `parse "invalid://endpoint: 12efg": invalid port ": 12efg" after host`),
Expand All @@ -76,6 +82,7 @@ func TestValidate(t *testing.T) {
},
},
},
ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
},
expectedErr: multierr.Combine(
fmt.Errorf("%w: %s", errInvalidEndpoint, `parse "www.opentelemetry.io/docs": invalid URI for request`),
Expand All @@ -96,6 +103,7 @@ func TestValidate(t *testing.T) {
},
},
},
ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
},
expectedErr: nil,
},
Expand Down
Loading

0 comments on commit 158ee0e

Please sign in to comment.