-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increase coverage for Sub's methods to 50 percent.
- Loading branch information
1 parent
8d870aa
commit cc6a77f
Showing
2 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.idea | ||
*.iml | ||
coverage.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |