testing: reduce verbosity of output log
Previously the log output included the test name twice and a long date format. The test output is already grouped by test, so adding the test name did not add any new information. The date and time are only useful to understand elapsed time, so using a short format should provide succident detail. Also fixed a bug in NewTestAgentWithFields where nil was returned instead of the test agent.
This commit is contained in:
parent
0505ebd04c
commit
823295fe2a
|
@ -138,11 +138,7 @@ func TestAgent_ConnectClusterIDConfig(t *testing.T) {
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
// This is a rare case where using a constructor for TestAgent
|
a := NewTestAgentWithFields(t, false, TestAgent{HCL: tt.hcl})
|
||||||
// (NewTestAgent and the likes) won't work, since we expect an error
|
|
||||||
// in one test case, and the constructors have built-in retry logic
|
|
||||||
// that runs automatically upon error.
|
|
||||||
a := &TestAgent{Name: tt.name, HCL: tt.hcl, LogOutput: testutil.TestWriter(t)}
|
|
||||||
err := a.Start()
|
err := a.Start()
|
||||||
if tt.wantErr {
|
if tt.wantErr {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
|
@ -25,7 +25,6 @@ import (
|
||||||
"github.com/hashicorp/consul/agent/structs"
|
"github.com/hashicorp/consul/agent/structs"
|
||||||
"github.com/hashicorp/consul/api"
|
"github.com/hashicorp/consul/api"
|
||||||
"github.com/hashicorp/consul/sdk/freeport"
|
"github.com/hashicorp/consul/sdk/freeport"
|
||||||
"github.com/hashicorp/consul/sdk/testutil"
|
|
||||||
"github.com/hashicorp/consul/sdk/testutil/retry"
|
"github.com/hashicorp/consul/sdk/testutil/retry"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -104,11 +103,8 @@ func NewTestAgentWithFields(t *testing.T, start bool, ta TestAgent) *TestAgent {
|
||||||
if a.Name == "" {
|
if a.Name == "" {
|
||||||
a.Name = t.Name()
|
a.Name = t.Name()
|
||||||
}
|
}
|
||||||
if a.LogOutput == nil {
|
|
||||||
a.LogOutput = testutil.TestWriter(t)
|
|
||||||
}
|
|
||||||
if !start {
|
if !start {
|
||||||
return nil
|
return &a
|
||||||
}
|
}
|
||||||
|
|
||||||
retry.RunWith(retry.ThreeTimes(), t, func(r *retry.R) {
|
retry.RunWith(retry.ThreeTimes(), t, func(r *retry.R) {
|
||||||
|
@ -162,9 +158,9 @@ func (a *TestAgent) Start() (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
logger := hclog.NewInterceptLogger(&hclog.LoggerOptions{
|
logger := hclog.NewInterceptLogger(&hclog.LoggerOptions{
|
||||||
Name: a.Name,
|
Level: hclog.Debug,
|
||||||
Level: hclog.Debug,
|
Output: logOutput,
|
||||||
Output: logOutput,
|
TimeFormat: "04:05.000",
|
||||||
})
|
})
|
||||||
|
|
||||||
portsConfig, returnPortsFn := randomPortsSource(a.UseTLS)
|
portsConfig, returnPortsFn := randomPortsSource(a.UseTLS)
|
||||||
|
|
Loading…
Reference in New Issue