Skip to content

Commit

Permalink
[tests] Initial bats tests
Browse files Browse the repository at this point in the history
  • Loading branch information
goldyfruit committed Nov 18, 2023
1 parent 07e31c5 commit 6b0a401
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions tests/bats/main.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env bats

function setup() {
load "$HOME/Developments/SmartGic/shell-test/test_helper/bats-support/load"
load "$HOME/Developments/SmartGic/shell-test/test_helper/bats-assert/load"
load ../../utils/constants.sh
load ../../utils/common.sh
LOG_FILE=/tmp/ovos-installer.log
}

@test "function_delete_log_if_exist" {
run touch "$LOG_FILE"
run delete_log
assert_success
}

@test "function_delete_log_non_exist" {
run delete_log
assert_success
}

@test "function_delete_log_fail" {
LOG_FILE=/var/log/ovos-installer.log
run delete_log
assert_failure
}

@test "function_detect_user_root" {
USER_ID=0
run detect_user
assert_success
}

@test "function_detect_user_non_root" {
run detect_user
assert_output --partial "This script must be run as root or with sudo"
}

@test "function_detect_cpu_instructions_capable" {
function grep() {
return 0
}
export -f grep
detect_cpu_instructions
echo $CPU_IS_CAPABLE
[ "${CPU_IS_CAPABLE}" == "true" ]
unset grep
}

@test "function_detect_cpu_instructions_not_capable" {
function grep() {
return 1
}
export -f grep
detect_cpu_instructions
echo $CPU_IS_CAPABLE
[ "${CPU_IS_CAPABLE}" == "false" ]
unset grep
}

0 comments on commit 6b0a401

Please sign in to comment.