3 Little integration testing script while proper integration tests in Rust aren't implemented.
6 import magic
, os
, hashlib
8 def make_random_file():
9 with
open('test-file', 'wb') as fout
:
10 fout
.write(os
.urandom(2048))
12 def sanity_check_format(format
: str):
14 md5sum
= hashlib
.md5(open('test-file', 'rb').read()).hexdigest()
15 os
.system(f
"cargo run -- -i test-file -o test-file.{format}")
16 os
.remove('test-file')
17 os
.system(f
"cargo run -- -i test-file.{format}")
18 if md5sum
!= hashlib
.md5(open('test-file', 'rb').read()).hexdigest():
19 print("Something went wrong with tar (de)compression.")
21 os
.remove('test-file')
22 os
.remove(f
'test-file.{format}')
25 if __name__
== "__main__":
27 # We'll use MIME sniffing through magic numbers to
28 # verify if ouch is actually outputting the file formats
31 m
= magic
.open(magic
.MAGIC_MIME
)
34 os
.mkdir("testbuilds")
36 print ("Could not make testbuilds folder. Exiting.")
39 os
.chdir("testbuilds")
52 expected_mime_types
= [
56 "application/x-bzip2",
57 "application/x-bzip2",
63 rv
= os
.system(f
"cargo run -- -i ../src/ -o {file}")
65 print(f
"Failed while compressing {file}")
67 for (file, expected_mime
) in zip(files
, expected_mime_types
):
68 if m
.file(file) != expected_mime
:
69 print(f
"Test failed at file {file}")
72 for (idx
, file) in enumerate(files
):
73 rv
= os
.system(f
"cargo run -- -i {file} -o out{idx}/")
75 print(f
"Failed while decompressing {file}")
79 os
.system("rm -rf testbuilds")
81 # We'll now verify if ouch is not altering the data it is compressing
84 sanity_check_format("tar")
85 sanity_check_format("tar.gz")
86 sanity_check_format("tar.bz")
87 sanity_check_format("tar.bz2")
88 sanity_check_format("tar.lz")
89 sanity_check_format("tar.lzma")