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():
28 with test_tempdir('bup-tclient-') as tmpdir:
29 os.environ['BUP_MAIN_EXE'] = '../../../bup'
30 os.environ['BUP_DIR'] = bupdir = tmpdir
33 c = client.Client(bupdir, create=True)
34 rw = c.new_packwriter()
46 def test_multiple_suggestions():
47 with no_lingering_errors():
48 with test_tempdir('bup-tclient-') as tmpdir:
49 os.environ['BUP_MAIN_EXE'] = '../../../bup'
50 os.environ['BUP_DIR'] = bupdir = tmpdir
59 WVPASSEQ(len(glob.glob(git.repo('objects/pack'+IDX_PAT))), 2)
61 c = client.Client(bupdir, create=True)
62 WVPASSEQ(len(glob.glob(c.cachedir+IDX_PAT)), 0)
63 rw = c.new_packwriter()
64 s1sha = rw.new_blob(s1)
65 WVPASS(rw.exists(s1sha))
66 s2sha = rw.new_blob(s2)
67 # This is a little hacky, but ensures that we test the
69 while (len(glob.glob(c.cachedir+IDX_PAT)) < 2 and
70 not c.conn.has_input()):
73 WVPASS(rw.objcache.exists(s1sha))
74 WVPASS(rw.objcache.exists(s2sha))
76 WVPASSEQ(len(glob.glob(c.cachedir+IDX_PAT)), 2)
78 WVPASSEQ(len(glob.glob(c.cachedir+IDX_PAT)), 3)
82 def test_dumb_client_server():
83 with no_lingering_errors():
84 with test_tempdir('bup-tclient-') as tmpdir:
85 os.environ['BUP_MAIN_EXE'] = '../../../bup'
86 os.environ['BUP_DIR'] = bupdir = tmpdir
88 open(git.repo('bup-dumb-server'), 'w').close()
94 c = client.Client(bupdir, create=True)
95 rw = c.new_packwriter()
96 WVPASSEQ(len(glob.glob(c.cachedir+IDX_PAT)), 1)
98 WVPASSEQ(len(glob.glob(c.cachedir+IDX_PAT)), 1)
101 WVPASSEQ(len(glob.glob(c.cachedir+IDX_PAT)), 2)
105 def test_midx_refreshing():
106 with no_lingering_errors():
107 with test_tempdir('bup-tclient-') as tmpdir:
108 os.environ['BUP_MAIN_EXE'] = bupmain = '../../../bup'
109 os.environ['BUP_DIR'] = bupdir = tmpdir
110 git.init_repo(bupdir)
111 c = client.Client(bupdir, create=True)
112 rw = c.new_packwriter()
114 p1base = rw.breakpoint()
115 p1name = os.path.join(c.cachedir, p1base)
116 s1sha = rw.new_blob(s1) # should not be written; it's already in p1
117 s2sha = rw.new_blob(s2)
119 p2name = os.path.join(c.cachedir, p2base)
122 pi = git.PackIdxList(bupdir + '/objects/pack')
123 WVPASSEQ(len(pi.packs), 2)
125 WVPASSEQ(len(pi.packs), 2)
126 WVPASSEQ(sorted([os.path.basename(i.name) for i in pi.packs]),
127 sorted([p1base, p2base]))
129 p1 = git.open_idx(p1name)
130 WVPASS(p1.exists(s1sha))
131 p2 = git.open_idx(p2name)
132 WVFAIL(p2.exists(s1sha))
133 WVPASS(p2.exists(s2sha))
135 subprocess.call([bupmain, 'midx', '-f'])
137 WVPASSEQ(len(pi.packs), 1)
138 pi.refresh(skip_midx=True)
139 WVPASSEQ(len(pi.packs), 2)
140 pi.refresh(skip_midx=False)
141 WVPASSEQ(len(pi.packs), 1)
145 def test_remote_parsing():
146 with no_lingering_errors():
148 (':/bup', ('file', None, None, '/bup')),
149 ('file:///bup', ('file', None, None, '/bup')),
150 ('192.168.1.1:/bup', ('ssh', '192.168.1.1', None, '/bup')),
151 ('ssh://192.168.1.1:2222/bup', ('ssh', '192.168.1.1', '2222', '/bup')),
152 ('ssh://[ff:fe::1]:2222/bup', ('ssh', 'ff:fe::1', '2222', '/bup')),
153 ('bup://foo.com:1950', ('bup', 'foo.com', '1950', None)),
154 ('bup://foo.com:1950/bup', ('bup', 'foo.com', '1950', '/bup')),
155 ('bup://[ff:fe::1]/bup', ('bup', 'ff:fe::1', None, '/bup')),)
156 for remote, values in tests:
157 WVPASSEQ(client.parse_remote(remote), values)
159 client.parse_remote('http://asdf.com/bup')
161 except client.ClientError: