Skip to content

Commit

Permalink
move lots of files, fix sudo test
Browse files Browse the repository at this point in the history
  • Loading branch information
joelmccracken committed Dec 29, 2024
1 parent d495955 commit 8261466
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 49 deletions.
6 changes: 5 additions & 1 deletion ws_tool/lib/properties.bash
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,10 @@ prop_ws_nix_global_config_fix () {
echo "${parts[2]}"
} > "$new_conf"

sudo "${WORKSTATION_DIR}/ws_tool/bin/safe-overwrite" "$new_conf" "$WS_NIX_GLOBAL_CONFIG_LOCATION"
maybe_sudo="bash" # basically does nothing different
if ! [[ -w "$WS_NIX_GLOBAL_CONFIG_LOCATION" ]]; then
maybe_sudo="sudo"
fi
"$maybe_sudo" "${WORKSTATION_DIR}/ws_tool/bin/safe-overwrite" "$new_conf" "$WS_NIX_GLOBAL_CONFIG_LOCATION"
}

24 changes: 0 additions & 24 deletions ws_tool/test/logging.bats

This file was deleted.

25 changes: 10 additions & 15 deletions ws_tool/test/test_helper/helper.bash
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
_setup_common() {
# BATS_LIB_PATH="test_helper/bats-support:/opt/homebrew/lib:/opt/homebrew/Cellar/bats-support/0.3.0/lib:$BATS_LIB_PATH"
load 'test_helper/bats-support/load'
load 'test_helper/bats-assert/load'


# get the containing directory of this file
# use $BATS_TEST_FILENAME instead of ${BASH_SOURCE[0]} or $0,
# as those will point to the bats executable's location or the preprocessed file respectively
PROJECT_ROOT="$( cd "$( dirname "$BATS_TEST_FILENAME" )/../../" >/dev/null 2>&1 && pwd )"
ws_unset_settings
# echo "$PROJECT_ROOT, $BATS_TEST_FILENAME" >&3
# make executables in src/ visible to PATH
PATH="$PROJECT_ROOT:/bin/:${PROJECT_ROOT}/ws_tool:$PATH"
: "${WORKSTATION_DIR:="$PROJECT_ROOT"}"
. "$PROJECT_ROOT/ws_tool/lib/lib.bash"
PROJECT_ROOT="$( cd "$(dirname "${BASH_SOURCE[0]}")/../../../" &>/dev/null && pwd)"
BATS_LIB_PATH="$PROJECT_ROOT/ws_tool/test/test_helper:$BATS_LIB_PATH"
bats_load_library "bats-support"
bats_load_library "bats-assert"

ws_unset_settings
# echo "$PROJECT_ROOT, $BATS_TEST_FILENAME" >&3
PATH="$PROJECT_ROOT:/bin/:${PROJECT_ROOT}/ws_tool:$PATH"
: "${WORKSTATION_DIR:="$PROJECT_ROOT"}"
. "$PROJECT_ROOT/ws_tool/lib/lib.bash"
}

set_workstation_version_last_sha() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

setup (){
load 'test_helper/helper'
load '../test_helper/helper'
_setup_common
. "$PROJECT_ROOT/ws_tool/lib/properties.bash"
. "$PROJECT_ROOT/ws_tool/lib/bootstrap_doctor.bash"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env zsh

setup (){
load 'test_helper/helper'
load '../test_helper/helper'
_setup_common
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

setup (){
load 'test_helper/helper'
load '../test_helper/helper'
_setup_common
}

Expand Down
6 changes: 3 additions & 3 deletions ws_tool/test/lib.bats → ws_tool/test/unit/lib.bats
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
setup (){
load 'test_helper/helper'
_setup_common
. "$PROJECT_ROOT/ws_tool/lib/lib.bash"
load "../test_helper/helper"
_setup_common
. "$PROJECT_ROOT/ws_tool/lib/lib.bash"
}

@test "find_bracketed_content" {
Expand Down
24 changes: 24 additions & 0 deletions ws_tool/test/unit/logging.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
setup (){
load "../test_helper/helper"
_setup_common
. "$PROJECT_ROOT/ws_tool/lib/logging.bash"
}

@test "log_level_num gets level number from name" {
export BATS_VERBOSE_RUN=true
run retfunc log_level_num error
assert_output --partial 'VAR:REPLY=([0]="4")'
}

@test "logs by log level" {
WORKSTATION_LOG_LEVEL=debug
run debug "hello world"
assert_output --partial 'hello world'
}

@test "skips logs when out of log level" {
WORKSTATION_LOG_LEVEL=error
run debug "hello world"
refute_output --partial 'hello world'
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
setup (){
load 'test_helper/helper'
load '../test_helper/helper'
_setup_common
. "$PROJECT_ROOT/ws_tool/lib/properties.bash"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
setup (){
load 'test_helper/helper'
load '../test_helper/helper'
_setup_common
ws_reset_settings
}
Expand Down
2 changes: 1 addition & 1 deletion ws_tool/test/ws-cli.bats → ws_tool/test/unit/ws-cli.bats
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
setup (){
load 'test_helper/helper'
load "../test_helper/helper"
_setup_common
. "$PROJECT_ROOT/ws_tool/ws"
}
Expand Down

0 comments on commit 8261466

Please sign in to comment.