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