mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
d6415b2572
'any' type is supported starting from Go1.18. Let's consistently use it instead of 'interface{}' type across the code base, since `any` is easier to read than 'interface{}'.
25 lines
697 B
Go
25 lines
697 B
Go
package logger
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func TestFormatLogMessage(t *testing.T) {
|
|
f := func(format string, args []any, maxArgLen int, expectedResult string) {
|
|
t.Helper()
|
|
result := formatLogMessage(maxArgLen, format, args)
|
|
if result != expectedResult {
|
|
t.Fatalf("unexpected result; got\n%q\nwant\n%q", result, expectedResult)
|
|
}
|
|
}
|
|
|
|
// Zero format args
|
|
f("foobar", nil, 1, "foobar")
|
|
|
|
// Format args not exceeding the maxArgLen
|
|
f("foo: %d, %s, %s, %s", []any{123, "bar", []byte("baz"), fmt.Errorf("abc")}, 3, "foo: 123, bar, baz, abc")
|
|
|
|
// Format args exceeding the maxArgLen
|
|
f("foo: %s, %q, %s", []any{"abcde", fmt.Errorf("foo bar baz"), "xx"}, 4, `foo: a..e, "f..z", xx`)
|
|
}
|