**What** - Add new flags to toggle the name, instance, and timestamp fields. Additionally, the new `time-format` also allows controlling the actual timestamp format. - Also provide the log format flag to allow printing the output as JSON, key-values, or the plain format. This should make it easy to integrate with other tools, like JQ etc. Signed-off-by: Lucas Roesler <roesler.lucas@gmail.com>
33 lines
723 B
Go
33 lines
723 B
Go
package flags
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestTimeFormat(t *testing.T) {
|
|
|
|
cases := []struct {
|
|
name string
|
|
value string
|
|
expected string
|
|
}{
|
|
{"can parse short name rfc850", "rfc850", "Monday, 02-Jan-06 15:04:05 MST"},
|
|
{"can accept an arbitrary format string", "2006-01-02 15:04:05.999999999 -0700 MST", "2006-01-02 15:04:05.999999999 -0700 MST"},
|
|
{"can accept arbitrary string", "nonsense", "nonsense"},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
var f TimeFormat
|
|
err := f.Set(tc.value)
|
|
if err != nil {
|
|
t.Fatalf("should not be able to error")
|
|
}
|
|
if f.String() != tc.expected {
|
|
t.Errorf("expected time %s, got %s", tc.expected, f.String())
|
|
}
|
|
})
|
|
}
|
|
|
|
}
|