Skip to content

Commit

Permalink
Rename skipCaller to skipCallers
Browse files Browse the repository at this point in the history
  • Loading branch information
dl1998 committed Apr 28, 2024
1 parent 7c340e5 commit 6a3b1ef
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 54 deletions.
6 changes: 3 additions & 3 deletions pkg/common/formatter/formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ var (
loggerName = "test"
loggingLevel = level.Debug
timeFormat = ""
skipCaller = 1
skipCallers = 1
)

// TestParseKey tests that ParseKey returns correct value for the key.
func TestParseKey(t *testing.T) {
record := logrecord.New(loggerName, loggingLevel, timeFormat, skipCaller)
record := logrecord.New(loggerName, loggingLevel, timeFormat, skipCallers)

tests := map[string]struct {
key string
Expand All @@ -44,7 +44,7 @@ func TestParseKey(t *testing.T) {

// BenchmarkParseKey performs benchmarking of the ParseKey().
func BenchmarkParseKey(b *testing.B) {
record := logrecord.New(loggerName, loggingLevel, timeFormat, skipCaller)
record := logrecord.New(loggerName, loggingLevel, timeFormat, skipCallers)

benchmarks := map[string]struct {
key string
Expand Down
36 changes: 18 additions & 18 deletions pkg/common/logrecord/logrecord_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import (
)

var (
skipCaller = 1
logLevel = level.Debug
name = "test"
timeFormat = ""
skipCallers = 1
logLevel = level.Debug
name = "test"
timeFormat = ""
)

// TestNew tests that New function returns a new LogRecord struct instance.
func TestNew(t *testing.T) {
_, file, line, _ := runtime.Caller(0)
record := New(name, logLevel, timeFormat, skipCaller)
record := New(name, logLevel, timeFormat, skipCallers)

testutils.AssertEquals(t, name, record.name)
testutils.AssertEquals(t, logLevel, record.level)
Expand All @@ -32,65 +32,65 @@ func TestNew(t *testing.T) {
// BenchmarkNew benchmarks the New function.
func BenchmarkNew(b *testing.B) {
for index := 0; index < b.N; index++ {
New(name, logLevel, "", skipCaller)
New(name, logLevel, "", skipCallers)
}
}

// TestName tests that Name function returns the name of the log record.
func TestName(t *testing.T) {
record := New(name, logLevel, "", skipCaller)
record := New(name, logLevel, "", skipCallers)

testutils.AssertEquals(t, name, record.Name())
}

// BenchmarkName benchmarks the Name function.
func BenchmarkName(b *testing.B) {
record := New(name, logLevel, "", skipCaller)
record := New(name, logLevel, "", skipCallers)
for index := 0; index < b.N; index++ {
record.Name()
}
}

// TestTime tests that Time function returns the time of the log record.
func TestTime(t *testing.T) {
record := New(name, logLevel, "", skipCaller)
record := New(name, logLevel, "", skipCallers)

testutils.AssertEquals(t, record.timestamp.Format(record.timeFormat), record.Time())
}

// BenchmarkTime benchmarks the Time function.
func BenchmarkTime(b *testing.B) {
record := New(name, logLevel, "", skipCaller)
record := New(name, logLevel, "", skipCallers)
for index := 0; index < b.N; index++ {
record.Time()
}
}

// TestTimestamp tests that Timestamp function returns the timestamp of the log record.
func TestTimestamp(t *testing.T) {
record := New(name, logLevel, "", skipCaller)
record := New(name, logLevel, "", skipCallers)

testutils.AssertEquals(t, record.timestamp.Unix(), record.Timestamp())
}

// BenchmarkTimestamp benchmarks the Timestamp function.
func BenchmarkTimestamp(b *testing.B) {
record := New(name, logLevel, "", skipCaller)
record := New(name, logLevel, "", skipCallers)
for index := 0; index < b.N; index++ {
record.Timestamp()
}
}

// TestLevel tests that Level function returns the level of the log record.
func TestLevel(t *testing.T) {
record := New(name, logLevel, "", skipCaller)
record := New(name, logLevel, "", skipCallers)

testutils.AssertEquals(t, logLevel, record.Level())
}

// BenchmarkLevel benchmarks the Level function.
func BenchmarkLevel(b *testing.B) {
record := New(name, logLevel, "", skipCaller)
record := New(name, logLevel, "", skipCallers)
for index := 0; index < b.N; index++ {
record.Level()
}
Expand All @@ -99,14 +99,14 @@ func BenchmarkLevel(b *testing.B) {
// TestFileName tests that FileName function returns the file name of the log record.
func TestFileName(t *testing.T) {
_, file, _, _ := runtime.Caller(0)
record := New(name, logLevel, "", skipCaller)
record := New(name, logLevel, "", skipCallers)

testutils.AssertEquals(t, file, record.FileName())
}

// BenchmarkFileName benchmarks the FileName function.
func BenchmarkFileName(b *testing.B) {
record := New(name, logLevel, "", skipCaller)
record := New(name, logLevel, "", skipCallers)
for index := 0; index < b.N; index++ {
record.FileName()
}
Expand All @@ -115,14 +115,14 @@ func BenchmarkFileName(b *testing.B) {
// TestFileLine tests that FileLine function returns the file line of the log record.
func TestFileLine(t *testing.T) {
_, _, line, _ := runtime.Caller(0)
record := New(name, logLevel, "", skipCaller)
record := New(name, logLevel, "", skipCallers)

testutils.AssertEquals(t, line+1, record.FileLine())
}

// BenchmarkFileLine benchmarks the FileLine function.
func BenchmarkFileLine(b *testing.B) {
record := New(name, logLevel, "", skipCaller)
record := New(name, logLevel, "", skipCallers)
for index := 0; index < b.N; index++ {
record.FileLine()
}
Expand Down
18 changes: 9 additions & 9 deletions pkg/logger/formatter/formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var (
loggingLevel = level.Debug
timeFormat = ""
emptyParameters = make([]any, 0)
skipCaller = 1
skipCallers = 1
)

// TestNew tests that New create correct Formatter instance.
Expand Down Expand Up @@ -85,7 +85,7 @@ func TestFormatter_Format(t *testing.T) {
}

for name, parameters := range tests {
record := logrecord.New(loggerName, loggingLevel, timeFormat, message, emptyParameters, skipCaller)
record := logrecord.New(loggerName, loggingLevel, timeFormat, message, emptyParameters, skipCallers)

t.Run(name, func(t *testing.T) {
actual := newFormatter.Format(record, parameters.colored)
Expand All @@ -99,7 +99,7 @@ func TestFormatter_Format(t *testing.T) {
func BenchmarkFormatter_Format(b *testing.B) {
newFormatter := New(template)

record := logrecord.New(loggerName, loggingLevel, timeFormat, message, emptyParameters, skipCaller)
record := logrecord.New(loggerName, loggingLevel, timeFormat, message, emptyParameters, skipCallers)

b.ResetTimer()

Expand All @@ -110,7 +110,7 @@ func BenchmarkFormatter_Format(b *testing.B) {

// TestParseTemplate tests that ParseTemplate correctly replaces keys with values.
func TestParseTemplate(t *testing.T) {
format := ParseTemplate(template, logrecord.New(loggerName, loggingLevel, timeFormat, message, emptyParameters, skipCaller))
format := ParseTemplate(template, logrecord.New(loggerName, loggingLevel, timeFormat, message, emptyParameters, skipCallers))

expected := fmt.Sprintf("%s:%s:%s", loggingLevel.String(), loggerName, message)

Expand All @@ -120,13 +120,13 @@ func TestParseTemplate(t *testing.T) {
// BenchmarkParseTemplate performs benchmarking of the ParseTemplate().
func BenchmarkParseTemplate(b *testing.B) {
for index := 0; index < b.N; index++ {
ParseTemplate(template, logrecord.New(loggerName, loggingLevel, timeFormat, message, emptyParameters, skipCaller))
ParseTemplate(template, logrecord.New(loggerName, loggingLevel, timeFormat, message, emptyParameters, skipCallers))
}
}

// TestReplaceKey tests that ReplaceKey correctly replaces key with value.
func TestReplaceKey(t *testing.T) {
record := logrecord.New(loggerName, loggingLevel, timeFormat, message, emptyParameters, skipCaller)
record := logrecord.New(loggerName, loggingLevel, timeFormat, message, emptyParameters, skipCallers)

tests := map[string]struct {
key string
Expand All @@ -147,7 +147,7 @@ func TestReplaceKey(t *testing.T) {

// BenchmarkReplaceKey performs benchmarking of the ReplaceKey().
func BenchmarkReplaceKey(b *testing.B) {
record := logrecord.New(loggerName, loggingLevel, timeFormat, message, emptyParameters, skipCaller)
record := logrecord.New(loggerName, loggingLevel, timeFormat, message, emptyParameters, skipCallers)

benchmarks := map[string]struct {
key string
Expand All @@ -169,7 +169,7 @@ func BenchmarkReplaceKey(b *testing.B) {

// TestParseKey tests that ParseKey returns correct value for the key.
func TestParseKey(t *testing.T) {
record := logrecord.New(loggerName, loggingLevel, timeFormat, message, emptyParameters, skipCaller)
record := logrecord.New(loggerName, loggingLevel, timeFormat, message, emptyParameters, skipCallers)

tests := map[string]struct {
key string
Expand All @@ -196,7 +196,7 @@ func TestParseKey(t *testing.T) {

// BenchmarkParseKey performs benchmarking of the ParseKey().
func BenchmarkParseKey(b *testing.B) {
record := logrecord.New(loggerName, loggingLevel, timeFormat, message, emptyParameters, skipCaller)
record := logrecord.New(loggerName, loggingLevel, timeFormat, message, emptyParameters, skipCallers)

benchmarks := map[string]struct {
key string
Expand Down
20 changes: 10 additions & 10 deletions pkg/logger/logrecord/logrecord_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,39 @@ import (
)

var (
skipCaller = 1
logLevel = level.Debug
name = "test"
timeFormat = ""
message = "Test message."
parameters = make([]any, 0)
skipCallers = 1
logLevel = level.Debug
name = "test"
timeFormat = ""
message = "Test message."
parameters = make([]any, 0)
)

// TestNew tests that New function returns a new LogRecord instance.
func TestNew(t *testing.T) {
record := New(name, logLevel, timeFormat, message, parameters, skipCaller)
record := New(name, logLevel, timeFormat, message, parameters, skipCallers)

testutils.AssertEquals(t, message, record.message)
}

// BenchmarkNew benchmarks the New function.
func BenchmarkNew(b *testing.B) {
for index := 0; index < b.N; index++ {
New(name, logLevel, timeFormat, message, parameters, skipCaller)
New(name, logLevel, timeFormat, message, parameters, skipCallers)
}
}

// TestMessage tests that Message function returns the formatted message of the
// log record.
func TestMessage(t *testing.T) {
record := New(name, logLevel, timeFormat, message, parameters, skipCaller)
record := New(name, logLevel, timeFormat, message, parameters, skipCallers)

testutils.AssertEquals(t, message, record.Message())
}

// BenchmarkMessage benchmarks the Message function.
func BenchmarkMessage(b *testing.B) {
record := New(name, logLevel, timeFormat, message, parameters, skipCaller)
record := New(name, logLevel, timeFormat, message, parameters, skipCallers)
for index := 0; index < b.N; index++ {
record.Message()
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/structuredlogger/formatter/formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const (
pairSeparator = ", "
message = "Test message."
static = "test"
skipCallers = 1
)

var template = map[string]string{
Expand Down Expand Up @@ -77,7 +78,7 @@ func TestJSONFormatter_Format(t *testing.T) {
}

for testName, parameters := range tests {
record := logrecord.New(loggerName, loggingLevel, "", map[string]interface{}{"message": message}, 0)
record := logrecord.New(loggerName, loggingLevel, "", map[string]interface{}{"message": message}, skipCallers)
t.Run(testName, func(t *testing.T) {
newFormatter := NewJSON(parameters.template, parameters.pretty)

Expand All @@ -90,7 +91,7 @@ func TestJSONFormatter_Format(t *testing.T) {
func TestJSONFormatter_FormatError(t *testing.T) {
newFormatter := NewJSON(template, pretty)

record := logrecord.New(loggerName, loggingLevel, "", map[string]interface{}{"key": math.Inf(1)}, 0)
record := logrecord.New(loggerName, loggingLevel, "", map[string]interface{}{"key": math.Inf(1)}, skipCallers)

testutils.AssertEquals(t, "", newFormatter.Format(record, false))
}
Expand Down Expand Up @@ -125,7 +126,7 @@ func BenchmarkJSONFormatter_Format(b *testing.B) {
}

for testName, parameters := range benchmarks {
record := logrecord.New(loggerName, loggingLevel, "", map[string]interface{}{"message": message}, 0)
record := logrecord.New(loggerName, loggingLevel, "", map[string]interface{}{"message": message}, skipCallers)
b.Run(testName, func(b *testing.B) {
b.ResetTimer()

Expand Down Expand Up @@ -207,7 +208,7 @@ func TestKeyValueFormatter_Format(t *testing.T) {
}

for testName, parameters := range tests {
record := logrecord.New(loggerName, loggingLevel, "", map[string]interface{}{"message": message, "bool": boolValue, "int": intValue, "int64": int64Value, "float64": float64Value, "float32": float32Value}, 0)
record := logrecord.New(loggerName, loggingLevel, "", map[string]interface{}{"message": message, "bool": boolValue, "int": intValue, "int64": int64Value, "float64": float64Value, "float32": float32Value}, skipCallers)
t.Run(testName, func(t *testing.T) {
newFormatter := NewKeyValue(parameters.template, parameters.delimiter, parameters.separator)

Expand Down Expand Up @@ -245,7 +246,7 @@ func BenchmarkKeyValueFormatter_Format(b *testing.B) {
}

for testName, parameters := range benchmarks {
record := logrecord.New(loggerName, loggingLevel, "", map[string]interface{}{"message": message}, 0)
record := logrecord.New(loggerName, loggingLevel, "", map[string]interface{}{"message": message}, skipCallers)
b.Run(testName, func(b *testing.B) {
b.ResetTimer()

Expand Down
18 changes: 9 additions & 9 deletions pkg/structuredlogger/logrecord/logrecord_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,39 @@ import (
)

var (
skipCaller = 1
logLevel = level.Debug
name = "test"
timeFormat = ""
parameters = map[string]interface{}{
skipCallers = 1
logLevel = level.Debug
name = "test"
timeFormat = ""
parameters = map[string]interface{}{
"message": "Test Message.",
}
)

// TestNew tests that New function returns a new structured LogRecord instance.
func TestNew(t *testing.T) {
record := New(name, logLevel, timeFormat, parameters, skipCaller)
record := New(name, logLevel, timeFormat, parameters, skipCallers)

testutils.AssertEquals(t, parameters, record.parameters)
}

// BenchmarkNew benchmarks the New function.
func BenchmarkNew(b *testing.B) {
for index := 0; index < b.N; index++ {
New(name, logLevel, timeFormat, parameters, skipCaller)
New(name, logLevel, timeFormat, parameters, skipCallers)
}
}

// TestParameters tests that Parameters function returns the parameters of the log record.
func TestParameters(t *testing.T) {
record := New(name, logLevel, timeFormat, parameters, skipCaller)
record := New(name, logLevel, timeFormat, parameters, skipCallers)

testutils.AssertEquals(t, parameters, record.Parameters())
}

// BenchmarkParameters benchmarks the Parameters function.
func BenchmarkParameters(b *testing.B) {
record := New(name, logLevel, timeFormat, parameters, skipCaller)
record := New(name, logLevel, timeFormat, parameters, skipCallers)
for index := 0; index < b.N; index++ {
record.Parameters()
}
Expand Down

0 comments on commit 6a3b1ef

Please sign in to comment.