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