Skip to content

Commit d78b748

Browse files
authored
[otelcol] Add unit test for implicit config use case (#9302)
**Description:** * Add unit test that illustrates running the command without an external config * This models how Jaeger all-in-one uses collector because all-in-one can be run without arguments, for maximum user friendliness --------- Signed-off-by: Yuri Shkuro <[email protected]>
1 parent 9bb794b commit d78b748

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

otelcol/command_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"path/filepath"
88
"testing"
99

10+
"github.com/spf13/cobra"
1011
"github.com/stretchr/testify/assert"
1112
"github.com/stretchr/testify/require"
1213

@@ -26,6 +27,26 @@ func TestNewCommandNoConfigURI(t *testing.T) {
2627
require.Error(t, cmd.Execute())
2728
}
2829

30+
// This test emulates usage of Collector in Jaeger all-in-one, which
31+
// allows running the binary with no explicit configuration.
32+
func TestNewCommandProgrammaticallyPassedConfig(t *testing.T) {
33+
cmd := NewCommand(CollectorSettings{Factories: nopFactories})
34+
otelRunE := cmd.RunE
35+
cmd.RunE = func(c *cobra.Command, args []string) error {
36+
configFlag := c.Flag("config")
37+
cfg := `
38+
service:
39+
extensions: [invalid_component_name]
40+
receivers:
41+
invalid_component_name:
42+
`
43+
require.NoError(t, configFlag.Value.Set("yaml:"+cfg))
44+
return otelRunE(cmd, args)
45+
}
46+
// verify that cmd.Execute was run with the implicitly provided config.
47+
require.ErrorContains(t, cmd.Execute(), "invalid_component_name")
48+
}
49+
2950
func TestNewCommandInvalidComponent(t *testing.T) {
3051
cfgProvider, err := NewConfigProvider(
3152
ConfigProviderSettings{

0 commit comments

Comments
 (0)