diff --git a/cmd/config.go b/cmd/config.go index 4aa3ea19..7094134d 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -105,7 +105,7 @@ func (c ConfigRelatedOptions) Parse(out io.Writer, component string, config inte continue } kk := strings.Split(kv[0], "_") - if len(kk) < 4 || kk[0] != "AKVORADO" || kk[1] != "CFG" || kk[2] != strings.ToUpper(component) { + if len(kk) < 4 || kk[0] != "AKVORADO" || kk[1] != "CFG" || kk[2] != strings.ReplaceAll(strings.ToUpper(component), "-", "") { continue } // From AKVORADO_CFG_CMP_SQUID_PURPLE_QUIRK=47, we diff --git a/cmd/console_test.go b/cmd/console_test.go index 474ca8b3..5059c99f 100644 --- a/cmd/console_test.go +++ b/cmd/console_test.go @@ -4,6 +4,7 @@ package cmd import ( + "bytes" "testing" "akvorado/common/reporter" @@ -17,3 +18,14 @@ func TestConsoleStart(t *testing.T) { t.Fatalf("consoleStart() error:\n%+v", err) } } + +func TestConsole(t *testing.T) { + root := RootCmd + buf := new(bytes.Buffer) + root.SetOut(buf) + root.SetArgs([]string{"console", "--check", "/dev/null"}) + err := root.Execute() + if err != nil { + t.Errorf("`console` error:\n%+v", err) + } +} diff --git a/cmd/demo-exporter_test.go b/cmd/demo-exporter_test.go index 8894778c..3714379b 100644 --- a/cmd/demo-exporter_test.go +++ b/cmd/demo-exporter_test.go @@ -4,8 +4,11 @@ package cmd import ( + "bytes" + "strings" "testing" + "akvorado/common/helpers" "akvorado/common/reporter" ) @@ -17,3 +20,27 @@ func TestDemoExporterStart(t *testing.T) { t.Fatalf("demoExporterStart() error:\n%+v", err) } } + +func TestDemoExporter(t *testing.T) { + root := RootCmd + buf := new(bytes.Buffer) + root.SetOut(buf) + root.SetArgs([]string{"demo-exporter", "--check", "/dev/null"}) + t.Setenv("AKVORADO_CFG_DEMOEXPORTER_SNMP_NAME", "test") + err := root.Execute() + if err == nil { + t.Fatal("`demo-exporter` should produce an error") + } + + want := []string{ + `invalid configuration:`, + `Key: 'DemoExporterConfiguration.SNMP.Interfaces' Error:Field validation for 'Interfaces' failed on the 'min' tag`, + `Key: 'DemoExporterConfiguration.Flows.Flows' Error:Field validation for 'Flows' failed on the 'min' tag`, + `Key: 'DemoExporterConfiguration.Flows.Target' Error:Field validation for 'Target' failed on the 'required' tag`, + } + got := strings.Split(err.Error(), "\n") + if diff := helpers.Diff(got, want); diff != "" { + t.Fatalf("`demo-exporter` (-got, +want):\n%s", diff) + } + +} diff --git a/cmd/inlet_test.go b/cmd/inlet_test.go index f1f920f5..40df7fb0 100644 --- a/cmd/inlet_test.go +++ b/cmd/inlet_test.go @@ -4,6 +4,7 @@ package cmd import ( + "bytes" "testing" "akvorado/common/reporter" @@ -17,3 +18,14 @@ func TestInletStart(t *testing.T) { t.Fatalf("inletStart() error:\n%+v", err) } } + +func TestInlet(t *testing.T) { + root := RootCmd + buf := new(bytes.Buffer) + root.SetOut(buf) + root.SetArgs([]string{"inlet", "--check", "/dev/null"}) + err := root.Execute() + if err != nil { + t.Errorf("`inlet` error:\n%+v", err) + } +} diff --git a/cmd/orchestrator_test.go b/cmd/orchestrator_test.go index 5b31cd32..c2e4fce2 100644 --- a/cmd/orchestrator_test.go +++ b/cmd/orchestrator_test.go @@ -97,3 +97,14 @@ func TestOrchestratorConfig(t *testing.T) { }) } } + +func TestOrchestrator(t *testing.T) { + root := RootCmd + buf := new(bytes.Buffer) + root.SetOut(buf) + root.SetArgs([]string{"orchestrator", "--check", "/dev/null"}) + err := root.Execute() + if err != nil { + t.Errorf("`orchestrator` error:\n%+v", err) + } +}