Skip to content

Commit

Permalink
fix(logutil): fix golint error
Browse files Browse the repository at this point in the history
  • Loading branch information
maxshuang committed Jun 23, 2022
1 parent c695f06 commit b1ce2c9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
13 changes: 13 additions & 0 deletions pkg/logutil/context_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
// Copyright 2022 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

package logutil

import (
Expand Down
9 changes: 6 additions & 3 deletions pkg/logutil/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,15 @@ func TestErrorFilterContextCanceled(t *testing.T) {
buffer.Reset()

ErrorFilterContextCanceled(log.L(), "the message", zap.Int("number", 123456),
zap.Ints("array", []int{7, 8, 9}), ShortError(errors.Annotate(context.Canceled, "extra info")))
zap.Ints("array", []int{7, 8, 9}),
ShortError(errors.Annotate(context.Canceled, "extra info")))
require.Equal(t, "", buffer.Stripped())
buffer.Reset()

ErrorFilterContextCanceled(log.L(), "the message", zap.Int("number", 123456),
zap.Ints("array", []int{7, 8, 9}))
require.Regexp(t, regexp.QuoteMeta("[\"the message\"] [number=123456] [array=\"[7,8,9]\"]"), buffer.Stripped())
require.Regexp(t, regexp.QuoteMeta("[\"the message\"]"+
" [number=123456] [array=\"[7,8,9]\"]"), buffer.Stripped())
}

func TestShortError(t *testing.T) {
Expand All @@ -135,7 +137,8 @@ func TestShortError(t *testing.T) {

err = cerrors.ErrMetaNotInRegion.GenWithStackByArgs("extra info")
log.L().Warn("short error", ShortError(err))
require.Regexp(t, regexp.QuoteMeta("[\"short error\"] [error=\"[CDC:ErrMetaNotInRegion]meta not exists in region"), buffer.Stripped())
require.Regexp(t, regexp.QuoteMeta("[\"short error\"] "+
"[error=\"[CDC:ErrMetaNotInRegion]meta not exists in region"), buffer.Stripped())
buffer.Reset()

log.L().Warn("short error", ShortError(nil))
Expand Down

0 comments on commit b1ce2c9

Please sign in to comment.