]> arthur.barton.de Git - bup.git/blob - t/test-ftp
62c81c150c8b92afcf363703df47627ff488c231
[bup.git] / t / test-ftp
1 #!/bin/sh
2 """": # -*-python-*-
3 bup_python="$(dirname "$0")/../cmd/bup-python" || exit $?
4 exec "$bup_python" "$0" ${1+"$@"}
5 """
6 # end of bup preamble
7
8 from __future__ import print_function
9 from os import environ, chdir, mkdir, symlink, unlink
10 from os.path import abspath, dirname
11 from time import localtime, strftime
12 import os, sys
13
14 script_home = abspath(dirname(sys.argv[0] or '.'))
15 sys.path[:0] = [abspath(script_home + '/../lib'), abspath(script_home + '/..')]
16 top = os.getcwd()
17 bup_cmd = top + '/bup'
18
19 from buptest import exc, exo, logcmd, test_tempdir
20 from wvtest import wvfail, wvpass, wvpasseq, wvpassne, wvstart
21
22 from bup.helpers import unlink as unlink_if_exists
23
24 def bup(*args, **kwargs):
25     return exo((bup_cmd,) + args, **kwargs)[0]
26
27 def bupc(*args, **kwargs):
28     return exc((bup_cmd,) + args, **kwargs)
29
30 def jl(*lines):
31     return ''.join(line + '\n' for line in lines)
32
33 environ['GIT_AUTHOR_NAME'] = 'bup test'
34 environ['GIT_COMMITTER_NAME'] = 'bup test'
35 environ['GIT_AUTHOR_EMAIL'] = 'bup@a425bc70a02811e49bdf73ee56450e6f'
36 environ['GIT_COMMITTER_EMAIL'] = 'bup@a425bc70a02811e49bdf73ee56450e6f'
37
38 with test_tempdir('ftp-') as tmpdir:
39     environ['BUP_DIR'] = tmpdir + '/repo'
40     environ['GIT_DIR'] = tmpdir + '/repo'
41
42     chdir(tmpdir)
43     mkdir('src')
44     chdir('src')
45     mkdir('dir')
46     with open('file-1', 'wb') as f:
47         print('excitement!', file=f)
48     with open('dir/file-2', 'wb') as f:
49         print('more excitement!', file=f)
50     symlink('file-1', 'file-symlink')
51     symlink('dir', 'dir-symlink')
52     symlink('not-there', 'bad-symlink')
53
54     chdir(tmpdir)    
55     bupc('init')
56     bupc('index', 'src')
57     bupc('save', '-n', 'src', '--strip', 'src')
58     save_utc = int(exo(('git', 'show', '-s', '--format=%at', 'src')).out.strip())
59     save_name = strftime('%Y-%m-%d-%H%M%S', localtime(save_utc))
60     
61     wvstart('help')
62     wvpasseq('Commands: ls cd pwd cat get mget help quit\n',
63              exo((bup_cmd, 'ftp'), input='help\n').err)
64
65     wvstart('pwd/cd')
66     wvpasseq('/\n', bup('ftp', input='pwd\n'))
67     wvpasseq('', bup('ftp', input='cd src\n'))
68     wvpasseq('/src\n', bup('ftp', input=jl('cd src', 'pwd')))
69     wvpasseq('/src\n/\n', bup('ftp', input=jl('cd src', 'pwd', 'cd ..', 'pwd')))
70     wvpasseq('/src\n/\n', bup('ftp', input=jl('cd src', 'pwd',
71                                               'cd ..', 'cd ..', 'pwd')))
72     wvpasseq('/src/latest/dir\n',
73              bup('ftp', input=jl('cd src/latest/dir-symlink', 'pwd')))
74     wvpasseq('/src/latest/dir\n',
75              bup('ftp', input=jl('cd src latest dir-symlink', 'pwd')))
76     wvpassne(0, bupc('ftp',
77                      input=jl('cd src/latest/bad-symlink', 'pwd'),
78                      check=False).rc)
79     wvpassne(0, bupc('ftp',
80                      input=jl('cd src/latest/not-there', 'pwd'),
81                      check=False).rc)
82
83     wvstart('ls')
84     # FIXME: elaborate
85     wvpasseq('src\n', bup('ftp', input='ls\n'))
86     wvpasseq(save_name + '\nlatest\n',
87              bup('ftp', input='ls src\n'))
88
89     wvstart('cat')
90     wvpasseq('excitement!\n',
91              bup('ftp', input='cat src/latest/file-1\n'))
92     wvpasseq('excitement!\nmore excitement!\n',
93              bup('ftp', input='cat src/latest/file-1 src/latest/dir/file-2\n'))
94     
95     wvstart('get')
96     bupc('ftp', input=jl('get src/latest/file-1 dest'))
97     with open('dest', 'rb') as f:
98         wvpasseq('excitement!\n', f.read())
99     unlink('dest')
100     bupc('ftp', input=jl('get src/latest/file-symlink dest'))
101     with open('dest', 'rb') as f:
102         wvpasseq('excitement!\n', f.read())
103     unlink('dest')
104     wvpassne(0, bupc('ftp',
105                      input=jl('get src/latest/bad-symlink dest'),
106                      check=False).rc)
107     wvpassne(0, bupc('ftp',
108                      input=jl('get src/latest/not-there'),
109                      check=False).rc)
110     
111     wvstart('mget')
112     unlink_if_exists('file-1')
113     bupc('ftp', input=jl('mget src/latest/file-1'))
114     with open('file-1', 'rb') as f:
115         wvpasseq('excitement!\n', f.read())
116     unlink_if_exists('file-1')
117     unlink_if_exists('file-2')
118     bupc('ftp', input=jl('mget src/latest/file-1 src/latest/dir/file-2'))
119     with open('file-1', 'rb') as f:
120         wvpasseq('excitement!\n', f.read())
121     with open('file-2', 'rb') as f:
122         wvpasseq('more excitement!\n', f.read())
123     unlink_if_exists('file-symlink')
124     bupc('ftp', input=jl('mget src/latest/file-symlink'))
125     with open('file-symlink', 'rb') as f:
126         wvpasseq('excitement!\n', f.read())
127     wvpassne(0, bupc('ftp',
128                      input=jl('mget src/latest/bad-symlink dest'),
129                      check=False).rc)
130     # bup mget currently always does pattern matching
131     bupc('ftp', input='mget src/latest/not-there\n')