aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/transport/server/server_test.go
blob: b266196cd0cd738e56fc3ab39c93e0802e65b44d (plain) (blame)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package server_test

import (
	"fmt"
	"testing"

	"github.com/src-d/go-git-fixtures"
	"srcd.works/go-git.v4/plumbing/transport"
	"srcd.works/go-git.v4/plumbing/transport/client"
	"srcd.works/go-git.v4/plumbing/transport/server"
	"srcd.works/go-git.v4/storage/filesystem"
	"srcd.works/go-git.v4/storage/memory"

	. "gopkg.in/check.v1"
)

func Test(t *testing.T) { TestingT(t) }

const inprocScheme = "inproc"

type BaseSuite struct {
	fixtures.Suite
	loader       server.MapLoader
	client       transport.Transport
	clientBackup transport.Transport
}

func (s *BaseSuite) SetUpSuite(c *C) {
	s.Suite.SetUpSuite(c)
	s.loader = server.MapLoader{}
	s.client = server.NewServer(s.loader)
	s.clientBackup = client.Protocols[inprocScheme]
	client.Protocols[inprocScheme] = s.client
}

func (s *BaseSuite) TearDownSuite(c *C) {
	if s.clientBackup == nil {
		delete(client.Protocols, inprocScheme)
	} else {
		client.Protocols[inprocScheme] = s.clientBackup
	}
}

func (s *BaseSuite) prepareRepositories(c *C, basic *transport.Endpoint,
	empty *transport.Endpoint, nonExistent *transport.Endpoint) {

	f := fixtures.Basic().One()
	fs := f.DotGit()
	path := fs.Base()
	url := fmt.Sprintf("%s://%s", inprocScheme, path)
	ep, err := transport.NewEndpoint(url)
	c.Assert(err, IsNil)
	*basic = ep
	sto, err := filesystem.NewStorage(fs)
	c.Assert(err, IsNil)
	s.loader[ep] = sto

	path = "/empty.git"
	url = fmt.Sprintf("%s://%s", inprocScheme, path)
	ep, err = transport.NewEndpoint(url)
	c.Assert(err, IsNil)
	*empty = ep
	s.loader[ep] = memory.NewStorage()

	path = "/non-existent.git"
	url = fmt.Sprintf("%s://%s", inprocScheme, path)
	ep, err = transport.NewEndpoint(url)
	c.Assert(err, IsNil)
	*nonExistent = ep
}