util: add tests (#5989)

This commit is contained in:
ᴜɴᴋɴᴡᴏɴ
2020-03-16 01:54:08 +08:00
committed by GitHub
parent 9e9ca66467
commit a4de85dc80
6 changed files with 103 additions and 3 deletions

View File

@@ -10,8 +10,26 @@ import (
"github.com/gogs/git-module"
"github.com/stretchr/testify/assert"
"gogs.io/gogs/internal/errutil"
)
func TestError_NotFound(t *testing.T) {
tests := []struct {
err error
expVal bool
}{
{err: git.ErrSubmoduleNotExist, expVal: true},
{err: git.ErrRevisionNotExist, expVal: true},
{err: git.ErrNoMergeBase, expVal: false},
}
for _, test := range tests {
t.Run("", func(t *testing.T) {
assert.Equal(t, test.expVal, errutil.IsNotFound(NewError(test.err)))
})
}
}
func TestIsErrRevisionNotExist(t *testing.T) {
assert.True(t, IsErrRevisionNotExist(git.ErrRevisionNotExist))
assert.False(t, IsErrRevisionNotExist(os.ErrNotExist))