aboutsummaryrefslogtreecommitdiff
path: root/internal/gitutil/error_test.go
blob: 331751f1ce2f6c95ea43ded205285185a33cb236 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2020 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package gitutil

import (
	"os"
	"testing"

	"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))
}

func TestIsErrNoMergeBase(t *testing.T) {
	assert.True(t, IsErrNoMergeBase(git.ErrNoMergeBase))
	assert.False(t, IsErrNoMergeBase(os.ErrNotExist))
}