git-svn-id: https://s3tools.svn.sourceforge.net/svnroot/s3tools/s3cmd/trunk@278 830e0280-6d2a-0410-9c65-932aecc39d9d
Michal Ludvig authored on 2008/11/30 23:15:13... | ... |
@@ -1,4 +1,5 @@ |
1 | 1 |
#!/usr/bin/env python |
2 |
+# -*- coding=utf-8 -*- |
|
2 | 3 |
|
3 | 4 |
## Amazon S3cmd - testsuite |
4 | 5 |
## Author: Michal Ludvig <michal@logix.cz> |
... | ... |
@@ -17,7 +18,7 @@ def test(label, cmd_args = [], retcode = 0, must_find = [], must_not_find = [], |
17 | 17 |
global count_fail |
18 | 18 |
if message: |
19 | 19 |
message = " (%s)" % message |
20 |
- print "FAIL%s" % (message) |
|
20 |
+ print "\x1b[31;1mFAIL%s\x1b[0m" % (message) |
|
21 | 21 |
count_fail += 1 |
22 | 22 |
print "----" |
23 | 23 |
print " ".join([arg.find(" ")>=0 and "'%s'" % arg or arg for arg in cmd_args]) |
... | ... |
@@ -29,7 +30,7 @@ def test(label, cmd_args = [], retcode = 0, must_find = [], must_not_find = [], |
29 | 29 |
global count_pass |
30 | 30 |
if message: |
31 | 31 |
message = " (%s)" % message |
32 |
- print "OK%s" % (message) |
|
32 |
+ print "\x1b[32;1mOK\x1b[0m%s" % (message) |
|
33 | 33 |
count_pass += 1 |
34 | 34 |
return 0 |
35 | 35 |
def compile_list(_list, regexps = False): |
... | ... |
@@ -37,7 +38,7 @@ def test(label, cmd_args = [], retcode = 0, must_find = [], must_not_find = [], |
37 | 37 |
_list = [_list] |
38 | 38 |
|
39 | 39 |
if regexps == False: |
40 |
- _list = [re.escape(item) for item in _list] |
|
40 |
+ _list = [re.escape(item.encode("utf-8")) for item in _list] |
|
41 | 41 |
|
42 | 42 |
return [re.compile(item) for item in _list] |
43 | 43 |
|
... | ... |
@@ -52,18 +53,25 @@ def test(label, cmd_args = [], retcode = 0, must_find = [], must_not_find = [], |
52 | 52 |
find_list = [] |
53 | 53 |
find_list.extend(compile_list(must_find)) |
54 | 54 |
find_list.extend(compile_list(must_find_re, regexps = True)) |
55 |
+ find_list_patterns = [] |
|
56 |
+ find_list_patterns.extend(must_find) |
|
57 |
+ find_list_patterns.extend(must_find_re) |
|
58 |
+ |
|
55 | 59 |
not_find_list = [] |
56 | 60 |
not_find_list.extend(compile_list(must_not_find)) |
57 | 61 |
not_find_list.extend(compile_list(must_not_find_re, regexps = True)) |
62 |
+ not_find_list_patterns = [] |
|
63 |
+ not_find_list_patterns.extend(must_not_find) |
|
64 |
+ not_find_list_patterns.extend(must_not_find_re) |
|
58 | 65 |
|
59 |
- for pattern in find_list: |
|
60 |
- match = pattern.search(stdout) |
|
66 |
+ for index in range(len(find_list)): |
|
67 |
+ match = find_list[index].search(stdout) |
|
61 | 68 |
if not match: |
62 |
- return failure("pattern not found: %s" % match.group()) |
|
63 |
- for pattern in not_find_list: |
|
64 |
- match = pattern.search(stdout) |
|
69 |
+ return failure("pattern not found: %s" % find_list_patterns[index]) |
|
70 |
+ for index in range(len(not_find_list)): |
|
71 |
+ match = not_find_list[index].search(stdout) |
|
65 | 72 |
if match: |
66 |
- return failure("pattern found: %s" % match.group()) |
|
73 |
+ return failure("pattern found: %s (match: %s)" % (not_find_list_patterns[index], match.group(0))) |
|
67 | 74 |
return success() |
68 | 75 |
|
69 | 76 |
def test_s3cmd(label, cmd_args = [], **kwargs): |
... | ... |
@@ -71,23 +79,74 @@ def test_s3cmd(label, cmd_args = [], **kwargs): |
71 | 71 |
cmd_args.insert(0, "./s3cmd") |
72 | 72 |
return test(label, cmd_args, **kwargs) |
73 | 73 |
|
74 |
-test_s3cmd("Remove test buckets", ['rb', '-r', 's3://s3cmd-autotest-1', 's3://s3cmd-autotest-2', 's3://s3cmd-autotest-3'], |
|
74 |
+test_s3cmd("Remove test buckets", ['rb', '-r', 's3://s3cmd-autotest-1', 's3://s3cmd-autotest-2', 's3://s3cmd-Autotest-3'], |
|
75 | 75 |
must_find = [ "Bucket 's3://s3cmd-autotest-1/' removed", |
76 | 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'], |
|
77 |
+ "Bucket 's3://s3cmd-Autotest-3/' removed" ]) |
|
78 |
+ |
|
79 |
+test_s3cmd("Create one bucket (EU)", ['mb', '--bucket-location=EU', 's3://s3cmd-autotest-1'], |
|
80 | 80 |
must_find = "Bucket 's3://s3cmd-autotest-1/' created") |
81 | 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" ]) |
|
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 | 84 |
|
85 |
-test_s3cmd("Invalid bucket name", ["mb", "s3://s3cmd-Autotest-.-"], |
|
85 |
+test_s3cmd("Invalid bucket name", ["mb", "--bucket-location=EU", "s3://s3cmd-Autotest-EU"], |
|
86 | 86 |
retcode = 1, |
87 |
- must_find = "ERROR: Parameter problem: Bucket name", |
|
87 |
+ must_find = "ERROR: Parameter problem: Bucket name 's3cmd-Autotest-EU' contains disallowed character", |
|
88 | 88 |
must_not_find_re = "Bucket.*created") |
89 | 89 |
|
90 | 90 |
test_s3cmd("Buckets list", ["ls"], |
91 |
- must_find = [ "autotest-1", "autotest-2", "autotest-3" ], must_not_find_re = "Autotest") |
|
91 |
+ must_find = [ "autotest-1", "autotest-2", "Autotest-3" ], must_not_find_re = "Autotest-EU") |
|
92 |
+ |
|
93 |
+test_s3cmd("Sync to S3", ['sync', 'testsuite', 's3://s3cmd-autotest-1/xyz/', '--exclude', '.svn/*', '--exclude', '*.png', '--no-encrypt']) |
|
94 |
+ |
|
95 |
+test_s3cmd("Check bucket content", ['ls', 's3://s3cmd-autotest-1'], |
|
96 |
+ must_find = [ u"s3://s3cmd-autotest-1/xyz/unicode/ŪņЇЌœđЗ/☺ unicode € rocks ™" ], |
|
97 |
+ must_not_find = [ "logo.png" ]) |
|
98 |
+ |
|
99 |
+# test_s3cmd("Recursive put", ['put', '--recursive', 'testsuite/etc', 's3://s3cmd-autotest-1/xyz/']) |
|
100 |
+ |
|
101 |
+test_s3cmd("Put public, guess MIME", ['put', '--guess-mime-type', '--acl-public', 'testsuite/etc/logo.png', 's3://s3cmd-autotest-1/xyz/etc/logo.png'], |
|
102 |
+ must_find = [ "stored as s3://s3cmd-autotest-1/xyz/etc/logo.png" ]) |
|
103 |
+ |
|
104 |
+test("Removing local target", ['rm', '-rf', 'testsuite-out']) |
|
105 |
+ |
|
106 |
+test_s3cmd("Sync from S3", ['sync', 's3://s3cmd-autotest-1/xyz', 'testsuite-out'], |
|
107 |
+ must_find = [ "stored as testsuite-out/etc/logo.png ", u"unicode/ŪņЇЌœđЗ/☺ unicode € rocks ™" ]) |
|
108 |
+ |
|
109 |
+test("Retrieve public URL", ['wget', 'http://s3cmd-autotest-1.s3.amazonaws.com/xyz/etc/logo.png'], |
|
110 |
+ must_find_re = [ 'logo.png.*saved \[22059/22059\]' ]) |
|
111 |
+ |
|
112 |
+test_s3cmd("Sync more to S3", ['sync', 'testsuite', 's3://s3cmd-autotest-1/xyz/', '--exclude', '*.png', '--no-encrypt']) |
|
113 |
+ |
|
114 |
+test_s3cmd("Rename within S3", ['mv', 's3://s3cmd-autotest-1/xyz/etc/logo.png', 's3://s3cmd-autotest-1/xyz/etc2/Logo.PNG'], |
|
115 |
+ must_find = [ 'Object s3://s3cmd-autotest-1/xyz/etc/logo.png moved to s3://s3cmd-autotest-1/xyz/etc2/Logo.PNG' ]) |
|
116 |
+ |
|
117 |
+test_s3cmd("Rename (NoSuchKey)", ['mv', 's3://s3cmd-autotest-1/xyz/etc/logo.png', 's3://s3cmd-autotest-1/xyz/etc2/Logo.PNG'], |
|
118 |
+ retcode = 1, |
|
119 |
+ must_find_re = [ 'ERROR:.*NoSuchKey' ], |
|
120 |
+ must_not_find = [ 'Object s3://s3cmd-autotest-1/xyz/etc/logo.png moved to s3://s3cmd-autotest-1/xyz/etc2/Logo.PNG' ]) |
|
121 |
+ |
|
122 |
+test_s3cmd("Sync more from S3", ['sync', '--delete-removed', 's3://s3cmd-autotest-1/xyz', 'testsuite-out'], |
|
123 |
+ must_find = [ "deleted 'testsuite-out/etc/logo.png'", "stored as testsuite-out/etc2/Logo.PNG (22059 bytes", |
|
124 |
+ "stored as testsuite-out/.svn/format " ], |
|
125 |
+ must_not_find = [ "not-deleted etc/logo.png" ]) |
|
126 |
+ |
|
127 |
+test_s3cmd("Copy between buckets", ['cp', 's3://s3cmd-autotest-1/xyz/etc2/Logo.PNG', 's3://s3cmd-Autotest-3'], |
|
128 |
+ must_find = [ "Object s3://s3cmd-autotest-1/xyz/etc2/Logo.PNG copied to s3://s3cmd-Autotest-3/xyz/etc2/Logo.PNG" ]) |
|
129 |
+ |
|
130 |
+test_s3cmd("Simple delete", ['del', 's3://s3cmd-autotest-1/xyz/etc2/Logo.PNG'], |
|
131 |
+ must_find = [ "Object s3://s3cmd-autotest-1/xyz/etc2/Logo.PNG deleted" ]) |
|
132 |
+ |
|
133 |
+test_s3cmd("Recursive delete", ['del', '--recursive', 's3://s3cmd-autotest-1/xyz/unicode'], |
|
134 |
+ must_find_re = [ "Object.*unicode/ŪņЇЌœđЗ/.*deleted" ]) |
|
135 |
+ |
|
136 |
+test_s3cmd("Recursive delete all", ['del', '--recursive', '--force', 's3://s3cmd-autotest-1'], |
|
137 |
+ must_find_re = [ "Object.*binary/random-crap deleted" ]) |
|
138 |
+ |
|
139 |
+test_s3cmd("Remove empty bucket", ['rb', 's3://s3cmd-autotest-1'], |
|
140 |
+ must_find = [ "Bucket 's3://s3cmd-autotest-1/' removed" ]) |
|
92 | 141 |
|
93 |
-test_s3cmd("Sync with exclude", ['sync', 'testsuite', 's3://s3cmd-autotest-1/xyz/', '--exclude', '*/thousands/*', '--no-encrypt']) |
|
142 |
+test_s3cmd("Remove remaining buckets", ['rb', '--recursive', 's3://s3cmd-autotest-2', 's3://s3cmd-Autotest-3'], |
|
143 |
+ must_find = [ "Bucket 's3://s3cmd-autotest-2/' removed", |
|
144 |
+ "Bucket 's3://s3cmd-Autotest-3/' removed" ]) |