From 6b0a401bfaccf280c15a52b7188a69fa2af783c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Trellu?= Date: Fri, 17 Nov 2023 21:21:36 -0500 Subject: [PATCH] [tests] Initial bats tests --- tests/bats/main.bats | 59 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tests/bats/main.bats diff --git a/tests/bats/main.bats b/tests/bats/main.bats new file mode 100644 index 0000000..797b93a --- /dev/null +++ b/tests/bats/main.bats @@ -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 +}