mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-12 06:24:10 +01:00
cmd: test command checks
This commit is contained in:
@@ -105,7 +105,7 @@ func (c ConfigRelatedOptions) Parse(out io.Writer, component string, config inte
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
kk := strings.Split(kv[0], "_")
|
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
|
continue
|
||||||
}
|
}
|
||||||
// From AKVORADO_CFG_CMP_SQUID_PURPLE_QUIRK=47, we
|
// From AKVORADO_CFG_CMP_SQUID_PURPLE_QUIRK=47, we
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"akvorado/common/reporter"
|
"akvorado/common/reporter"
|
||||||
@@ -17,3 +18,14 @@ func TestConsoleStart(t *testing.T) {
|
|||||||
t.Fatalf("consoleStart() error:\n%+v", err)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,8 +4,11 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"akvorado/common/helpers"
|
||||||
"akvorado/common/reporter"
|
"akvorado/common/reporter"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -17,3 +20,27 @@ func TestDemoExporterStart(t *testing.T) {
|
|||||||
t.Fatalf("demoExporterStart() error:\n%+v", err)
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"akvorado/common/reporter"
|
"akvorado/common/reporter"
|
||||||
@@ -17,3 +18,14 @@ func TestInletStart(t *testing.T) {
|
|||||||
t.Fatalf("inletStart() error:\n%+v", err)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user