From 3583ae4bcbfc6ab3d809dc95d854c1e47e562c8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Trellu?= Date: Sat, 18 Nov 2023 19:02:34 -0500 Subject: [PATCH] [tests] Add more BATS tests --- tests/bats/main.bats | 58 ++++++++++++++++++++++++++++++++++++--- tests/bats/sound.bats | 63 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+), 4 deletions(-) create mode 100644 tests/bats/sound.bats diff --git a/tests/bats/main.bats b/tests/bats/main.bats index 4a9e9df3..97099996 100644 --- a/tests/bats/main.bats +++ b/tests/bats/main.bats @@ -36,8 +36,8 @@ function setup() { } export -f grep detect_cpu_instructions - echo $CPU_IS_CAPABLE - [ "${CPU_IS_CAPABLE}" == "true" ] + echo "$CPU_IS_CAPABLE" + [ "$CPU_IS_CAPABLE" == "true" ] unset grep } @@ -47,7 +47,57 @@ function setup() { } export -f grep detect_cpu_instructions - echo $CPU_IS_CAPABLE - [ "${CPU_IS_CAPABLE}" == "false" ] + echo "$CPU_IS_CAPABLE" + [ "$CPU_IS_CAPABLE" == "false" ] unset grep } + +@test "function_detect_existing_instance_docker_exists" { + function docker() { + echo "adf1dedc2025" + } + export -f docker + detect_existing_instance + echo "$EXISTING_INSTANCE" + [ "$EXISTING_INSTANCE" == "true" ] + unset docker +} + +@test "function_detect_existing_instance_docker_non_exists" { + function docker() { + return 0 + } + export -f docker + detect_existing_instance + echo "$EXISTING_INSTANCE" + [ "$EXISTING_INSTANCE" == "false" ] + unset docker +} + +@test "function_detect_existing_instance_podman_exists" { + function docker() { + return 0 + } + function podman() { + echo "adf1dedc2025" + } + export -f docker podman + detect_existing_instance + echo "$EXISTING_INSTANCE" + [ "$EXISTING_INSTANCE" == "true" ] + unset docker podman +} + +@test "function_detect_existing_instance_podman_non_exists" { + function docker() { + return 0 + } + function podman() { + return 0 + } + export -f docker podman + detect_existing_instance + echo "$EXISTING_INSTANCE" + [ "$EXISTING_INSTANCE" == "false" ] + unset docker podman +} diff --git a/tests/bats/sound.bats b/tests/bats/sound.bats new file mode 100644 index 00000000..973ee650 --- /dev/null +++ b/tests/bats/sound.bats @@ -0,0 +1,63 @@ +#!/usr/bin/env bats + +function setup() { + load "$HOME/shell-testing/test_helper/bats-support/load" + load "$HOME/shell-testing/test_helper/bats-assert/load" + load ../../utils/constants.sh + load ../../utils/common.sh + LOG_FILE=/tmp/ovos-installer.log +} + +@test "function_detect_sound_pulseaudio" { + function pgrep() { + echo "pulse" + } + function command() { + return 0 + } + function pactl() { + echo "Server Name: pulseaudio" + } + export -f pgrep command pactl + detect_sound + echo "$SOUND_SERVER" + [ "$SOUND_SERVER" == "pulseaudio" ] + unset pgrep command pactl +} + +@test "function_detect_sound_pulseaudio_via_pipewire" { + function pgrep() { + echo "pulse" + } + function command() { + return 1 + } + export -f pgrep command + detect_sound + echo "$SOUND_SERVER" + [ "$SOUND_SERVER" == "PulseAudio (on PipeWire)" ] + unset pgrep command +} + +@test "function_detect_sound_pipewire" { + function pgrep() { + echo "pipewire" + } + export -f pgrep + detect_sound + echo "$SOUND_SERVER" + [ "$SOUND_SERVER" == "PipeWire" ] + unset pgrep +} + +@test "function_detect_sound_no_audio" { + run touch "$LOG_FILE" + function pgrep() { + return 1 + } + export -f pgrep + detect_sound + echo "$SOUND_SERVER" + [ "$SOUND_SERVER" == "N/A" ] + unset pgrep +} \ No newline at end of file