chore: test coverage improvement (#240)

* chore: improves channel functions test coverage

* chore: improves errors functions test coverage

* chore: improves map functions test coverage

* chore: improves parallel slice functions test coverage

* chore: improves slice functions test coverage

* fix: uses atomic counter on parallel/slice_test

* Update channel_test.go

Co-authored-by: Samuel Berthe <dev@samuel-berthe.fr>
This commit is contained in:
VictorAssunc
2022-10-22 14:05:07 -03:00
committed by GitHub
parent 3206009698
commit 640e00c286
5 changed files with 155 additions and 20 deletions

View File

@@ -53,6 +53,13 @@ func TestMust(t *testing.T) {
is.PanicsWithValue("operation should fail: assert.AnError general error for testing", func() {
Must0(cb(), "operation should fail")
})
is.PanicsWithValue("must: invalid err type 'int', should either be a bool or an error", func() {
Must0(0)
})
is.PanicsWithValue("must: invalid err type 'string', should either be a bool or an error", func() {
Must0("error")
})
}
func TestMustX(t *testing.T) {
@@ -264,7 +271,11 @@ func TestTry(t *testing.T) {
func TestTryX(t *testing.T) {
t.Parallel()
is := assert.New(t)
is.True(Try1(func() error {
return nil
}))
is.True(Try2(func() (string, error) {
return "", nil
}))
@@ -284,7 +295,11 @@ func TestTryX(t *testing.T) {
is.True(Try6(func() (string, string, string, string, string, error) {
return "", "", "", "", "", nil
}))
is.False(Try1(func() error {
panic("error")
}))
is.False(Try2(func() (string, error) {
panic("error")
}))
@@ -304,7 +319,11 @@ func TestTryX(t *testing.T) {
is.False(Try6(func() (string, string, string, string, string, error) {
panic("error")
}))
is.False(Try1(func() error {
return errors.New("foo")
}))
is.False(Try2(func() (string, error) {
return "", errors.New("foo")
}))
@@ -489,11 +508,18 @@ func TestTryWithErrorValue(t *testing.T) {
is := assert.New(t)
err, ok := TryWithErrorValue(func() error {
// getting error in case of panic, using recover function
panic("error")
})
is.False(ok)
is.Equal("error", err)
err, ok = TryWithErrorValue(func() error {
return errors.New("foo")
})
is.False(ok)
is.EqualError(err.(error), "foo")
err, ok = TryWithErrorValue(func() error {
return nil
})