diff --git a/ChangeLog b/ChangeLog index 4b8271662..16a5eda05 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2008-09-10 Michal Ludvig + + * testsuite, run-tests.py: Added testsuite with first few tests. + 2008-09-10 Michal Ludvig * s3cmd, S3/S3Uri.py, S3/S3.py: All internal representations of diff --git a/run-tests.py b/run-tests.py new file mode 100755 index 000000000..7ab28b83c --- /dev/null +++ b/run-tests.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python + +## Amazon S3cmd - testsuite +## Author: Michal Ludvig +## http://www.logix.cz/michal +## License: GPL Version 2 + +import sys +import re +from subprocess import Popen, PIPE, STDOUT + +count_pass = 0 +count_fail = 0 + +def test(label, cmd_args = [], retcode = 0, must_find = [], must_not_find = [], must_find_re = [], must_not_find_re = []): + def failure(message = ""): + global count_fail + if message: + message = " (%s)" % message + print "FAIL%s" % (message) + count_fail += 1 + print "----" + print " ".join([arg.find(" ")>=0 and "'%s'" % arg or arg for arg in cmd_args]) + print "----" + print stdout + print "----" + return 1 + def success(message = ""): + global count_pass + if message: + message = " (%s)" % message + print "OK%s" % (message) + count_pass += 1 + return 0 + def compile_list(_list, regexps = False): + if type(_list) not in [ list, tuple ]: + _list = [_list] + + if regexps == False: + _list = [re.escape(item) for item in _list] + + return [re.compile(item) for item in _list] + + print (label + " ").ljust(30, "."), + sys.stdout.flush() + + p = Popen(cmd_args, stdout = PIPE, stderr = STDOUT, universal_newlines = True) + stdout, stderr = p.communicate() + if retcode != p.returncode: + return failure("retcode: %d, expected: %d" % (p.returncode, retcode)) + + find_list = [] + find_list.extend(compile_list(must_find)) + find_list.extend(compile_list(must_find_re, regexps = True)) + not_find_list = [] + not_find_list.extend(compile_list(must_not_find)) + not_find_list.extend(compile_list(must_not_find_re, regexps = True)) + + for pattern in find_list: + match = pattern.search(stdout) + if not match: + return failure("pattern not found: %s" % match.group()) + for pattern in not_find_list: + match = pattern.search(stdout) + if match: + return failure("pattern found: %s" % match.group()) + return success() + +def test_s3cmd(label, cmd_args = [], **kwargs): + if not cmd_args[0].endswith("s3cmd"): + cmd_args.insert(0, "./s3cmd") + return test(label, cmd_args, **kwargs) + +test_s3cmd("Remove test buckets", ['rb', '-r', 's3://s3cmd-autotest-1', 's3://s3cmd-autotest-2', 's3://s3cmd-autotest-3'], + must_find = [ "Bucket 's3://s3cmd-autotest-1/' removed", + "Bucket 's3://s3cmd-autotest-2/' removed", + "Bucket 's3://s3cmd-autotest-3/' removed" ]) + +test_s3cmd("Create one bucket", ['mb', 's3://s3cmd-autotest-1'], + must_find = "Bucket 's3://s3cmd-autotest-1/' created") + +test_s3cmd("Create multiple buckets", ['mb', 's3://s3cmd-autotest-2', 's3://s3cmd-autotest-3'], + must_find = [ "Bucket 's3://s3cmd-autotest-2/' created", "Bucket 's3://s3cmd-autotest-3/' created" ]) + +test_s3cmd("Invalid bucket name", ["mb", "s3://s3cmd-Autotest-.-"], + retcode = 1, + must_find = "ERROR: Parameter problem: Bucket name", + must_not_find_re = "Bucket.*created") + +test_s3cmd("Buckets list", ["ls"], + must_find = [ "autotest-1", "autotest-2", "autotest-3" ], must_not_find_re = "Autotest") + +test_s3cmd("Sync with exclude", ['sync', 'testsuite', 's3://s3cmd-autotest-1/xyz/', '--exclude', '*/thousands/*', '--no-encrypt']) diff --git a/run-tests.sh b/run-tests.sh index 855c5a877..9fc23567c 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -25,18 +25,13 @@ rm -f s3cmd-${VER}/file.to.remove ./s3cmd sync --delete s3cmd-${VER} s3://s3cmd-autotest/sync-test rm -f s3cmd-${VER}/S3/PkgInfo.py rm -f s3cmd-${VER}/s3cmd -./s3cmd sync --delete --exclude "/s3cmd-${VER}/S3/*" s3://s3cmd-autotest/sync-test s3cmd-${VER} +./s3cmd sync --delete --exclude "/s3cmd-${VER}/S3/S3*" s3://s3cmd-autotest/sync-test s3cmd-${VER} rm -rf s3cmd-${VER} ./s3cmd rb s3://s3cmd-autotest/ || true # ERROR: S3 error: 409 (Conflict): BucketNotEmpty -# hack to remove all objects from a bucket -mkdir empty -./s3cmd sync --delete empty/ s3://s3cmd-autotest -rm -rf empty - -./s3cmd rb s3://s3cmd-autotest/ +./s3cmd rb --force s3://s3cmd-autotest/ set +x diff --git a/testsuite/binary/random-crap b/testsuite/binary/random-crap new file mode 100644 index 000000000..d24db3a35 Binary files /dev/null and b/testsuite/binary/random-crap differ diff --git a/testsuite/binary/random-crap.md5 b/testsuite/binary/random-crap.md5 new file mode 100644 index 000000000..f870fb14a --- /dev/null +++ b/testsuite/binary/random-crap.md5 @@ -0,0 +1 @@ +cb76ecee9a834eadd96b226493acac28 random-crap diff --git "a/testsuite/unicode/\305\252\305\206\320\207\320\214\305\223\304\221\320\227/\305\275\305\257\305\276o" "b/testsuite/unicode/\305\252\305\206\320\207\320\214\305\223\304\221\320\227/\305\275\305\257\305\276o" new file mode 100644 index 000000000..e69de29bb diff --git "a/testsuite/unicode/\305\252\305\206\320\207\320\214\305\223\304\221\320\227/\342\230\272 unicode \342\202\254 rocks \342\204\242" "b/testsuite/unicode/\305\252\305\206\320\207\320\214\305\223\304\221\320\227/\342\230\272 unicode \342\202\254 rocks \342\204\242" new file mode 100644 index 000000000..2dda3860f --- /dev/null +++ "b/testsuite/unicode/\305\252\305\206\320\207\320\214\305\223\304\221\320\227/\342\230\272 unicode \342\202\254 rocks \342\204\242" @@ -0,0 +1 @@ +☺ unicode € rocks ™ diff --git "a/testsuite/unicode/\305\275\305\257\305\276o" "b/testsuite/unicode/\305\275\305\257\305\276o" new file mode 100644 index 000000000..c39ac154e --- /dev/null +++ "b/testsuite/unicode/\305\275\305\257\305\276o" @@ -0,0 +1 @@ +Žůžo