2022-11-23 10:42:04 +00:00
|
|
|
package logs
|
|
|
|
|
|
|
|
import (
|
2022-11-23 11:14:04 +00:00
|
|
|
"bytes"
|
2022-11-23 10:42:04 +00:00
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/rs/zerolog"
|
2022-11-23 11:14:04 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2022-11-23 10:42:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewRetryableHTTPLogger(t *testing.T) {
|
2022-11-23 11:14:04 +00:00
|
|
|
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)
|
2022-11-23 10:42:04 +00:00
|
|
|
|
|
|
|
logger := NewRetryableHTTPLogger(zerolog.New(out).With().Caller().Logger())
|
|
|
|
|
|
|
|
logger.Info("foo")
|
2022-11-23 11:14:04 +00:00
|
|
|
|
|
|
|
assert.Equal(t, "<nil> INF hclog_test.go:21 > Foo\n", buf.String())
|
2022-11-23 10:42:04 +00:00
|
|
|
}
|