Debian Codegraph @

otelcol/command_validate_test.go

raw
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package otelcol
5
6 import (
7 "context"
8 "path/filepath"
9 "testing"
10
11 "github.com/stretchr/testify/require"
12
13 "go.opentelemetry.io/collector/confmap"
14 "go.opentelemetry.io/collector/featuregate"
15 )
16
17 func TestValidateSubCommandNoConfig(t *testing.T) {
18 cmd := newValidateSubCommand(CollectorSettings{Factories: nopFactories}, flags(featuregate.GlobalRegistry()))
19 err := cmd.Execute()
20 require.ErrorContains(t, err, "at least one config flag must be provided")
21 }
22
23 func TestValidateSubCommandInvalidComponents(t *testing.T) {
24 filePath := filepath.Join("testdata", "otelcol-invalid-components.yaml")
25 fileProvider := newFakeProvider("file", func(_ context.Context, _ string, _ confmap.WatcherFunc) (*confmap.Retrieved, error) {
26 return confmap.NewRetrieved(newConfFromFile(t, filePath))
27 })
28 cmd := newValidateSubCommand(CollectorSettings{Factories: nopFactories, ConfigProviderSettings: ConfigProviderSettings{
29 ResolverSettings: confmap.ResolverSettings{
30 URIs: []string{filePath},
31 ProviderFactories: []confmap.ProviderFactory{fileProvider},
32 DefaultScheme: "file",
33 },
34 }}, flags(featuregate.GlobalRegistry()))
35 err := cmd.Execute()
36 require.ErrorContains(t, err, "unknown type: \"nosuchprocessor\"")
37 }