-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### Background → when cloning a message we always add a space separator but this is wrong. Only do it sometimes. ### Changes - fix bug ### Testing - added regression tests
- Loading branch information
1 parent
c0c6e4c
commit 9089801
Showing
2 changed files
with
77 additions
and
1 deletion.
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
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,67 @@ | ||
package gerror_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/drshriveer/gtools/gerror" | ||
) | ||
|
||
func TestCloneBase(t *testing.T) { | ||
t.Parallel() | ||
ErrNoMessage := gerror.FactoryOf(&gerror.GError{ | ||
Name: "ErrBase", | ||
Message: "", | ||
Source: "", | ||
}) | ||
|
||
tests := []struct { | ||
description string | ||
input gerror.Error | ||
|
||
expectedName string | ||
expectedMessage string | ||
expectedSource string | ||
expectedDetailTag string | ||
}{ | ||
{ | ||
description: "add message does not include extra white space", | ||
input: ErrNoMessage.Msg("hi! blah"), | ||
expectedName: "ErrBase", | ||
expectedSource: "gerror_test:TestCloneBase", | ||
expectedMessage: "hi! blah", | ||
}, | ||
{ | ||
description: "add message is trimmed", | ||
input: ErrNoMessage.Msg(" hi! blah "), | ||
expectedName: "ErrBase", | ||
expectedSource: "gerror_test:TestCloneBase", | ||
expectedMessage: "hi! blah", | ||
}, | ||
{ | ||
description: "add message is trimmed + chaining", | ||
input: ErrNoMessage.Msg(" hi! blah ").(*gerror.GError).Msg(" \t bye! "), | ||
expectedName: "ErrBase", | ||
expectedSource: "gerror_test:TestCloneBase", | ||
expectedMessage: "hi! blah bye!", | ||
}, | ||
{ | ||
description: "lots of whitespace is trimmed", | ||
input: ErrNoMessage.Msg(" hi! blah \n"), | ||
expectedName: "ErrBase", | ||
expectedSource: "gerror_test:TestCloneBase", | ||
expectedMessage: "hi! blah", | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.description, func(t *testing.T) { | ||
t.Parallel() | ||
assert.Equal(t, test.expectedName, test.input.ErrName()) | ||
assert.Equal(t, test.expectedMessage, test.input.ErrMessage()) | ||
assert.Equal(t, test.expectedSource, test.input.ErrSource()) | ||
assert.Equal(t, test.expectedDetailTag, test.input.ErrDetailTag()) | ||
}) | ||
} | ||
} |