From 3e793469ec33fea4dd4df7d045bf33540316957a Mon Sep 17 00:00:00 2001 From: congqixia Date: Thu, 4 Nov 2021 14:58:08 +0800 Subject: [PATCH] Fix log unit test (#11225) Signed-off-by: Congqi Xia --- internal/log/zap_log_test.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/internal/log/zap_log_test.go b/internal/log/zap_log_test.go index 804eef74c7..07204c7701 100644 --- a/internal/log/zap_log_test.go +++ b/internal/log/zap_log_test.go @@ -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) {