Improve test logger assertions
This commit is contained in:
parent
3dd4968c41
commit
08279047ae
11 changed files with 88 additions and 11 deletions
|
@ -1,17 +1,24 @@
|
|||
package logs
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewAWSWrapper(t *testing.T) {
|
||||
out := zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339}
|
||||
buf := bytes.NewBuffer(nil)
|
||||
cwb := zerolog.ConsoleWriter{Out: buf, TimeFormat: time.RFC3339, NoColor: true}
|
||||
|
||||
out := zerolog.MultiLevelWriter(zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339}, cwb)
|
||||
|
||||
logger := NewAWSWrapper(zerolog.New(out).With().Caller().Logger())
|
||||
|
||||
logger.Log("foo")
|
||||
|
||||
assert.Equal(t, "<nil> DBG aws_test.go:21 > foo\n", buf.String())
|
||||
}
|
||||
|
|
|
@ -1,17 +1,24 @@
|
|||
package logs
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewDatadogLogger(t *testing.T) {
|
||||
out := zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339}
|
||||
buf := bytes.NewBuffer(nil)
|
||||
cwb := zerolog.ConsoleWriter{Out: buf, TimeFormat: time.RFC3339, NoColor: true}
|
||||
|
||||
out := zerolog.MultiLevelWriter(zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339}, cwb)
|
||||
|
||||
logger := NewDatadogLogger(zerolog.New(out).With().Caller().Logger())
|
||||
|
||||
logger.Log("foo")
|
||||
|
||||
assert.Equal(t, "<nil> DBG datadog_test.go:21 > foo\n", buf.String())
|
||||
}
|
||||
|
|
|
@ -1,17 +1,24 @@
|
|||
package logs
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewElasticLogger(t *testing.T) {
|
||||
out := zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339}
|
||||
buf := bytes.NewBuffer(nil)
|
||||
cwb := zerolog.ConsoleWriter{Out: buf, TimeFormat: time.RFC3339, NoColor: true}
|
||||
|
||||
out := zerolog.MultiLevelWriter(zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339}, cwb)
|
||||
|
||||
logger := NewElasticLogger(zerolog.New(out).With().Caller().Logger())
|
||||
|
||||
logger.Errorf("foo")
|
||||
|
||||
assert.Equal(t, "<nil> ERR elastic_test.go:21 > foo\n", buf.String())
|
||||
}
|
||||
|
|
|
@ -1,17 +1,24 @@
|
|||
package logs
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewGoKitWrapper(t *testing.T) {
|
||||
out := zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339}
|
||||
buf := bytes.NewBuffer(nil)
|
||||
cwb := zerolog.ConsoleWriter{Out: buf, TimeFormat: time.RFC3339, NoColor: true}
|
||||
|
||||
out := zerolog.MultiLevelWriter(zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339}, cwb)
|
||||
|
||||
logger := NewGoKitWrapper(zerolog.New(out).With().Caller().Logger())
|
||||
|
||||
_ = logger.Log("foo")
|
||||
|
||||
assert.Equal(t, "<nil> DBG gokit_test.go:21 > foo\n", buf.String())
|
||||
}
|
||||
|
|
|
@ -1,17 +1,24 @@
|
|||
package logs
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewHaystackLogger(t *testing.T) {
|
||||
out := zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339}
|
||||
buf := bytes.NewBuffer(nil)
|
||||
cwb := zerolog.ConsoleWriter{Out: buf, TimeFormat: time.RFC3339, NoColor: true}
|
||||
|
||||
out := zerolog.MultiLevelWriter(zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339}, cwb)
|
||||
|
||||
logger := NewHaystackLogger(zerolog.New(out).With().Caller().Logger())
|
||||
|
||||
logger.Info("foo")
|
||||
|
||||
assert.Equal(t, "<nil> INF haystack_test.go:21 > foo\n", buf.String())
|
||||
}
|
||||
|
|
|
@ -1,17 +1,24 @@
|
|||
package logs
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewRetryableHTTPLogger(t *testing.T) {
|
||||
out := zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339}
|
||||
buf := bytes.NewBuffer(nil)
|
||||
cwb := zerolog.ConsoleWriter{Out: buf, TimeFormat: time.RFC3339, NoColor: true}
|
||||
|
||||
out := zerolog.MultiLevelWriter(zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339}, cwb)
|
||||
|
||||
logger := NewRetryableHTTPLogger(zerolog.New(out).With().Caller().Logger())
|
||||
|
||||
logger.Info("foo")
|
||||
|
||||
assert.Equal(t, "<nil> INF hclog_test.go:21 > Foo\n", buf.String())
|
||||
}
|
||||
|
|
|
@ -1,17 +1,24 @@
|
|||
package logs
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewInstanaLogger(t *testing.T) {
|
||||
out := zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339}
|
||||
buf := bytes.NewBuffer(nil)
|
||||
cwb := zerolog.ConsoleWriter{Out: buf, TimeFormat: time.RFC3339, NoColor: true}
|
||||
|
||||
out := zerolog.MultiLevelWriter(zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339}, cwb)
|
||||
|
||||
logger := NewInstanaLogger(zerolog.New(out).With().Caller().Logger())
|
||||
|
||||
logger.Info("foo")
|
||||
|
||||
assert.Equal(t, "<nil> INF instana_test.go:21 > foo\n", buf.String())
|
||||
}
|
||||
|
|
|
@ -1,17 +1,24 @@
|
|||
package logs
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewJaegerLogger(t *testing.T) {
|
||||
out := zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339}
|
||||
buf := bytes.NewBuffer(nil)
|
||||
cwb := zerolog.ConsoleWriter{Out: buf, TimeFormat: time.RFC3339, NoColor: true}
|
||||
|
||||
out := zerolog.MultiLevelWriter(zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339}, cwb)
|
||||
|
||||
logger := NewJaegerLogger(zerolog.New(out).With().Caller().Logger())
|
||||
|
||||
logger.Infof("foo")
|
||||
|
||||
assert.Equal(t, "<nil> DBG jaeger_test.go:21 > foo\n", buf.String())
|
||||
}
|
||||
|
|
|
@ -1,17 +1,24 @@
|
|||
package logs
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNoLevel(t *testing.T) {
|
||||
out := zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339}
|
||||
buf := bytes.NewBuffer(nil)
|
||||
cwb := zerolog.ConsoleWriter{Out: buf, TimeFormat: time.RFC3339, NoColor: true}
|
||||
|
||||
out := zerolog.MultiLevelWriter(zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339}, cwb)
|
||||
|
||||
logger := NoLevel(zerolog.New(out).With().Caller().Logger(), zerolog.DebugLevel)
|
||||
|
||||
logger.Info().Msg("foo")
|
||||
|
||||
assert.Equal(t, "<nil> INF log_test.go:21 > foo\n", buf.String())
|
||||
}
|
||||
|
|
|
@ -1,17 +1,24 @@
|
|||
package logs
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewLogrusStdWrapper(t *testing.T) {
|
||||
out := zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339}
|
||||
buf := bytes.NewBuffer(nil)
|
||||
cwb := zerolog.ConsoleWriter{Out: buf, TimeFormat: time.RFC3339, NoColor: true}
|
||||
|
||||
out := zerolog.MultiLevelWriter(zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339}, cwb)
|
||||
|
||||
logger := NewLogrusWrapper(zerolog.New(out).With().Caller().Logger())
|
||||
|
||||
logger.Println("foo")
|
||||
|
||||
assert.Equal(t, "<nil> DBG logrus_test.go:21 > foo\n", buf.String())
|
||||
}
|
||||
|
|
|
@ -1,17 +1,24 @@
|
|||
package logs
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewOxyWrapper(t *testing.T) {
|
||||
out := zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339}
|
||||
buf := bytes.NewBuffer(nil)
|
||||
cwb := zerolog.ConsoleWriter{Out: buf, TimeFormat: time.RFC3339, NoColor: true}
|
||||
|
||||
out := zerolog.MultiLevelWriter(zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339}, cwb)
|
||||
|
||||
logger := NewOxyWrapper(zerolog.New(out).With().Caller().Logger())
|
||||
|
||||
logger.Info("foo")
|
||||
|
||||
assert.Equal(t, "<nil> INF oxy_test.go:21 > foo\n", buf.String())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue