1 import sys, os, stat, time, random, subprocess, glob
2 from bup import client, git
8 s += chr(random.randrange(0,256))
18 def test_server_split_with_indexes():
19 os.environ['BUP_MAIN_EXE'] = '../../../bup'
20 os.environ['BUP_DIR'] = bupdir = 'buptest_tclient.tmp'
21 subprocess.call(['rm', '-rf', bupdir])
24 c = client.Client(bupdir, create=True)
25 rw = c.new_packwriter()
36 def test_multiple_suggestions():
37 os.environ['BUP_MAIN_EXE'] = '../../../bup'
38 os.environ['BUP_DIR'] = bupdir = 'buptest_tclient.tmp'
39 subprocess.call(['rm', '-rf', bupdir])
48 WVPASSEQ(len(glob.glob(git.repo('objects/pack'+IDX_PAT))), 2)
50 c = client.Client(bupdir, create=True)
51 WVPASSEQ(len(glob.glob(c.cachedir+IDX_PAT)), 0)
52 rw = c.new_packwriter()
53 s1sha = rw.new_blob(s1)
54 WVPASS(rw.exists(s1sha))
55 s2sha = rw.new_blob(s2)
56 # This is a little hacky, but ensures that we test the code under test
57 while (len(glob.glob(c.cachedir+IDX_PAT)) < 2 and
58 not c.conn.has_input()):
61 WVPASS(rw.objcache.exists(s1sha))
62 WVPASS(rw.objcache.exists(s2sha))
64 WVPASSEQ(len(glob.glob(c.cachedir+IDX_PAT)), 2)
66 WVPASSEQ(len(glob.glob(c.cachedir+IDX_PAT)), 3)
70 def test_dumb_client_server():
71 os.environ['BUP_MAIN_EXE'] = '../../../bup'
72 os.environ['BUP_DIR'] = bupdir = 'buptest_tclient.tmp'
73 subprocess.call(['rm', '-rf', bupdir])
75 open(git.repo('bup-dumb-server'), 'w').close()
81 c = client.Client(bupdir, create=True)
82 rw = c.new_packwriter()
83 WVPASSEQ(len(glob.glob(c.cachedir+IDX_PAT)), 1)
85 WVPASSEQ(len(glob.glob(c.cachedir+IDX_PAT)), 1)
88 WVPASSEQ(len(glob.glob(c.cachedir+IDX_PAT)), 2)
92 def test_midx_refreshing():
93 os.environ['BUP_MAIN_EXE'] = bupmain = '../../../bup'
94 os.environ['BUP_DIR'] = bupdir = 'buptest_tmidx.tmp'
95 subprocess.call(['rm', '-rf', bupdir])
97 c = client.Client(bupdir, create=True)
98 rw = c.new_packwriter()
100 p1base = rw.breakpoint()
101 p1name = os.path.join(c.cachedir, p1base)
102 s1sha = rw.new_blob(s1) # should not be written; it's already in p1
103 s2sha = rw.new_blob(s2)
105 p2name = os.path.join(c.cachedir, p2base)
108 pi = git.PackIdxList(bupdir + '/objects/pack')
109 WVPASSEQ(len(pi.packs), 2)
111 WVPASSEQ(len(pi.packs), 2)
112 WVPASSEQ(sorted([os.path.basename(i.name) for i in pi.packs]),
113 sorted([p1base, p2base]))
115 p1 = git.open_idx(p1name)
116 WVPASS(p1.exists(s1sha))
117 p2 = git.open_idx(p2name)
118 WVFAIL(p2.exists(s1sha))
119 WVPASS(p2.exists(s2sha))
121 subprocess.call([bupmain, 'midx', '-f'])
123 WVPASSEQ(len(pi.packs), 1)
124 pi.refresh(skip_midx=True)
125 WVPASSEQ(len(pi.packs), 2)
126 pi.refresh(skip_midx=False)
127 WVPASSEQ(len(pi.packs), 1)
131 def test_remote_parsing():
133 (':/bup', ('file', None, None, '/bup')),
134 ('file:///bup', ('file', None, None, '/bup')),
135 ('192.168.1.1:/bup', ('ssh', '192.168.1.1', None, '/bup')),
136 ('ssh://192.168.1.1:2222/bup', ('ssh', '192.168.1.1', '2222', '/bup')),
137 ('ssh://[ff:fe::1]:2222/bup', ('ssh', 'ff:fe::1', '2222', '/bup')),
138 ('bup://foo.com:1950', ('bup', 'foo.com', '1950', None)),
139 ('bup://foo.com:1950/bup', ('bup', 'foo.com', '1950', '/bup')),
140 ('bup://[ff:fe::1]/bup', ('bup', 'ff:fe::1', None, '/bup')),
142 for remote, values in tests:
143 WVPASSEQ(client.parse_remote(remote), values)
145 client.parse_remote('http://asdf.com/bup')
147 except client.ClientError: