diff options
Diffstat (limited to 'src/fs/test_gnunet_fs_rec.py.in')
-rwxr-xr-x | src/fs/test_gnunet_fs_rec.py.in | 152 |
1 files changed, 76 insertions, 76 deletions
diff --git a/src/fs/test_gnunet_fs_rec.py.in b/src/fs/test_gnunet_fs_rec.py.in index 3828a65c9..99850232b 100755 --- a/src/fs/test_gnunet_fs_rec.py.in +++ b/src/fs/test_gnunet_fs_rec.py.in | |||
@@ -2,20 +2,18 @@ | |||
2 | # This file is part of GNUnet. | 2 | # This file is part of GNUnet. |
3 | # (C) 2010 Christian Grothoff (and other contributing authors) | 3 | # (C) 2010 Christian Grothoff (and other contributing authors) |
4 | # | 4 | # |
5 | # GNUnet is free software; you can redistribute it and/or modify | 5 | # GNUnet is free software: you can redistribute it and/or modify it |
6 | # it under the terms of the GNU General Public License as published | 6 | # under the terms of the GNU Affero General Public License as published |
7 | # by the Free Software Foundation; either version 2, or (at your | 7 | # by the Free Software Foundation, either version 3 of the License, |
8 | # option) any later version. | 8 | # or (at your option) any later version. |
9 | # | 9 | # |
10 | # GNUnet is distributed in the hope that it will be useful, but | 10 | # GNUnet is distributed in the hope that it will be useful, but |
11 | # WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | # WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | # General Public License for more details. | 13 | # Affero General Public License for more details. |
14 | # | 14 | # |
15 | # You should have received a copy of the GNU General Public License | 15 | # You should have received a copy of the GNU Affero General Public License |
16 | # along with GNUnet; see the file COPYING. If not, write to the | 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | # Boston, MA 02110-1301, USA. | ||
19 | # | 17 | # |
20 | # Testcase for file-sharing command-line tools (recursive publishing & download) | 18 | # Testcase for file-sharing command-line tools (recursive publishing & download) |
21 | import sys | 19 | import sys |
@@ -27,88 +25,90 @@ import tarfile | |||
27 | import filecmp | 25 | import filecmp |
28 | 26 | ||
29 | srcdir = "../.." | 27 | srcdir = "../.." |
30 | gnunet_pyexpect_dir = os.path.join (srcdir, "contrib") | 28 | gnunet_pyexpect_dir = os.path.join(srcdir, "contrib/scripts") |
31 | if gnunet_pyexpect_dir not in sys.path: | 29 | if gnunet_pyexpect_dir not in sys.path: |
32 | sys.path.append (gnunet_pyexpect_dir) | 30 | sys.path.append(gnunet_pyexpect_dir) |
33 | 31 | ||
34 | from gnunet_pyexpect import pexpect | 32 | from gnunet_pyexpect import pexpect |
35 | from pydiffer import dcdiff | 33 | from pydiffer import dcdiff |
36 | 34 | ||
37 | if os.name == 'posix': | 35 | if os.name == 'posix': |
38 | download = './gnunet-download' | 36 | download = './gnunet-download' |
39 | gnunetarm = 'gnunet-arm' | 37 | gnunetarm = 'gnunet-arm' |
40 | publish = './gnunet-publish' | 38 | publish = './gnunet-publish' |
41 | unindex = './gnunet-unindex' | 39 | unindex = './gnunet-unindex' |
42 | search = './gnunet-search' | 40 | search = './gnunet-search' |
43 | directory = './gnunet-directory' | 41 | directory = './gnunet-directory' |
44 | elif os.name == 'nt': | 42 | elif os.name == 'nt': |
45 | download = './gnunet-download.exe' | 43 | download = './gnunet-download.exe' |
46 | gnunetarm = 'gnunet-arm.exe' | 44 | gnunetarm = 'gnunet-arm.exe' |
47 | publish = './gnunet-publish.exe' | 45 | publish = './gnunet-publish.exe' |
48 | unindex = './gnunet-unindex.exe' | 46 | unindex = './gnunet-unindex.exe' |
49 | search = './gnunet-search.exe' | 47 | search = './gnunet-search.exe' |
50 | directory = './gnunet-directory.exe' | 48 | directory = './gnunet-directory.exe' |
51 | 49 | ||
52 | if os.name == "nt": | 50 | if os.name == "nt": |
53 | shutil.rmtree (os.path.join (os.getenv ("TEMP"), "gnunet-test-fs-py-rec"), True) | 51 | shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-rec"), True) |
54 | else: | 52 | else: |
55 | shutil.rmtree ("/tmp/gnunet-test-fs-py-rec", True) | 53 | shutil.rmtree("/tmp/gnunet-test-fs-py-rec", True) |
56 | 54 | ||
57 | arm = subprocess.Popen ([gnunetarm, '-sq', '-c', 'test_gnunet_fs_rec_data.conf']) | 55 | arm = subprocess.Popen([gnunetarm, '-sq', '-c', 'test_gnunet_fs_rec_data.conf']) |
58 | arm.communicate () | 56 | arm.communicate() |
59 | 57 | ||
60 | # pray that `tar' is in PATH | 58 | # pray that `tar' is in PATH. |
61 | tar = tarfile.open ('test_gnunet_fs_rec_data.tgz') | 59 | # FIXME: Actually we should check for that and output |
62 | tar.extractall () | 60 | # a message if it isn't found. |
61 | tar = tarfile.open('test_gnunet_fs_rec_data.tgz') | ||
62 | tar.extractall() | ||
63 | # first, basic publish-search-download run | 63 | # first, basic publish-search-download run |
64 | try: | 64 | try: |
65 | pub = pexpect () | 65 | pub = pexpect() |
66 | pub.spawn (None, [publish, '-c', 'test_gnunet_fs_rec_data.conf', '-d', '-k', 'testdir', 'dir/'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 66 | pub.spawn(None, [publish, '-c', 'test_gnunet_fs_rec_data.conf', '-d', '-k', 'testdir', 'dir/'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
67 | # Can't say much for publishing, except that the last one is the toplevel directory | 67 | # Can't say much for publishing, except that the last one is the toplevel directory |
68 | pub.expect ("stdout", re.compile (r"Publishing `.+' done\.\r?\n")) | 68 | pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n")) |
69 | pub.expect ("stdout", re.compile (r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) | 69 | pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) |
70 | pub.expect ("stdout", re.compile (r"Publishing `.+' done\.\r?\n")) | 70 | pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n")) |
71 | pub.expect ("stdout", re.compile (r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) | 71 | pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) |
72 | pub.expect ("stdout", re.compile (r"Publishing `.+' done\.\r?\n")) | 72 | pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n")) |
73 | pub.expect ("stdout", re.compile (r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) | 73 | pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) |
74 | pub.expect ("stdout", re.compile (r"Publishing `.+' done\.\r?\n")) | 74 | pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n")) |
75 | pub.expect ("stdout", re.compile (r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) | 75 | pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) |
76 | pub.expect ("stdout", re.compile (r"Publishing `.+' done\.\r?\n")) | 76 | pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n")) |
77 | pub.expect ("stdout", re.compile (r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) | 77 | pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) |
78 | pub.expect ("stdout", re.compile (r"Publishing `.+' done\.\r?\n")) | 78 | pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n")) |
79 | pub.expect ("stdout", re.compile (r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) | 79 | pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) |
80 | pub.expect ("stdout", re.compile (r"Publishing `.+[\\/]dir[\\/]' done\.\r?\n")) | 80 | pub.expect("stdout", re.compile(r"Publishing `.+[\\/]dir[\\/]' done\.\r?\n")) |
81 | m = pub.expect ("stdout", re.compile (r".+\r?\n")) | 81 | m = pub.expect("stdout", re.compile(r".+\r?\n")) |
82 | if not m: | 82 | if not m: |
83 | sys.exit (3) | 83 | sys.exit(3) |
84 | output = m.string | 84 | output = m.string |
85 | url = output[output.find ("`")+1:output.find("'")] | 85 | url = output[output.find("`")+1:output.find("'")] |
86 | |||
87 | down = pexpect() | ||
88 | down.spawn(None, [download, '-c', 'test_gnunet_fs_rec_data.conf', '-R', '-o', 'rdir.gnd', url], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | ||
89 | down.expect("stdout", re.compile(r"Downloading `rdir.gnd' done (.*).\r?\n")) | ||
86 | 90 | ||
87 | down = pexpect () | 91 | d = pexpect() |
88 | down.spawn (None, [download, '-c', 'test_gnunet_fs_rec_data.conf', '-R', '-o', 'rdir.gnd', url], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 92 | d.spawn(None, [directory, '-c', 'test_gnunet_fs_rec_data.conf', 'rdir/a.gnd'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
89 | down.expect ("stdout", re.compile (r"Downloading `rdir.gnd' done (.*).\r?\n")) | 93 | d.expect("stdout", re.compile(r"Directory `a/' meta data:\r?\n")) |
94 | d.expect("stdout", re.compile(r"Directory `a/' contents:\r?\n")) | ||
95 | d.expect("stdout", re.compile(r"COPYING (.*)\r?\n")) | ||
96 | d.expect("stdout", re.compile(r"INSTALL (.*)\r?\n")) | ||
90 | 97 | ||
91 | d = pexpect () | 98 | os.remove("rdir/b.gnd") |
92 | d.spawn (None, [directory, '-c', 'test_gnunet_fs_rec_data.conf', 'rdir/a.gnd'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 99 | os.remove("rdir/a.gnd") |
93 | d.expect ("stdout", re.compile (r"Directory `a/' meta data:\r?\n")) | 100 | diff = dcdiff('dir', 'rdir') |
94 | d.expect ("stdout", re.compile (r"Directory `a/' contents:\r?\n")) | 101 | if len(diff) != 0: |
95 | d.expect ("stdout", re.compile (r"COPYING (.*)\r?\n")) | 102 | raise Exception("Unexpected difference between source directory and downloaded result:\n{}".format(diff)) |
96 | d.expect ("stdout", re.compile (r"INSTALL (.*)\r?\n")) | ||
97 | 103 | ||
98 | os.remove ("rdir/b.gnd") | ||
99 | os.remove ("rdir/a.gnd") | ||
100 | diff = dcdiff ('dir', 'rdir') | ||
101 | if len (diff) != 0: | ||
102 | raise Exception ("Unexpected difference between source directory and downloaded result:\n{}".format (diff)) | ||
103 | |||
104 | 104 | ||
105 | finally: | 105 | finally: |
106 | arm = subprocess.Popen ([gnunetarm, '-eq', '-c', 'test_gnunet_fs_rec_data.conf']) | 106 | arm = subprocess.Popen([gnunetarm, '-eq', '-c', 'test_gnunet_fs_rec_data.conf']) |
107 | arm.communicate () | 107 | arm.communicate() |
108 | if os.name == "nt": | 108 | if os.name == "nt": |
109 | shutil.rmtree (os.path.join (os.getenv ("TEMP"), "gnunet-test-fs-py-rec"), True) | 109 | shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-rec"), True) |
110 | else: | 110 | else: |
111 | shutil.rmtree ("/tmp/gnunet-test-fs-py-rec", True) | 111 | shutil.rmtree("/tmp/gnunet-test-fs-py-rec", True) |
112 | shutil.rmtree ("dir", True) | 112 | shutil.rmtree("dir", True) |
113 | shutil.rmtree ("rdir", True) | 113 | shutil.rmtree("rdir", True) |
114 | shutil.rmtree ("rdir.gnd", True) | 114 | shutil.rmtree("rdir.gnd", True) |