-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
50 lines (45 loc) · 1.39 KB
/
test.sh
File metadata and controls
50 lines (45 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
## @file tests.sh
## @brief Bash functions to perform unit test
## @author Lydéric Debusschère
## @fn f_test__file_exist
## @author Lydéric Debusschère
## @brief Test is a file exist
## @param file
## @return Return 0 if file exist; 1 if not
## @remark Example: f_test__file_exist <file_path>/file
f_test__file_exist() {
if [[ ! -e $1 ]]; then
echo "File $1 does not exist !"
return 1
fi
return 0
}
## @fn f_test__file_is_readable
## @author Lydéric Debusschère
## @brief Test is a file is readable
## @param file
## @return Return 0 if file is readable; 1 if not
## @remark Example: f_test__file_is_readable <file_path>/file
f_test__file_is_readable() {
if [[ ! -r $1 ]]; then
echo "File $1 is corrupted !"
return 1
fi
return 0
}
## @fn f_test__file_is_x_tar
## @author Lydéric Debusschère
## @brief Test is a file is an archive
## @param file
## @return Return 0 if file is an archive; 1 if not
## @remark Example: f_test__file_is_x_tar <file_path>/file
f_test__file_is_x_tar(){
if [[ $(file --mime-type $1 | awk '{print $(NF)}') != "application/x-tar" ]]; then
echo "File $1 is not of type application/x-tar.
type: $(file --mime-type $1 | awk '{print $(NF)}')
"
return 1
fi
return 0
}