mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-08 03:33:56 +00:00
ktesting: improve per-test log output
format.Object adds some white space in front of the value and a type identifier in angle brackets. Both is distracting when printing simple values and can be avoided by picking fmt.Sprintf for those types, plus trimming the result of format.Object. Before: allocator.go:483: I0625 15:35:31.946980] Allocating one device currentClaim= <int>: 0 totalClaims= <int>: 1 currentRequest= <int>: 0 totalRequestsPerClaim= <int>: 1 currentDevice= <int>: 0 devicesPerRequest= <int>: 1 allDevices= <bool>: false adminAccess= <bool>: false After: allocator.go:483: I0625 15:35:04.371441] Allocating one device currentClaim=0 totalClaims=1 currentRequest=0 totalRequestsPerClaim=1 currentDevice=0 devicesPerRequest=1 allDevices=false adminAccess=false
This commit is contained in:
parent
8cf93c8d83
commit
900457c09b
@ -20,6 +20,7 @@ import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/onsi/gomega"
|
||||
@ -241,7 +242,19 @@ func Init(tb TB, opts ...InitOption) TContext {
|
||||
if c.PerTestOutput {
|
||||
config := ktesting.NewConfig(
|
||||
ktesting.AnyToString(func(v interface{}) string {
|
||||
return format.Object(v, 1)
|
||||
// For basic types where the string
|
||||
// representation is "obvious" we use
|
||||
// fmt.Sprintf because format.Object always
|
||||
// adds a <"type"> prefix, which is too long
|
||||
// for simple values.
|
||||
switch v := v.(type) {
|
||||
case int, int32, int64, uint, uint32, uint64, float32, float64, bool:
|
||||
return fmt.Sprintf("%v", v)
|
||||
case string:
|
||||
return v
|
||||
default:
|
||||
return strings.TrimSpace(format.Object(v, 1))
|
||||
}
|
||||
}),
|
||||
ktesting.VerbosityFlagName("v"),
|
||||
ktesting.VModuleFlagName("vmodule"),
|
||||
|
Loading…
Reference in New Issue
Block a user