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')
24 if __name__
== "__main__":
26 # We'll use MIME sniffing through magic numbers to
27 # verify if ouch is actually outputting the file formats
30 m
= magic
.open(magic
.MAGIC_MIME
)
33 os
.mkdir("testbuilds")
35 print ("Could not make testbuilds folder. Exiting.")
38 os
.chdir("testbuilds")
51 expected_mime_types
= [
55 "application/x-bzip2",
56 "application/x-bzip2",
62 rv
= os
.system(f
"cargo run -- -i ../src/ -o {file}")
64 print(f
"Failed while compressing {file}")
66 for (file, expected_mime
) in zip(files
, expected_mime_types
):
67 if m
.file(file) != expected_mime
:
68 print(f
"Test failed at file {file}")
71 for (idx
, file) in enumerate(files
):
72 rv
= os
.system(f
"cargo run -- -i {file} -o out{idx}/")
74 print(f
"Failed while decompressing {file}")
78 os
.system("rm -rf testbuilds")
80 # We'll now verify if ouch is not altering the data it is compressing
83 sanity_check_format("tar")
84 sanity_check_format("tar.gz")
85 sanity_check_format("tar.bz")
86 sanity_check_format("tar.bz2")
87 sanity_check_format("tar.lz")
88 sanity_check_format("tar.lzma")