57 lines
1.6 KiB
Go
57 lines
1.6 KiB
Go
package main
|
|
|
|
import "testing"
|
|
|
|
func TestDebugFlagOnlyEnablesDetailedLogsForBothRoles(t *testing.T) {
|
|
for _, flag := range []string{"--debug", "-D"} {
|
|
for _, role := range []string{"agent", "dispatcher"} {
|
|
command := newAgentCommand()
|
|
if role == "dispatcher" {
|
|
command = newDispatcherCommand()
|
|
}
|
|
if err := command.ParseFlags([]string{flag}); err != nil {
|
|
t.Fatalf("%s %s: %v", role, flag, err)
|
|
}
|
|
enabled, err := command.Flags().GetBool("debug")
|
|
if err != nil || !enabled {
|
|
t.Fatalf("%s %s: %v %v", role, flag, enabled, err)
|
|
}
|
|
if role == "agent" {
|
|
capture, err := command.Flags().GetBool("capture")
|
|
if err != nil || capture {
|
|
t.Fatalf("debug enabled capture: %v %v", capture, err)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
for _, command := range []*struct {
|
|
role string
|
|
enabled bool
|
|
}{{role: "agent"}, {role: "dispatcher"}} {
|
|
c := newAgentCommand()
|
|
if command.role == "dispatcher" {
|
|
c = newDispatcherCommand()
|
|
}
|
|
if enabled, _ := c.Flags().GetBool("debug"); enabled {
|
|
t.Fatal("debug must be off by default")
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestCaptureFlagIsSeparateAndAgentOnly(t *testing.T) {
|
|
command := newAgentCommand()
|
|
if err := command.ParseFlags([]string{"--capture"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
capture, err := command.Flags().GetBool("capture")
|
|
if err != nil || !capture {
|
|
t.Fatal(capture, err)
|
|
}
|
|
if debug, _ := command.Flags().GetBool("debug"); debug {
|
|
t.Fatal("capture must not enable raw logging")
|
|
}
|
|
if err := newDispatcherCommand().ParseFlags([]string{"--capture"}); err == nil {
|
|
t.Fatal("Dispatcher must reject capture")
|
|
}
|
|
}
|