Skip to content

Commit

Permalink
script to test hometasks
Browse files Browse the repository at this point in the history
  • Loading branch information
nixuser committed Feb 29, 2020
1 parent 20a8d7b commit cdbec67
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions itacademy/LinuxEssBash/virtual_lab/test_scripts/topten_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/bin/bash

# this is initial version to test hometask script
# place this file to directory with script
# run: bash topten_test.sh ./topten.sh

script_name=${1:-tt.sh}

is_exit_error(){
[ $1 != 0 ] && echo pass
}

is_exit_success(){
[ $1 == 0 ] && echo pass
}

# task create directory with files
# files with sizes from 1M, 2M, 3M to 10M
# names file_size_1M

test_dir_big_files(){
test_dir_name=${1:-test_dir}
[ -d "$test_dir_name" ] || mkdir "$test_dir_name"
for size in {1..10}
do
dd if=/dev/urandom of=./"${test_dir_name}"/file_size_${size}M bs=1M count=$size 1>/dev/null 2>&1
done
echo bash "$script_name" "$test_dir_name"
bash "$script_name" "$test_dir_name"
}

test_help(){
echo bash "$script_name" -h
bash "$script_name" -h
is_exit_success $?
}

test_two_args(){
echo bash "$script_name" argument1 argument2
bash "$script_name" argument1 argument2
is_exit_error $?
}

test_noargs(){
echo bash "$script_name"
bash "$script_name"
is_exit_error $?
}

test_non_exised_file(){
echo bash "$script_name" /abcd
bash "$script_name" /abcd
is_exit_error $?
}

test_non_dir_file(){
echo bash "$script_name" /etc/passwd
bash "$script_name" /etc/passwd
is_exit_error $?
}

test_spaces(){
test_dir_big_files "dir with spaces"
}

test_dir_big_files
test_spaces
test_help
test_two_args
test_non_exised_file
test_non_dir_file

0 comments on commit cdbec67

Please sign in to comment.