mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-05 15:10:59 +00:00
(QOL) Improve test setup for logger, improve test coverage for database (#447)
* Improved test setup for logger, improved test coverage for database * removed some new lines * add new line * removed database config detailS * removed lines * code cleanup
This commit is contained in:
@@ -6,22 +6,24 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/common/convert"
|
||||
)
|
||||
|
||||
var (
|
||||
trueptr = func(b bool) *bool { return &b }(true)
|
||||
falseptr = func(b bool) *bool { return &b }(false)
|
||||
)
|
||||
func TestMain(m *testing.M) {
|
||||
setupTestLoggers()
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func SetupTest() {
|
||||
func setupTestLoggers() {
|
||||
logTest := Config{
|
||||
Enabled: trueptr,
|
||||
Enabled: convert.BoolPtr(true),
|
||||
SubLoggerConfig: SubLoggerConfig{
|
||||
Output: "console",
|
||||
Level: "INFO|WARN|DEBUG|ERROR",
|
||||
},
|
||||
AdvancedSettings: advancedSettings{
|
||||
ShowLogSystemName: trueptr,
|
||||
ShowLogSystemName: convert.BoolPtr(true),
|
||||
Spacer: " | ",
|
||||
TimeStampFormat: timestampFormat,
|
||||
Headers: headers{
|
||||
@@ -46,7 +48,7 @@ func SetupTest() {
|
||||
|
||||
func SetupDisabled() {
|
||||
logTest := Config{
|
||||
Enabled: falseptr,
|
||||
Enabled: convert.BoolPtr(false),
|
||||
}
|
||||
|
||||
GlobalLogConfig = &logTest
|
||||
@@ -55,8 +57,6 @@ func SetupDisabled() {
|
||||
}
|
||||
|
||||
func BenchmarkInfo(b *testing.B) {
|
||||
SetupTest()
|
||||
|
||||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
Info(Global, "Hello this is an info benchmark")
|
||||
@@ -101,8 +101,6 @@ func TestRemoveWriter(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLevel(t *testing.T) {
|
||||
SetupTest()
|
||||
|
||||
_, err := Level("LOG")
|
||||
if err != nil {
|
||||
t.Errorf("Failed to get log %s levels skipping", err)
|
||||
@@ -115,8 +113,6 @@ func TestLevel(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSetLevel(t *testing.T) {
|
||||
SetupTest()
|
||||
|
||||
newLevel, err := SetLevel("LOG", "ERROR")
|
||||
if err != nil {
|
||||
t.Skipf("Failed to get log %s levels skipping", err)
|
||||
@@ -155,7 +151,7 @@ func TestCloseLogger(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestConfigureSubLogger(t *testing.T) {
|
||||
err := configureSubLogger("log", "INFO", os.Stdin)
|
||||
err := configureSubLogger("LOG", "INFO", os.Stdin)
|
||||
if err != nil {
|
||||
t.Skipf("configureSubLogger() returned unexpected error %v", err)
|
||||
}
|
||||
@@ -195,8 +191,6 @@ func BenchmarkInfoDisabled(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkInfof(b *testing.B) {
|
||||
SetupTest()
|
||||
|
||||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
Infof(Global, "Hello this is an infof benchmark %v %v %v\n", n, 1, 2)
|
||||
@@ -204,8 +198,6 @@ func BenchmarkInfof(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkInfoln(b *testing.B) {
|
||||
SetupTest()
|
||||
|
||||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
Infoln(Global, "Hello this is an infoln benchmark")
|
||||
@@ -253,7 +245,6 @@ func TestInfo(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSubLoggerName(t *testing.T) {
|
||||
SetupTest()
|
||||
w := &bytes.Buffer{}
|
||||
registerNewSubLogger("sublogger")
|
||||
logger.newLogEvent("out", "header", "SUBLOGGER", w)
|
||||
|
||||
Reference in New Issue
Block a user