/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/git/tests/test_server.py

  • Committer: Robert Collins
  • Date: 2005-10-19 10:11:57 UTC
  • mfrom: (1185.16.78)
  • mto: This revision was merged to the branch mainline in revision 1470.
  • Revision ID: robertc@robertcollins.net-20051019101157-17438d311e746b4f
mergeĀ fromĀ upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2011-2018 Jelmer Vernooij <jelmer@jelmer.uk>
2
 
#
3
 
# This program is free software; you can redistribute it and/or modify
4
 
# it under the terms of the GNU General Public License as published by
5
 
# the Free Software Foundation; either version 2 of the License, or
6
 
# (at your option) any later version.
7
 
#
8
 
# This program is distributed in the hope that it will be useful,
9
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
# GNU General Public License for more details.
12
 
#
13
 
# You should have received a copy of the GNU General Public License
14
 
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
"""Test for git server."""
18
 
 
19
 
from __future__ import absolute_import
20
 
 
21
 
from dulwich.client import TCPGitClient
22
 
from dulwich.repo import Repo
23
 
import threading
24
 
 
25
 
from ...transport import transport_server_registry
26
 
from ...tests import (
27
 
    TestCase,
28
 
    TestCaseWithTransport,
29
 
    )
30
 
 
31
 
from ..server import (
32
 
    BzrBackend,
33
 
    BzrTCPGitServer,
34
 
    )
35
 
 
36
 
 
37
 
class TestPresent(TestCase):
38
 
 
39
 
    def test_present(self):
40
 
        # Just test that the server is registered.
41
 
        transport_server_registry.get('git')
42
 
 
43
 
 
44
 
class GitServerTestCase(TestCaseWithTransport):
45
 
 
46
 
    def start_server(self, t):
47
 
        backend = BzrBackend(t)
48
 
        server = BzrTCPGitServer(backend, 'localhost', port=0)
49
 
        self.addCleanup(server.shutdown)
50
 
        thread = threading.Thread(target=server.serve).start()
51
 
        self._server = server
52
 
        _, port = self._server.socket.getsockname()
53
 
        return port
54
 
 
55
 
 
56
 
class TestPlainFetch(GitServerTestCase):
57
 
 
58
 
    def test_fetch_from_native_git(self):
59
 
        wt = self.make_branch_and_tree('t', format='git')
60
 
        self.build_tree(['t/foo'])
61
 
        wt.add('foo')
62
 
        revid = wt.commit(message="some data")
63
 
        wt.branch.tags.set_tag("atag", revid)
64
 
        t = self.get_transport('t')
65
 
        port = self.start_server(t)
66
 
        c = TCPGitClient('localhost', port=port)
67
 
        gitrepo = Repo.init('gitrepo', mkdir=True)
68
 
        result = c.fetch('/', gitrepo)
69
 
        self.assertEqual(
70
 
            set(result.refs.keys()),
71
 
            set([b"refs/tags/atag", b'refs/heads/master', b"HEAD"]))
72
 
 
73
 
    def test_fetch_nothing(self):
74
 
        wt = self.make_branch_and_tree('t')
75
 
        self.build_tree(['t/foo'])
76
 
        wt.add('foo')
77
 
        revid = wt.commit(message="some data")
78
 
        wt.branch.tags.set_tag("atag", revid)
79
 
        t = self.get_transport('t')
80
 
        port = self.start_server(t)
81
 
        c = TCPGitClient('localhost', port=port)
82
 
        gitrepo = Repo.init('gitrepo', mkdir=True)
83
 
        result = c.fetch('/', gitrepo, determine_wants=lambda x: [])
84
 
        self.assertEqual(
85
 
            set(result.refs.keys()),
86
 
            set([b"refs/tags/atag", b"HEAD"]))
87
 
 
88
 
    def test_fetch_from_non_git(self):
89
 
        wt = self.make_branch_and_tree('t', format='bzr')
90
 
        self.build_tree(['t/foo'])
91
 
        wt.add('foo')
92
 
        revid = wt.commit(message="some data")
93
 
        wt.branch.tags.set_tag("atag", revid)
94
 
        t = self.get_transport('t')
95
 
        port = self.start_server(t)
96
 
        c = TCPGitClient('localhost', port=port)
97
 
        gitrepo = Repo.init('gitrepo', mkdir=True)
98
 
        result = c.fetch('/', gitrepo)
99
 
        self.assertEqual(
100
 
            set(result.refs.keys()),
101
 
            set([b"refs/tags/atag", b"HEAD"]))