2
0

error_test.go 1014 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2020 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package gitutil
  5. import (
  6. "os"
  7. "testing"
  8. "github.com/gogs/git-module"
  9. "github.com/stretchr/testify/assert"
  10. "gogs.io/gogs/internal/errutil"
  11. )
  12. func TestError_NotFound(t *testing.T) {
  13. tests := []struct {
  14. err error
  15. expVal bool
  16. }{
  17. {err: git.ErrSubmoduleNotExist, expVal: true},
  18. {err: git.ErrRevisionNotExist, expVal: true},
  19. {err: git.ErrNoMergeBase, expVal: false},
  20. }
  21. for _, test := range tests {
  22. t.Run("", func(t *testing.T) {
  23. assert.Equal(t, test.expVal, errutil.IsNotFound(NewError(test.err)))
  24. })
  25. }
  26. }
  27. func TestIsErrRevisionNotExist(t *testing.T) {
  28. assert.True(t, IsErrRevisionNotExist(git.ErrRevisionNotExist))
  29. assert.False(t, IsErrRevisionNotExist(os.ErrNotExist))
  30. }
  31. func TestIsErrNoMergeBase(t *testing.T) {
  32. assert.True(t, IsErrNoMergeBase(git.ErrNoMergeBase))
  33. assert.False(t, IsErrNoMergeBase(os.ErrNotExist))
  34. }