NewMockWriter return *MockWriter -> MockWriter

pull/2/head
q191201771 5 years ago
parent b625351fcc
commit b2ab992bb2

@ -18,7 +18,7 @@ func BEUint16(p []byte) uint16 {
}
func BEUint24(p []byte) uint32 {
return uint32(p[2]) | uint32(p[1]) << 8 | uint32(p[0]) << 16
return uint32(p[2]) | uint32(p[1])<<8 | uint32(p[0])<<16
}
func BEUint32(p []byte) (ret uint32) {

@ -229,4 +229,3 @@ func BenchmarkWriteBE(b *testing.B) {
_ = WriteBE(out, in)
}
}

@ -176,7 +176,7 @@ func (l *logger) Outputf(level Level, calldepth int, format string, v ...interfa
msg := fmt.Sprintf(format, v...) + shortFileSuffix(calldepth)
if l.stdoutLogger != nil {
_ = l.stdoutLogger.Output(calldepth, levelToColorString[level] + msg)
_ = l.stdoutLogger.Output(calldepth, levelToColorString[level]+msg)
}
if l.fileLogger != nil {
if l.c.RotateMByte > 0 {
@ -195,7 +195,7 @@ func (l *logger) Outputf(level Level, calldepth int, format string, v ...interfa
}
}
}
_ = l.fileLogger.Output(calldepth, levelToString[level] + msg)
_ = l.fileLogger.Output(calldepth, levelToString[level]+msg)
}
}
@ -206,7 +206,7 @@ func (l *logger) Output(level Level, calldepth int, v ...interface{}) {
msg := fmt.Sprint(v...) + shortFileSuffix(calldepth)
if l.stdoutLogger != nil {
_ = l.stdoutLogger.Output(calldepth, levelToColorString[level] + msg)
_ = l.stdoutLogger.Output(calldepth, levelToColorString[level]+msg)
}
if l.fileLogger != nil {
if l.c.RotateMByte > 0 {
@ -225,7 +225,7 @@ func (l *logger) Output(level Level, calldepth int, v ...interface{}) {
}
}
}
_ = l.fileLogger.Output(calldepth, levelToString[level] + msg)
_ = l.fileLogger.Output(calldepth, levelToString[level]+msg)
}
}

@ -2,9 +2,9 @@ package log
import (
"github.com/q191201771/nezha/pkg/assert"
originLog "log"
"os"
"testing"
originLog "log"
)
func TestLogger(t *testing.T) {

@ -23,11 +23,11 @@ type MockWriter struct {
t WriterType
ts map[uint32]WriterType
count uint32
b bytes.Buffer
b bytes.Buffer
}
func NewMockWriter(t WriterType) *MockWriter {
return &MockWriter{
func NewMockWriter(t WriterType) MockWriter {
return MockWriter{
t: t,
}
}
@ -48,11 +48,10 @@ func (w *MockWriter) Write(b []byte) (int, error) {
return len(b), nil
case WriterTypeReturnError:
return 0, mockWriterErr
//case WriterTypeIntoBuffer:
// return w.b.Write(b)
//case WriterTypeIntoBuffer:
// return w.b.Write(b)
}
return w.b.Write(b)
//panic("never reach here.")
}

@ -11,10 +11,10 @@ func TestNewMockWriter(t *testing.T) {
func TestMockWriter_Write(t *testing.T) {
var (
w *MockWriter
n int
w MockWriter
n int
err error
b = []byte("hello")
b = []byte("hello")
)
w = NewMockWriter(WriterTypeDoNothing)
@ -35,10 +35,10 @@ func TestMockWriter_Write(t *testing.T) {
func TestMockWriter_SetSpecificType(t *testing.T) {
var (
w *MockWriter
n int
w MockWriter
n int
err error
b = []byte("hello")
b = []byte("hello")
)
w = NewMockWriter(WriterTypeDoNothing)
w.SetSpecificType(map[uint32]WriterType{
@ -70,3 +70,27 @@ func TestMockWriter_SetSpecificType(t *testing.T) {
assert.Equal(t, expectedErr[i], err)
}
}
func BenchmarkNewMockWriter(b *testing.B) {
b.ReportAllocs()
var tmp uint32
for i := 0; i < b.N; i++ {
mw := NewMockWriter(WriterTypeDoNothing)
tmp = tmp + mw.count
}
}
func newMockWriter2(t WriterType) *MockWriter {
return &MockWriter{
t: t,
}
}
func BenchmarkNewMockWriter2(b *testing.B) {
b.ReportAllocs()
var tmp uint32
for i := 0; i < b.N; i++ {
mw := newMockWriter2(WriterTypeDoNothing)
tmp = tmp + mw.count
}
}

@ -14,7 +14,7 @@ func TestGenUniqueKey(t *testing.T) {
for i := 0; i < 1000; i++ {
go func(j int) {
var uk string
if j % 2 == 0 {
if j%2 == 0 {
uk = GenUniqueKey("hello")
} else {
uk = GenUniqueKey("world")

Loading…
Cancel
Save