]> arthur.barton.de Git - bup.git/blob - t/test-ftp
c71bc54be79f512560b1a6d416bfc2d145e3e8b1
[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 absolute_import, print_function
9 from os import environ, chdir, mkdir, symlink, unlink
10 from os.path import abspath, dirname
11 from subprocess import PIPE
12 from time import localtime, strftime
13 import os, sys
14
15 script_home = abspath(dirname(sys.argv[0] or '.'))
16 sys.path[:0] = [abspath(script_home + '/../lib'), abspath(script_home + '/..')]
17 top = os.getcwd()
18 bup_cmd = top + '/bup'
19
20 from buptest import ex, exo, logcmd, test_tempdir
21 from wvtest import wvfail, wvpass, wvpasseq, wvpassne, wvstart
22
23 from bup.helpers import unlink as unlink_if_exists
24
25 def bup(*args, **kwargs):
26     if 'stdout' not in kwargs:
27         return exo((bup_cmd,) + args, **kwargs)
28     return ex((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     bup('init')
56     bup('index', 'src')
57     bup('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', stderr=PIPE).err)
64
65     wvstart('pwd/cd')
66     wvpasseq('/\n', bup('ftp', input='pwd\n').out)
67     wvpasseq('', bup('ftp', input='cd src\n').out)
68     wvpasseq('/src\n', bup('ftp', input=jl('cd src', 'pwd')).out)
69     wvpasseq('/src\n/\n', bup('ftp', input=jl('cd src', 'pwd',
70                                               'cd ..', 'pwd')).out)
71     wvpasseq('/src\n/\n', bup('ftp', input=jl('cd src', 'pwd',
72                                               'cd ..', 'cd ..', 'pwd')).out)
73     wvpasseq('/src/latest/dir\n',
74              bup('ftp', input=jl('cd src/latest/dir-symlink', 'pwd')).out)
75     wvpasseq('/src/latest/dir\n',
76              bup('ftp', input=jl('cd src latest dir-symlink', 'pwd')).out)
77     wvpassne(0, bup('ftp',
78                     input=jl('cd src/latest/bad-symlink', 'pwd'),
79                     check=False, stdout=None).rc)
80     wvpassne(0, bup('ftp',
81                     input=jl('cd src/latest/not-there', 'pwd'),
82                     check=False, stdout=None).rc)
83
84     wvstart('ls')
85     # FIXME: elaborate
86     wvpasseq('src\n', bup('ftp', input='ls\n').out)
87     wvpasseq(save_name + '\nlatest\n',
88              bup('ftp', input='ls src\n').out)
89
90     wvstart('cat')
91     wvpasseq('excitement!\n',
92              bup('ftp', input='cat src/latest/file-1\n').out)
93     wvpasseq('excitement!\nmore excitement!\n',
94              bup('ftp',
95                  input='cat src/latest/file-1 src/latest/dir/file-2\n').out)
96     
97     wvstart('get')
98     bup('ftp', input=jl('get src/latest/file-1 dest'))
99     with open('dest', 'rb') as f:
100         wvpasseq('excitement!\n', f.read())
101     unlink('dest')
102     bup('ftp', input=jl('get src/latest/file-symlink dest'))
103     with open('dest', 'rb') as f:
104         wvpasseq('excitement!\n', f.read())
105     unlink('dest')
106     wvpassne(0, bup('ftp',
107                     input=jl('get src/latest/bad-symlink dest'),
108                     check=False, stdout=None).rc)
109     wvpassne(0, bup('ftp',
110                     input=jl('get src/latest/not-there'),
111                     check=False, stdout=None).rc)
112     
113     wvstart('mget')
114     unlink_if_exists('file-1')
115     bup('ftp', input=jl('mget src/latest/file-1'))
116     with open('file-1', 'rb') as f:
117         wvpasseq('excitement!\n', f.read())
118     unlink_if_exists('file-1')
119     unlink_if_exists('file-2')
120     bup('ftp', input=jl('mget src/latest/file-1 src/latest/dir/file-2'))
121     with open('file-1', 'rb') as f:
122         wvpasseq('excitement!\n', f.read())
123     with open('file-2', 'rb') as f:
124         wvpasseq('more excitement!\n', f.read())
125     unlink_if_exists('file-symlink')
126     bup('ftp', input=jl('mget src/latest/file-symlink'))
127     with open('file-symlink', 'rb') as f:
128         wvpasseq('excitement!\n', f.read())
129     wvpassne(0, bup('ftp',
130                     input=jl('mget src/latest/bad-symlink dest'),
131                     check=False, stdout=None).rc)
132     # bup mget currently always does pattern matching
133     bup('ftp', input='mget src/latest/not-there\n')