2 import sys, os, stat, time, random, subprocess, glob
6 from bup import client, git
7 from bup.helpers import mkdirp
8 from buptest import no_lingering_errors, test_tempdir
14 s += chr(random.randrange(0,256))
26 def test_server_split_with_indexes():
27 with no_lingering_errors(), test_tempdir('bup-tclient-') as tmpdir:
28 os.environ['BUP_MAIN_EXE'] = '../../../bup'
29 os.environ['BUP_DIR'] = bupdir = tmpdir
32 c = client.Client(bupdir, create=True)
33 rw = c.new_packwriter()
45 def test_multiple_suggestions():
46 with no_lingering_errors(), test_tempdir('bup-tclient-') as tmpdir:
47 os.environ['BUP_MAIN_EXE'] = '../../../bup'
48 os.environ['BUP_DIR'] = bupdir = tmpdir
57 WVPASSEQ(len(glob.glob(git.repo('objects/pack'+IDX_PAT))), 2)
59 c = client.Client(bupdir, create=True)
60 WVPASSEQ(len(glob.glob(c.cachedir+IDX_PAT)), 0)
61 rw = c.new_packwriter()
62 s1sha = rw.new_blob(s1)
63 WVPASS(rw.exists(s1sha))
64 s2sha = rw.new_blob(s2)
65 # This is a little hacky, but ensures that we test the code under test
66 while (len(glob.glob(c.cachedir+IDX_PAT)) < 2 and
67 not c.conn.has_input()):
70 WVPASS(rw.objcache.exists(s1sha))
71 WVPASS(rw.objcache.exists(s2sha))
73 WVPASSEQ(len(glob.glob(c.cachedir+IDX_PAT)), 2)
75 WVPASSEQ(len(glob.glob(c.cachedir+IDX_PAT)), 3)
79 def test_dumb_client_server():
80 with no_lingering_errors(), test_tempdir('bup-tclient-') as tmpdir:
81 os.environ['BUP_MAIN_EXE'] = '../../../bup'
82 os.environ['BUP_DIR'] = bupdir = tmpdir
84 open(git.repo('bup-dumb-server'), 'w').close()
90 c = client.Client(bupdir, create=True)
91 rw = c.new_packwriter()
92 WVPASSEQ(len(glob.glob(c.cachedir+IDX_PAT)), 1)
94 WVPASSEQ(len(glob.glob(c.cachedir+IDX_PAT)), 1)
97 WVPASSEQ(len(glob.glob(c.cachedir+IDX_PAT)), 2)
101 def test_midx_refreshing():
102 with no_lingering_errors(), test_tempdir('bup-tclient-') as tmpdir:
103 os.environ['BUP_MAIN_EXE'] = bupmain = '../../../bup'
104 os.environ['BUP_DIR'] = bupdir = tmpdir
105 git.init_repo(bupdir)
106 c = client.Client(bupdir, create=True)
107 rw = c.new_packwriter()
109 p1base = rw.breakpoint()
110 p1name = os.path.join(c.cachedir, p1base)
111 s1sha = rw.new_blob(s1) # should not be written; it's already in p1
112 s2sha = rw.new_blob(s2)
114 p2name = os.path.join(c.cachedir, p2base)
117 pi = git.PackIdxList(bupdir + '/objects/pack')
118 WVPASSEQ(len(pi.packs), 2)
120 WVPASSEQ(len(pi.packs), 2)
121 WVPASSEQ(sorted([os.path.basename(i.name) for i in pi.packs]),
122 sorted([p1base, p2base]))
124 p1 = git.open_idx(p1name)
125 WVPASS(p1.exists(s1sha))
126 p2 = git.open_idx(p2name)
127 WVFAIL(p2.exists(s1sha))
128 WVPASS(p2.exists(s2sha))
130 subprocess.call([bupmain, 'midx', '-f'])
132 WVPASSEQ(len(pi.packs), 1)
133 pi.refresh(skip_midx=True)
134 WVPASSEQ(len(pi.packs), 2)
135 pi.refresh(skip_midx=False)
136 WVPASSEQ(len(pi.packs), 1)
140 def test_remote_parsing():
141 with no_lingering_errors():
143 (':/bup', ('file', None, None, '/bup')),
144 ('file:///bup', ('file', None, None, '/bup')),
145 ('192.168.1.1:/bup', ('ssh', '192.168.1.1', None, '/bup')),
146 ('ssh://192.168.1.1:2222/bup', ('ssh', '192.168.1.1', '2222', '/bup')),
147 ('ssh://[ff:fe::1]:2222/bup', ('ssh', 'ff:fe::1', '2222', '/bup')),
148 ('bup://foo.com:1950', ('bup', 'foo.com', '1950', None)),
149 ('bup://foo.com:1950/bup', ('bup', 'foo.com', '1950', '/bup')),
150 ('bup://[ff:fe::1]/bup', ('bup', 'ff:fe::1', None, '/bup')),)
151 for remote, values in tests:
152 WVPASSEQ(client.parse_remote(remote), values)
154 client.parse_remote('http://asdf.com/bup')
156 except client.ClientError: