Skip to content

Commit

Permalink
[tests] Add more BATS tests
Browse files Browse the repository at this point in the history
  • Loading branch information
goldyfruit committed Nov 19, 2023
1 parent b5e8c19 commit 3583ae4
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 4 deletions.
58 changes: 54 additions & 4 deletions tests/bats/main.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}
63 changes: 63 additions & 0 deletions tests/bats/sound.bats
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 3583ae4

Please sign in to comment.