Files
telemetry/otelcol/command_validate_test.go
Matthieu MORELandGitHub bb5e08536d [chore]: use ErrorContains and EqualError (#11295)
#### 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]>
2024-09-28 08:06:09 -07:00

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\"")
}