mirror of
https://github.com/hanzoai/telemetry.git
synced 2026-10-30 20:01:49 +00:00
#### Description Testifylint doesn't support it yet. This replaces `Contains(t, err.Error()` by `ErrorContains(t, err` and `Equal(t, err.Error()` by `EqualError(t, err` As they both check for nil error it becomes useless to check it yourself without having defined a custom message <!-- Signed-off-by: Matthieu MOREL <[email protected]> --> Signed-off-by: Matthieu MOREL <[email protected]>
38 lines
1.3 KiB
Go
38 lines
1.3 KiB
Go
// Copyright The OpenTelemetry Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package otelcol
|
|
|
|
import (
|
|
"context"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"go.opentelemetry.io/collector/confmap"
|
|
"go.opentelemetry.io/collector/featuregate"
|
|
)
|
|
|
|
func TestValidateSubCommandNoConfig(t *testing.T) {
|
|
cmd := newValidateSubCommand(CollectorSettings{Factories: nopFactories}, flags(featuregate.GlobalRegistry()))
|
|
err := cmd.Execute()
|
|
require.ErrorContains(t, err, "at least one config flag must be provided")
|
|
}
|
|
|
|
func TestValidateSubCommandInvalidComponents(t *testing.T) {
|
|
filePath := filepath.Join("testdata", "otelcol-invalid-components.yaml")
|
|
fileProvider := newFakeProvider("file", func(_ context.Context, _ string, _ confmap.WatcherFunc) (*confmap.Retrieved, error) {
|
|
return confmap.NewRetrieved(newConfFromFile(t, filePath))
|
|
})
|
|
cmd := newValidateSubCommand(CollectorSettings{Factories: nopFactories, ConfigProviderSettings: ConfigProviderSettings{
|
|
ResolverSettings: confmap.ResolverSettings{
|
|
URIs: []string{filePath},
|
|
ProviderFactories: []confmap.ProviderFactory{fileProvider},
|
|
DefaultScheme: "file",
|
|
},
|
|
}}, flags(featuregate.GlobalRegistry()))
|
|
err := cmd.Execute()
|
|
require.ErrorContains(t, err, "unknown type: \"nosuchprocessor\"")
|
|
}
|