Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase coverage for Sub's methods to 50 percent. #47

Merged
merged 1 commit into from
Sep 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea
*.iml
coverage.txt
92 changes: 92 additions & 0 deletions sub_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package xop

import (
"errors"
"github.com/muir/xop-go/xopnum"
"github.com/stretchr/testify/assert"
"testing"
"time"
)

func TestLog_Settings(t *testing.T) {
defaultLog := Default
logSettings := defaultLog.Settings()
assert.Equal(t, DefaultSettings, logSettings)
}

func TestSub_StackFrames(t *testing.T) {
sub := Default.Sub()
sub.StackFrames(xopnum.DebugLevel, 100)
sub.StackFrames(xopnum.ErrorLevel, 100)
sub.StackFrames(xopnum.TraceLevel, 2)
assert.Equal(t, 100, sub.settings.stackFramesWanted[xopnum.ErrorLevel])
assert.Equal(t, 100, sub.settings.stackFramesWanted[xopnum.AlertLevel])
assert.Equal(t, 2, sub.settings.stackFramesWanted[xopnum.TraceLevel])
assert.Equal(t, 2, sub.settings.stackFramesWanted[xopnum.DebugLevel])
}

func TestSub_SynchronousFlush(t *testing.T) {
sub := Default.Sub()
sub.SynchronousFlush(true)
assert.True(t, sub.settings.synchronousFlushWhenDone)
sub.SynchronousFlush(false)
assert.False(t, sub.settings.synchronousFlushWhenDone)
}

func TestSub_MinLevel(t *testing.T) {
sub := Default.Sub()
sub.MinLevel(xopnum.ErrorLevel)
assert.Equal(t, xopnum.ErrorLevel, sub.settings.minimumLogLevel)
}

func TestSub_TagLinesWithSpanSequence(t *testing.T) {
sub := Default.Sub()
sub.TagLinesWithSpanSequence(true)
assert.True(t, sub.settings.tagLinesWithSpanSequence)
sub.TagLinesWithSpanSequence(false)
assert.False(t, sub.settings.tagLinesWithSpanSequence)
}

func TestSub_PrefillText(t *testing.T) {
sub := Default.Sub()
assert.Empty(t, sub.settings.prefillMsg)
sub.PrefillText("text")
assert.Equal(t, "text", sub.settings.prefillMsg)
}

func TestSub_NoPrefill(t *testing.T) {
sub := Default.Sub()
assert.Nil(t, sub.settings.prefillData)
assert.Empty(t, sub.settings.prefillMsg)
sub.PrefillAny("foo", "bar")
sub.PrefillText("text")
assert.NotNil(t, sub.settings.prefillData)
assert.NotEmpty(t, sub.settings.prefillMsg)
sub.NoPrefill()
assert.Nil(t, sub.settings.prefillData)
assert.Empty(t, sub.settings.prefillMsg)
}

func TestSub_PrefillBool(t *testing.T) {
sub := Default.Sub()
sub.PrefillBool("key", true)
assert.Len(t, sub.settings.prefillData, 1)
}

func TestSub_PrefillDuration(t *testing.T) {
sub := Default.Sub()
sub.PrefillDuration("key", 1*time.Second)
assert.Len(t, sub.settings.prefillData, 1)
}

func TestSub_PrefillError(t *testing.T) {
sub := Default.Sub()
sub.PrefillError("key", errors.New("error"))
assert.Len(t, sub.settings.prefillData, 1)
}

func TestSub_PrefillFloat64(t *testing.T) {
sub := Default.Sub()
sub.PrefillFloat64("key", 64)
assert.Len(t, sub.settings.prefillData, 1)
}