Files
faas-cli/flags/log_format_test.go
Lucas Roesler 893972afff Add flags to control the log output format
**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>
2019-08-19 15:00:32 +01:00

34 lines
729 B
Go

package flags
import (
"errors"
"testing"
)
func TestLogFormat(t *testing.T) {
cases := []struct {
name string
value string
err error
}{
{"can accept plain", "plain", nil},
{"can accept keyvalue", "keyvalue", nil},
{"can accept json", "json", nil},
{"unknown strings cause error string", "nonsense", errors.New("unknown log format: 'nonsense'")},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
var f LogFormat
err := f.Set(tc.value)
if tc.err != nil && tc.err.Error() != err.Error() {
t.Fatalf("expected error %s, got %s", tc.err, err)
}
if tc.err == nil && f.String() != tc.value {
t.Errorf("expected format %s, got %s", tc.value, f.String())
}
})
}
}