]> arthur.barton.de Git - bup.git/blob - t/test-ftp
Split src tree python use to config/bin/python and dev/bup-python
[bup.git] / t / test-ftp
1 #!/bin/sh
2 """": # -*-python-*-
3 bup_python="$(dirname "$0")/../dev/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 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 # For buptest, wvtest, ...
16 sys.path[:0] = (abspath(os.path.dirname(__file__) + '/..'),)
17 sys.path[:0] = [os.path.dirname(os.path.realpath(__file__)) + '/../lib']
18
19 from buptest import ex, exo, logcmd, test_tempdir
20 from wvtest import wvfail, wvpass, wvpasseq, wvpassne, wvstart
21
22 from bup.compat import environ
23 from bup.helpers import unlink as unlink_if_exists
24 import bup.path
25
26 bup_cmd = bup.path.exe()
27
28 def bup(*args, **kwargs):
29     if 'stdout' not in kwargs:
30         return exo((bup_cmd,) + args, **kwargs)
31     return ex((bup_cmd,) + args, **kwargs)
32
33 def jl(*lines):
34     return b''.join(line + b'\n' for line in lines)
35
36 environ[b'GIT_AUTHOR_NAME'] = b'bup test'
37 environ[b'GIT_COMMITTER_NAME'] = b'bup test'
38 environ[b'GIT_AUTHOR_EMAIL'] = b'bup@a425bc70a02811e49bdf73ee56450e6f'
39 environ[b'GIT_COMMITTER_EMAIL'] = b'bup@a425bc70a02811e49bdf73ee56450e6f'
40
41 with test_tempdir(b'ftp-') as tmpdir:
42     environ[b'BUP_DIR'] = tmpdir + b'/repo'
43     environ[b'GIT_DIR'] = tmpdir + b'/repo'
44
45     chdir(tmpdir)
46     mkdir(b'src')
47     chdir(b'src')
48     mkdir(b'dir')
49     with open(b'file-1', 'wb') as f:
50         f.write(b'excitement!\n')
51     with open(b'dir/file-2', 'wb') as f:
52         f.write(b'more excitement!\n')
53     symlink(b'file-1', b'file-symlink')
54     symlink(b'dir', b'dir-symlink')
55     symlink(b'not-there', b'bad-symlink')
56
57     chdir(tmpdir)    
58     bup(b'init')
59     bup(b'index', b'src')
60     bup(b'save', b'-n', b'src', b'--strip', b'src')
61     save_utc = int(exo((b'git', b'show',
62                         b'-s', b'--format=%at', b'src')).out.strip())
63     save_name = strftime('%Y-%m-%d-%H%M%S', localtime(save_utc)).encode('ascii')
64     
65     wvstart('help')
66     wvpasseq(b'Commands: ls cd pwd cat get mget help quit\n',
67              exo((bup_cmd, b'ftp'), input=b'help\n', stderr=PIPE).out)
68
69     wvstart('pwd/cd')
70     wvpasseq(b'/\n', bup(b'ftp', input=b'pwd\n').out)
71     wvpasseq(b'', bup(b'ftp', input=b'cd src\n').out)
72     wvpasseq(b'/src\n', bup(b'ftp', input=jl(b'cd src', b'pwd')).out)
73     wvpasseq(b'/src\n/\n', bup(b'ftp', input=jl(b'cd src', b'pwd',
74                                                 b'cd ..', b'pwd')).out)
75     wvpasseq(b'/src\n/\n', bup(b'ftp', input=jl(b'cd src', b'pwd',
76                                                 b'cd ..', b'cd ..',
77                                                 b'pwd')).out)
78     wvpasseq(b'/src/%s/dir\n' % save_name,
79              bup(b'ftp', input=jl(b'cd src/latest/dir-symlink', b'pwd')).out)
80     wvpasseq(b'/src/%s/dir\n' % save_name,
81              bup(b'ftp', input=jl(b'cd src latest dir-symlink', b'pwd')).out)
82     wvpassne(0, bup(b'ftp',
83                     input=jl(b'cd src/latest/bad-symlink', b'pwd'),
84                     check=False, stdout=None).rc)
85     wvpassne(0, bup(b'ftp',
86                     input=jl(b'cd src/latest/not-there', b'pwd'),
87                     check=False, stdout=None).rc)
88
89     wvstart('ls')
90     # FIXME: elaborate
91     wvpasseq(b'src\n', bup(b'ftp', input=b'ls\n').out)
92     wvpasseq(save_name + b'\nlatest\n',
93              bup(b'ftp', input=b'ls src\n').out)
94
95     wvstart('cat')
96     wvpasseq(b'excitement!\n',
97              bup(b'ftp', input=b'cat src/latest/file-1\n').out)
98     wvpasseq(b'excitement!\nmore excitement!\n',
99              bup(b'ftp',
100                  input=b'cat src/latest/file-1 src/latest/dir/file-2\n').out)
101     
102     wvstart('get')
103     bup(b'ftp', input=jl(b'get src/latest/file-1 dest'))
104     with open(b'dest', 'rb') as f:
105         wvpasseq(b'excitement!\n', f.read())
106     unlink(b'dest')
107     bup(b'ftp', input=jl(b'get src/latest/file-symlink dest'))
108     with open(b'dest', 'rb') as f:
109         wvpasseq(b'excitement!\n', f.read())
110     unlink(b'dest')
111     wvpassne(0, bup(b'ftp',
112                     input=jl(b'get src/latest/bad-symlink dest'),
113                     check=False, stdout=None).rc)
114     wvpassne(0, bup(b'ftp',
115                     input=jl(b'get src/latest/not-there'),
116                     check=False, stdout=None).rc)
117     
118     wvstart('mget')
119     unlink_if_exists(b'file-1')
120     bup(b'ftp', input=jl(b'mget src/latest/file-1'))
121     with open(b'file-1', 'rb') as f:
122         wvpasseq(b'excitement!\n', f.read())
123     unlink_if_exists(b'file-1')
124     unlink_if_exists(b'file-2')
125     bup(b'ftp', input=jl(b'mget src/latest/file-1 src/latest/dir/file-2'))
126     with open(b'file-1', 'rb') as f:
127         wvpasseq(b'excitement!\n', f.read())
128     with open(b'file-2', 'rb') as f:
129         wvpasseq(b'more excitement!\n', f.read())
130     unlink_if_exists(b'file-symlink')
131     bup(b'ftp', input=jl(b'mget src/latest/file-symlink'))
132     with open(b'file-symlink', 'rb') as f:
133         wvpasseq(b'excitement!\n', f.read())
134     wvpassne(0, bup(b'ftp',
135                     input=jl(b'mget src/latest/bad-symlink dest'),
136                     check=False, stdout=None).rc)
137     # bup mget currently always does pattern matching
138     bup(b'ftp', input=b'mget src/latest/not-there\n')