mirror of
https://github.com/hanzoai/telemetry.git
synced 2026-10-30 20:01:49 +00:00
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Switch `scraper/scraperhelper` `ControllerConfig` to schema-based generated configuration. This adds metadata-driven config generation for the scraper controller settings, publishes the reusable `controller_config` schema from `pkg/scraperhelper`, and updates the mdatagen sample scraper to embed that exported config via schema reference. <!-- Issue number if applicable --> #### Link to tracking issue Fixes #15258 <!--Describe what testing was performed and which tests were added.--> #### Testing Added usage example to `samplescraper` test component. --------- Co-authored-by: Dmitry Anoshin <[email protected]>
53 lines
1.0 KiB
Go
53 lines
1.0 KiB
Go
// Copyright The OpenTelemetry Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package controller // import "go.opentelemetry.io/collector/scraper/scraperhelper/internal/controller"
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestControllerConfigValidate(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
name string
|
|
cfg ControllerConfig
|
|
wantErr string
|
|
}{
|
|
{
|
|
name: "default configuration",
|
|
cfg: NewDefaultControllerConfig(),
|
|
},
|
|
{
|
|
name: "zero value configuration",
|
|
cfg: ControllerConfig{},
|
|
wantErr: `"collection_interval": requires positive value`,
|
|
},
|
|
{
|
|
name: "invalid timeout",
|
|
cfg: ControllerConfig{
|
|
CollectionInterval: time.Minute,
|
|
Timeout: -time.Minute,
|
|
},
|
|
wantErr: `"timeout": requires positive value`,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
err := tt.cfg.Validate()
|
|
if tt.wantErr == "" {
|
|
require.NoError(t, err)
|
|
return
|
|
}
|
|
require.EqualError(t, err, tt.wantErr)
|
|
})
|
|
}
|
|
}
|