Skip to content

Commit

Permalink
[tests] User asser_equal
Browse files Browse the repository at this point in the history
  • Loading branch information
goldyfruit committed Nov 19, 2023
1 parent 05e1754 commit a7a3e4a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 39 deletions.
17 changes: 7 additions & 10 deletions tests/bats/display.bats
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,33 @@ function setup() {
@test "function_detect_display_x11" {
function loginctl() {
echo "x11"
}
}
sessions="3"
export -f loginctl
detect_display
echo $DISPLAY_SERVER
[ "$DISPLAY_SERVER" == "x11" ]
assert_equal "$DISPLAY_SERVER" "x11"
unset loginctl
}

@test "function_detect_display_wayland" {
function loginctl() {
echo "wayland"
}
}
sessions="6"
export -f loginctl
detect_display
echo $DISPLAY_SERVER
[ "$DISPLAY_SERVER" == "wayland" ]
assert_equal "$DISPLAY_SERVER" "wayland"
unset loginctl
}


@test "function_detect_display_no_display" {
function loginctl() {
echo "tty"
}
}
sessions="11"
export -f loginctl
detect_display
echo $DISPLAY_SERVER
[ "$DISPLAY_SERVER" == "N/A" ]
assert_equal "$DISPLAY_SERVER" "N/A"
unset loginctl
}
}
22 changes: 8 additions & 14 deletions tests/bats/instance.bats
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ function setup() {
}
export -f docker
detect_existing_instance
echo "$EXISTING_INSTANCE"
[ "$EXISTING_INSTANCE" == "true" ]
assert_equal "$EXISTING_INSTANCE" "true"
unset docker
}

Expand All @@ -25,8 +24,7 @@ function setup() {
}
export -f docker
detect_existing_instance
echo "$EXISTING_INSTANCE"
[ "$EXISTING_INSTANCE" == "false" ]
assert_equal "$EXISTING_INSTANCE" "false"
unset docker
}

Expand All @@ -39,8 +37,7 @@ function setup() {
}
export -f docker podman
detect_existing_instance
echo "$EXISTING_INSTANCE"
[ "$EXISTING_INSTANCE" == "true" ]
assert_equal "$EXISTING_INSTANCE" "true"
unset docker podman
}

Expand All @@ -53,8 +50,7 @@ function setup() {
}
export -f docker podman
detect_existing_instance
echo "$EXISTING_INSTANCE"
[ "$EXISTING_INSTANCE" == "false" ]
assert_equal "$EXISTING_INSTANCE" "false"
unset docker podman
}

Expand All @@ -69,9 +65,8 @@ function setup() {
}
export -f docker podman
detect_existing_instance
echo "$EXISTING_INSTANCE"
[ "$EXISTING_INSTANCE" == "true" ]
unset docker podman
assert_equal "$EXISTING_INSTANCE" "true"
unset docker podman
}

@test "function_detect_existing_instance_venv_non_exists" {
Expand All @@ -83,7 +78,6 @@ function setup() {
}
export -f docker podman
detect_existing_instance
echo "$EXISTING_INSTANCE"
[ "$EXISTING_INSTANCE" == "false" ]
assert_equal "$EXISTING_INSTANCE" "false"
unset docker podman
}
}
16 changes: 10 additions & 6 deletions tests/bats/main.bats
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ function setup() {
LOG_FILE=/tmp/ovos-installer.log
}

@test "function_on_error_detected" {
run on_error
assert_failure
assert_output --partial "Please check $LOG_FILE for more details"
}

@test "function_delete_log_if_exist" {
run touch "$LOG_FILE"
run delete_log
Expand All @@ -20,13 +26,14 @@ function setup() {
}

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

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

Expand All @@ -36,8 +43,7 @@ function setup() {
}
export -f grep
detect_cpu_instructions
echo "$CPU_IS_CAPABLE"
[ "$CPU_IS_CAPABLE" == "true" ]
assert_equal "$CPU_IS_CAPABLE" "true"
unset grep
}

Expand All @@ -47,8 +53,6 @@ function setup() {
}
export -f grep
detect_cpu_instructions
echo "$CPU_IS_CAPABLE"
[ "$CPU_IS_CAPABLE" == "false" ]
assert_equal "$CPU_IS_CAPABLE" "false"
unset grep
}

14 changes: 5 additions & 9 deletions tests/bats/sound.bats
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ function setup() {
}
export -f pgrep command pactl
detect_sound
echo "$SOUND_SERVER"
[ "$SOUND_SERVER" == "pulseaudio" ]
assert_equal "$SOUND_SERVER" "pulseaudio"
unset pgrep command pactl
}

Expand All @@ -34,8 +33,7 @@ function setup() {
}
export -f pgrep command
detect_sound
echo "$SOUND_SERVER"
[ "$SOUND_SERVER" == "PulseAudio (on PipeWire)" ]
assert_equal "$SOUND_SERVER" "PulseAudio (on PipeWire)"
unset pgrep command
}

Expand All @@ -45,8 +43,7 @@ function setup() {
}
export -f pgrep
detect_sound
echo "$SOUND_SERVER"
[ "$SOUND_SERVER" == "PipeWire" ]
assert_equal "$SOUND_SERVER" "PipeWire"
unset pgrep
}

Expand All @@ -57,7 +54,6 @@ function setup() {
}
export -f pgrep
detect_sound
echo "$SOUND_SERVER"
[ "$SOUND_SERVER" == "N/A" ]
assert_equal "$SOUND_SERVER" "N/A"
unset pgrep
}
}

0 comments on commit a7a3e4a

Please sign in to comment.