|
|
|
@@ -7,104 +7,104 @@ setup() {
|
|
|
|
|
common_setup
|
|
|
|
|
|
|
|
|
|
export XDG_CONFIG_HOME="$TEST_TEMP_DIR/.config"
|
|
|
|
|
export ENV_FILE="$XDG_CONFIG_HOME/huami-token.env"
|
|
|
|
|
export DROPIN_DIR="$TEST_TEMP_DIR/huami-token.service.d"
|
|
|
|
|
export DROPIN_FILE="$DROPIN_DIR/01-set-working-directory.conf"
|
|
|
|
|
export TIMER_DIR="$XDG_CONFIG_HOME/systemd/user/timers.target.wants"
|
|
|
|
|
export TIMER_LINK="$TIMER_DIR/huami-token.timer"
|
|
|
|
|
mkdir -p "$TIMER_DIR"
|
|
|
|
|
mkdir -p "$XDG_CONFIG_HOME"
|
|
|
|
|
touch "$TEST_TEMP_DIR/dummy-timer.target"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# bats file_tags=generate
|
|
|
|
|
@test "The happy path" {
|
|
|
|
|
cat <<EOF >"$XDG_CONFIG_HOME/huami-token.env"
|
|
|
|
|
cat <<EOF >"$ENV_FILE"
|
|
|
|
|
ZEPP_USER=fnuggi
|
|
|
|
|
ZEPP_PASS=ugh
|
|
|
|
|
ZEPP_AGPS_TARGET_DIR=/tmp/tmp
|
|
|
|
|
EOF
|
|
|
|
|
unset -f _is_timer_disabled _disable_timer
|
|
|
|
|
ln -sf "$TEST_TEMP_DIR/dummy-timer.target" "$TIMER_LINK"
|
|
|
|
|
|
|
|
|
|
run main "$TEST_TEMP_DIR"
|
|
|
|
|
|
|
|
|
|
assert_file_exists "$TEST_TEMP_DIR/01-WorkingDirectory.conf"
|
|
|
|
|
assert_file_contains "$TEST_TEMP_DIR/01-WorkingDirectory.conf" "WorkingDirectory=/tmp/tmp"
|
|
|
|
|
assert_file_exists "$DROPIN_FILE"
|
|
|
|
|
assert_file_contains "$DROPIN_FILE" "WorkingDirectory=/tmp/tmp"
|
|
|
|
|
assert_link_exists "$TIMER_LINK"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# bats file_tags=generate
|
|
|
|
|
@test "The systemd conf is updated with new value" {
|
|
|
|
|
cat <<EOF >"$XDG_CONFIG_HOME/huami-token.env"
|
|
|
|
|
cat <<EOF >"$ENV_FILE"
|
|
|
|
|
ZEPP_USER=fnuggi
|
|
|
|
|
ZEPP_PASS=ugh
|
|
|
|
|
ZEPP_AGPS_TARGET_DIR=/tmp/ugh
|
|
|
|
|
EOF
|
|
|
|
|
echo "WorkingDirectory=/tmp/tmp" > "$TEST_TEMP_DIR/01-WorkingDirectory.conf"
|
|
|
|
|
unset -f _is_timer_disabled _disable_timer
|
|
|
|
|
ln -sf "$TEST_TEMP_DIR/dummy-timer.target" "$TIMER_LINK"
|
|
|
|
|
mkdir -p "$DROPIN_DIR"
|
|
|
|
|
echo "WorkingDirectory=/tmp/tmp" > "$DROPIN_FILE"
|
|
|
|
|
|
|
|
|
|
run main "$TEST_TEMP_DIR"
|
|
|
|
|
|
|
|
|
|
assert_file_exists "$TEST_TEMP_DIR/01-WorkingDirectory.conf"
|
|
|
|
|
assert_file_contains "$TEST_TEMP_DIR/01-WorkingDirectory.conf" "WorkingDirectory=/tmp/ugh"
|
|
|
|
|
assert_file_exists "$DROPIN_FILE"
|
|
|
|
|
assert_file_contains "$DROPIN_FILE" "WorkingDirectory=/tmp/ugh"
|
|
|
|
|
assert_link_exists "$TIMER_LINK"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# bats file_tags=generate
|
|
|
|
|
@test "Config file is missing, the timer is disabled" {
|
|
|
|
|
rm -f "$XDG_CONFIG_HOME/huami-token.env"
|
|
|
|
|
echo "WorkingDirectory=/tmp/tmp" > "$TEST_TEMP_DIR/01-WorkingDirectory.conf"
|
|
|
|
|
|
|
|
|
|
unset -f _is_timer_enabled
|
|
|
|
|
stub _is_timer_enabled 'echo disabled'
|
|
|
|
|
@test "Config file is missing, the timer status was disabled" {
|
|
|
|
|
rm -f "$ENV_FILE"
|
|
|
|
|
mkdir -p "$DROPIN_DIR"
|
|
|
|
|
echo "WorkingDirectory=/tmp/tmp" > "$DROPIN_FILE"
|
|
|
|
|
|
|
|
|
|
run main "$TEST_TEMP_DIR"
|
|
|
|
|
|
|
|
|
|
assert_file_not_exists "$TEST_TEMP_DIR/01-WorkingDirectory.conf"
|
|
|
|
|
unstub _is_timer_enabled
|
|
|
|
|
assert_file_not_exists "$DROPIN_FILE"
|
|
|
|
|
assert_file_not_exists "$TIMER_LINK"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# bats file_tags=generate
|
|
|
|
|
@test "Config file is missing, the timer is enabled" {
|
|
|
|
|
rm -f "$XDG_CONFIG_HOME/huami-token.env"
|
|
|
|
|
echo "WorkingDirectory=/tmp/tmp" > "$TEST_TEMP_DIR/01-WorkingDirectory.conf"
|
|
|
|
|
|
|
|
|
|
unset -f _is_timer_enabled _disable_timer
|
|
|
|
|
stub _is_timer_enabled 'echo enabled'
|
|
|
|
|
stub _disable_timer 'true'
|
|
|
|
|
@test "Config file is missing, the timer status was enabled" {
|
|
|
|
|
rm -f "$ENV_FILE"
|
|
|
|
|
ln -sf "$TEST_TEMP_DIR/dummy-timer.target" "$TIMER_LINK"
|
|
|
|
|
mkdir -p "$DROPIN_DIR"
|
|
|
|
|
echo "WorkingDirectory=/tmp/tmp" > "$DROPIN_FILE"
|
|
|
|
|
|
|
|
|
|
run main "$TEST_TEMP_DIR"
|
|
|
|
|
|
|
|
|
|
assert_file_not_exists "$TEST_TEMP_DIR/01-WorkingDirectory.conf"
|
|
|
|
|
unstub _is_timer_enabled
|
|
|
|
|
unstub _disable_timer
|
|
|
|
|
assert_file_not_exists "$DROPIN_FILE"
|
|
|
|
|
assert_file_not_exists "$TIMER_LINK"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# bats file_tags=generate
|
|
|
|
|
@test "No target dir is set, the timer is disabled" {
|
|
|
|
|
cat <<EOF >"$XDG_CONFIG_HOME/huami-token.env"
|
|
|
|
|
@test "No target dir is set, the timer status was disabled" {
|
|
|
|
|
cat <<EOF >"$ENV_FILE"
|
|
|
|
|
ZEPP_USER=fnuggi
|
|
|
|
|
ZEPP_PASS=ugh
|
|
|
|
|
ZEPP_AGPS_TARGET_DIR=
|
|
|
|
|
EOF
|
|
|
|
|
echo "WorkingDirectory=/tmp/tmp" > "$TEST_TEMP_DIR/01-WorkingDirectory.conf"
|
|
|
|
|
|
|
|
|
|
unset -f _is_timer_enabled
|
|
|
|
|
stub _is_timer_enabled 'echo disabled'
|
|
|
|
|
mkdir -p "$DROPIN_DIR"
|
|
|
|
|
echo "WorkingDirectory=/tmp/tmp" > "$DROPIN_FILE"
|
|
|
|
|
|
|
|
|
|
run main "$TEST_TEMP_DIR"
|
|
|
|
|
|
|
|
|
|
assert_file_not_exists "$TEST_TEMP_DIR/01-WorkingDirectory.conf"
|
|
|
|
|
unstub _is_timer_enabled
|
|
|
|
|
assert_file_not_exists "$DROPIN_FILE"
|
|
|
|
|
assert_file_not_exists "$TIMER_LINK"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# bats file_tags=generate
|
|
|
|
|
@test "No target dir is set, the timer is enabled" {
|
|
|
|
|
cat <<EOF >"$XDG_CONFIG_HOME/huami-token.env"
|
|
|
|
|
@test "No target dir is set, the timer status was enabled" {
|
|
|
|
|
cat <<EOF >"$ENV_FILE"
|
|
|
|
|
ZEPP_USER=fnuggi
|
|
|
|
|
ZEPP_PASS=ugh
|
|
|
|
|
ZEPP_AGPS_TARGET_DIR=
|
|
|
|
|
EOF
|
|
|
|
|
echo "WorkingDirectory=/tmp/tmp" > "$TEST_TEMP_DIR/01-WorkingDirectory.conf"
|
|
|
|
|
|
|
|
|
|
unset -f _is_timer_enabled _disable_timer
|
|
|
|
|
stub _is_timer_enabled 'echo enabled'
|
|
|
|
|
stub _disable_timer 'true'
|
|
|
|
|
mkdir -p "$DROPIN_DIR"
|
|
|
|
|
echo "WorkingDirectory=/tmp/tmp" > "$DROPIN_FILE"
|
|
|
|
|
ln -sf "$TEST_TEMP_DIR/dummy-timer.target" "$TIMER_LINK"
|
|
|
|
|
|
|
|
|
|
run main "$TEST_TEMP_DIR"
|
|
|
|
|
|
|
|
|
|
assert_file_not_exists "$TEST_TEMP_DIR/01-WorkingDirectory.conf"
|
|
|
|
|
unstub _is_timer_enabled
|
|
|
|
|
unstub _disable_timer
|
|
|
|
|
assert_file_not_exists "$DROPIN_FILE"
|
|
|
|
|
assert_file_not_exists "$TIMER_LINK"
|
|
|
|
|
}
|
|
|
|
|