Fix log unit test (#11225)

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
pull/11102/head
congqixia 2021-11-04 14:58:08 +08:00 committed by GitHub
parent 83bfe43e76
commit 3e793469ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 10 deletions

View File

@ -114,14 +114,14 @@ func TestLog(t *testing.T) {
zap.Duration("duration", 10*time.Second),
)
ts.assertMessages(
`[INFO] [zap_log_test.go:61] ["failed to fetch URL"] [url=http://example.com] [attempt=3] [backoff=1s]`,
`[INFO] [zap_log_test.go:66] ["failed to \"fetch\" [URL]: http://example.com"]`,
`[DEBUG] [zap_log_test.go:67] ["Slow query"] [sql="SELECT * FROM TABLE\n\tWHERE ID=\"abc\""] [duration=1.3s] ["process keys"=1500]`,
`[INFO] [zap_log_test.go:73] [Welcome]`,
`[INFO] [zap_log_test.go:74] [欢迎]`,
`[WARN] [zap_log_test.go:75] [Type] [Counter=NaN] [Score=+Inf]`,
`[INFO] [zap_log_test.go:80] ["new connection"] [connID=1] [traceID=dse1121]`,
`[INFO] [zap_log_test.go:81] ["Testing typs"] [filed1=noquote] `+
`[INFO] [zap_log_test.go:66] ["failed to fetch URL"] [url=http://example.com] [attempt=3] [backoff=1s]`,
`[INFO] [zap_log_test.go:71] ["failed to \"fetch\" [URL]: http://example.com"]`,
`[DEBUG] [zap_log_test.go:72] ["Slow query"] [sql="SELECT * FROM TABLE\n\tWHERE ID=\"abc\""] [duration=1.3s] ["process keys"=1500]`,
`[INFO] [zap_log_test.go:78] [Welcome]`,
`[INFO] [zap_log_test.go:79] [欢迎]`,
`[WARN] [zap_log_test.go:80] [Type] [Counter=NaN] [Score=+Inf]`,
`[INFO] [zap_log_test.go:85] ["new connection"] [connID=1] [traceID=dse1121]`,
`[INFO] [zap_log_test.go:86] ["Testing typs"] [filed1=noquote] `+
`[filed2="in quote"] [urls="[http://mock1.com:2347,http://mock2.com:2432]"] `+
`[urls-peer="[t1,\"t2 fine\"]"] ["store ids"="[1,4,5]"] [object="{username=user1}"] `+
`[object2="{username=\"user 2\"}"] [binary="YWIxMjM="] ["is processed"=true] `+
@ -192,8 +192,8 @@ func TestLogJSON(t *testing.T) {
"backoff", time.Second,
)
logger.With(zap.String("connID", "1"), zap.String("traceID", "dse1121")).Info("new connection")
ts.assertMessages("{\"level\":\"INFO\",\"caller\":\"zap_log_test.go:184\",\"message\":\"failed to fetch URL\",\"url\":\"http://example.com\",\"attempt\":3,\"backoff\":\"1s\"}",
"{\"level\":\"INFO\",\"caller\":\"zap_log_test.go:189\",\"message\":\"new connection\",\"connID\":\"1\",\"traceID\":\"dse1121\"}")
ts.assertMessages("{\"level\":\"INFO\",\"caller\":\"zap_log_test.go:189\",\"message\":\"failed to fetch URL\",\"url\":\"http://example.com\",\"attempt\":3,\"backoff\":\"1s\"}",
"{\"level\":\"INFO\",\"caller\":\"zap_log_test.go:194\",\"message\":\"new connection\",\"connID\":\"1\",\"traceID\":\"dse1121\"}")
}
func TestRotateLog(t *testing.T) {