Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 94 lines (76 sloc) 3.073 kb
330c51e @mludvig * testsuite, run-tests.py: Added testsuite with first few tests.
mludvig authored
1 #!/usr/bin/env python
2
3 ## Amazon S3cmd - testsuite
4 ## Author: Michal Ludvig <michal@logix.cz>
5 ## http://www.logix.cz/michal
6 ## License: GPL Version 2
7
8 import sys
9 import re
10 from subprocess import Popen, PIPE, STDOUT
11
12 count_pass = 0
13 count_fail = 0
14
15 def test(label, cmd_args = [], retcode = 0, must_find = [], must_not_find = [], must_find_re = [], must_not_find_re = []):
16 def failure(message = ""):
17 global count_fail
18 if message:
19 message = " (%s)" % message
20 print "FAIL%s" % (message)
21 count_fail += 1
22 print "----"
23 print " ".join([arg.find(" ")>=0 and "'%s'" % arg or arg for arg in cmd_args])
24 print "----"
25 print stdout
26 print "----"
27 return 1
28 def success(message = ""):
29 global count_pass
30 if message:
31 message = " (%s)" % message
32 print "OK%s" % (message)
33 count_pass += 1
34 return 0
35 def compile_list(_list, regexps = False):
36 if type(_list) not in [ list, tuple ]:
37 _list = [_list]
38
39 if regexps == False:
40 _list = [re.escape(item) for item in _list]
41
42 return [re.compile(item) for item in _list]
43
44 print (label + " ").ljust(30, "."),
45 sys.stdout.flush()
46
47 p = Popen(cmd_args, stdout = PIPE, stderr = STDOUT, universal_newlines = True)
48 stdout, stderr = p.communicate()
49 if retcode != p.returncode:
50 return failure("retcode: %d, expected: %d" % (p.returncode, retcode))
51
52 find_list = []
53 find_list.extend(compile_list(must_find))
54 find_list.extend(compile_list(must_find_re, regexps = True))
55 not_find_list = []
56 not_find_list.extend(compile_list(must_not_find))
57 not_find_list.extend(compile_list(must_not_find_re, regexps = True))
58
59 for pattern in find_list:
60 match = pattern.search(stdout)
61 if not match:
62 return failure("pattern not found: %s" % match.group())
63 for pattern in not_find_list:
64 match = pattern.search(stdout)
65 if match:
66 return failure("pattern found: %s" % match.group())
67 return success()
68
69 def test_s3cmd(label, cmd_args = [], **kwargs):
70 if not cmd_args[0].endswith("s3cmd"):
71 cmd_args.insert(0, "./s3cmd")
72 return test(label, cmd_args, **kwargs)
73
74 test_s3cmd("Remove test buckets", ['rb', '-r', 's3://s3cmd-autotest-1', 's3://s3cmd-autotest-2', 's3://s3cmd-autotest-3'],
75 must_find = [ "Bucket 's3://s3cmd-autotest-1/' removed",
76 "Bucket 's3://s3cmd-autotest-2/' removed",
77 "Bucket 's3://s3cmd-autotest-3/' removed" ])
78
79 test_s3cmd("Create one bucket", ['mb', 's3://s3cmd-autotest-1'],
80 must_find = "Bucket 's3://s3cmd-autotest-1/' created")
81
82 test_s3cmd("Create multiple buckets", ['mb', 's3://s3cmd-autotest-2', 's3://s3cmd-autotest-3'],
83 must_find = [ "Bucket 's3://s3cmd-autotest-2/' created", "Bucket 's3://s3cmd-autotest-3/' created" ])
84
85 test_s3cmd("Invalid bucket name", ["mb", "s3://s3cmd-Autotest-.-"],
86 retcode = 1,
87 must_find = "ERROR: Parameter problem: Bucket name",
88 must_not_find_re = "Bucket.*created")
89
90 test_s3cmd("Buckets list", ["ls"],
91 must_find = [ "autotest-1", "autotest-2", "autotest-3" ], must_not_find_re = "Autotest")
92
93 test_s3cmd("Sync with exclude", ['sync', 'testsuite', 's3://s3cmd-autotest-1/xyz/', '--exclude', '*/thousands/*', '--no-encrypt'])
Something went wrong with that request. Please try again.