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 26db411 commit 05e1754
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 49 deletions.
46 changes: 46 additions & 0 deletions tests/bats/display.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/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_display_x11" {
function loginctl() {
echo "x11"
}
sessions="3"
export -f loginctl
detect_display
echo $DISPLAY_SERVER
[ "$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" ]
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" ]
unset loginctl
}
89 changes: 89 additions & 0 deletions tests/bats/instance.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/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_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
}

@test "function_detect_existing_instance_venv_exists" {
RUN_AS_HOME=$USER
run mkdir -p "$RUN_AS_HOME/.venvs/ovos"
function docker() {
return 0
}
function podman() {
return 0
}
export -f docker podman
detect_existing_instance
echo "$EXISTING_INSTANCE"
[ "$EXISTING_INSTANCE" == "true" ]
unset docker podman
}

@test "function_detect_existing_instance_venv_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
}
49 changes: 0 additions & 49 deletions tests/bats/main.bats
Original file line number Diff line number Diff line change
Expand Up @@ -52,52 +52,3 @@ function setup() {
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
}

0 comments on commit 05e1754

Please sign in to comment.