-43
internal/test/checkers.go
-43
internal/test/checkers.go
···
1
-
package test
2
-
3
-
import (
4
-
"errors"
5
-
"fmt"
6
-
7
-
check "gopkg.in/check.v1"
8
-
)
9
-
10
-
// This check.Checker implementation exists because there's no implementation
11
-
// in the library that compares errors using `errors.Is`. If / when the check
12
-
// library fixes https://github.com/go-check/check/issues/139, this code can
13
-
// likely be removed and replaced with the library implementation.
14
-
//
15
-
// Added in Go 1.13 [https://go.dev/blog/go1.13-errors] `errors.Is` is the
16
-
// best mechanism to use to compare errors that might be wrapped in other
17
-
// errors.
18
-
type errorIsChecker struct {
19
-
*check.CheckerInfo
20
-
}
21
-
22
-
var ErrorIs check.Checker = errorIsChecker{
23
-
&check.CheckerInfo{
24
-
Name: "ErrorIs",
25
-
Params: []string{"obtained", "expected"},
26
-
},
27
-
}
28
-
29
-
func (e errorIsChecker) Check(params []interface{}, names []string) (bool, string) {
30
-
obtained, ok := params[0].(error)
31
-
if !ok {
32
-
return false, "obtained is not an error"
33
-
}
34
-
expected, ok := params[1].(error)
35
-
if !ok {
36
-
return false, "expected is not an error"
37
-
}
38
-
39
-
if !errors.Is(obtained, expected) {
40
-
return false, fmt.Sprintf("obtained: %+v expected: %+v", obtained, expected)
41
-
}
42
-
return true, ""
43
-
}
+43
-36
plumbing/server/loader_test.go
+43
-36
plumbing/server/loader_test.go
···
1
1
package server
2
2
3
3
import (
4
+
"os"
4
5
"os/exec"
5
6
"path/filepath"
7
+
"testing"
6
8
7
9
"github.com/go-git/go-git/v5/plumbing/transport"
8
10
"github.com/go-git/go-git/v5/storage/memory"
9
-
10
-
. "gopkg.in/check.v1"
11
+
"github.com/stretchr/testify/suite"
11
12
)
12
13
13
14
type loaderSuiteRepo struct {
···
17
18
}
18
19
19
20
type LoaderSuite struct {
21
+
suite.Suite
20
22
Repos map[string]loaderSuiteRepo
21
23
}
22
24
23
-
var _ = Suite(&LoaderSuite{
24
-
Repos: map[string]loaderSuiteRepo{
25
-
"repo": {path: "repo.git"},
26
-
"bare": {path: "bare.git", bare: true},
27
-
},
28
-
})
25
+
func TestLoaderSuite(t *testing.T) {
26
+
suite.Run(t,
27
+
&LoaderSuite{
28
+
Repos: map[string]loaderSuiteRepo{
29
+
"repo": {path: "repo.git"},
30
+
"bare": {path: "bare.git", bare: true},
31
+
},
32
+
},
33
+
)
34
+
}
29
35
30
-
func (s *LoaderSuite) SetUpSuite(c *C) {
36
+
func (s *LoaderSuite) SetupSuite() {
31
37
if err := exec.Command("git", "--version").Run(); err != nil {
32
-
c.Skip("git command not found")
38
+
s.T().Skip("git command not found")
33
39
}
34
40
35
-
dir := c.MkDir()
41
+
dir, err := os.MkdirTemp("", "")
42
+
s.NoError(err)
36
43
37
44
for key, repo := range s.Repos {
38
45
repo.path = filepath.Join(dir, repo.path)
39
46
if repo.bare {
40
-
c.Assert(exec.Command("git", "init", "--bare", repo.path).Run(), IsNil)
47
+
s.Nil(exec.Command("git", "init", "--bare", repo.path).Run())
41
48
} else {
42
-
c.Assert(exec.Command("git", "init", repo.path).Run(), IsNil)
49
+
s.Nil(exec.Command("git", "init", repo.path).Run())
43
50
}
44
51
s.Repos[key] = repo
45
52
}
46
53
47
54
}
48
55
49
-
func (s *LoaderSuite) endpoint(c *C, url string) *transport.Endpoint {
56
+
func (s *LoaderSuite) endpoint(url string) *transport.Endpoint {
50
57
ep, err := transport.NewEndpoint(url)
51
-
c.Assert(err, IsNil)
58
+
s.NoError(err)
52
59
return ep
53
60
}
54
61
55
-
func (s *LoaderSuite) TestLoadNonExistent(c *C) {
56
-
sto, err := DefaultLoader.Load(s.endpoint(c, "does-not-exist"))
57
-
c.Assert(err, Equals, transport.ErrRepositoryNotFound)
58
-
c.Assert(sto, IsNil)
62
+
func (s *LoaderSuite) TestLoadNonExistent() {
63
+
sto, err := DefaultLoader.Load(s.endpoint("does-not-exist"))
64
+
s.ErrorIs(err, transport.ErrRepositoryNotFound)
65
+
s.Nil(sto)
59
66
}
60
67
61
-
func (s *LoaderSuite) TestLoadNonExistentIgnoreHost(c *C) {
62
-
sto, err := DefaultLoader.Load(s.endpoint(c, "https://github.com/does-not-exist"))
63
-
c.Assert(err, Equals, transport.ErrRepositoryNotFound)
64
-
c.Assert(sto, IsNil)
68
+
func (s *LoaderSuite) TestLoadNonExistentIgnoreHost() {
69
+
sto, err := DefaultLoader.Load(s.endpoint("https://github.com/does-not-exist"))
70
+
s.ErrorIs(err, transport.ErrRepositoryNotFound)
71
+
s.Nil(sto)
65
72
}
66
73
67
-
func (s *LoaderSuite) TestLoad(c *C) {
68
-
sto, err := DefaultLoader.Load(s.endpoint(c, s.Repos["repo"].path))
69
-
c.Assert(err, IsNil)
70
-
c.Assert(sto, NotNil)
74
+
func (s *LoaderSuite) TestLoad() {
75
+
sto, err := DefaultLoader.Load(s.endpoint(s.Repos["repo"].path))
76
+
s.NoError(err)
77
+
s.NotNil(sto)
71
78
}
72
79
73
-
func (s *LoaderSuite) TestLoadBare(c *C) {
74
-
sto, err := DefaultLoader.Load(s.endpoint(c, s.Repos["bare"].path))
75
-
c.Assert(err, IsNil)
76
-
c.Assert(sto, NotNil)
80
+
func (s *LoaderSuite) TestLoadBare() {
81
+
sto, err := DefaultLoader.Load(s.endpoint(s.Repos["bare"].path))
82
+
s.NoError(err)
83
+
s.NotNil(sto)
77
84
}
78
85
79
-
func (s *LoaderSuite) TestMapLoader(c *C) {
86
+
func (s *LoaderSuite) TestMapLoader() {
80
87
ep, err := transport.NewEndpoint("file://test")
81
88
sto := memory.NewStorage()
82
-
c.Assert(err, IsNil)
89
+
s.NoError(err)
83
90
84
91
loader := MapLoader{ep.String(): sto}
85
92
86
93
ep, err = transport.NewEndpoint("file://test")
87
-
c.Assert(err, IsNil)
94
+
s.NoError(err)
88
95
89
96
loaderSto, err := loader.Load(ep)
90
-
c.Assert(err, IsNil)
91
-
c.Assert(sto, Equals, loaderSto)
97
+
s.NoError(err)
98
+
s.Equal(loaderSto, sto)
92
99
}