From 09d045f5a5c25dd03095a32bea9264cc6274ff1b Mon Sep 17 00:00:00 2001 From: Matty Evans Date: Wed, 15 Jan 2025 17:31:43 +1000 Subject: [PATCH 1/2] refactor(install): ask users if they wish to start contributoor post install --- install.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 6cfd868..5b13a3d 100755 --- a/install.sh +++ b/install.sh @@ -24,7 +24,7 @@ if ! tput clear >/dev/null 2>&1; then fi # Installation defaults -TOTAL_STEPS="8" +TOTAL_STEPS="9" CONTRIBUTOOR_PATH=${CONTRIBUTOOR_PATH:-"$HOME/.contributoor"} CONTRIBUTOOR_BIN="$CONTRIBUTOOR_PATH/bin" CONTRIBUTOOR_VERSION="latest" @@ -757,9 +757,21 @@ main() { progress 8 "Run install wizard" "$CONTRIBUTOOR_BIN/contributoor" --config-path "$CONTRIBUTOOR_PATH" install --version "$CONTRIBUTOOR_VERSION" --run-method "$INSTALL_MODE" + # Ask user if they want to start the service + printf "\nWould you like to start contributoor now? [y/N]: " + read -r START_SERVICE + case "$(echo "$START_SERVICE" | tr '[:upper:]' '[:lower:]')" in + y|yes) + "$CONTRIBUTOOR_BIN/contributoor" --config-path "$CONTRIBUTOOR_PATH" restart + ;; + *) + printf "${COLOR_YELLOW}You can start contributoor later by running:${COLOR_RESET} contributoor start" + ;; + esac + # Show PATH refresh message if needed. if [ "$ADDED_TO_PATH" = true ]; then - printf "${COLOR_YELLOW}NOTE: To use contributoor commands, either start a new terminal or run: source ~/.$(basename "$SHELL")rc${COLOR_RESET}\n" + printf "\n\n${COLOR_YELLOW}NOTE: To use contributoor commands, either start a new terminal or run:${COLOR_RESET} source ~/.$(basename "$SHELL")rc\n" fi } From 549423acd72383476d0244f9fd7cfa8875ba8742 Mon Sep 17 00:00:00 2001 From: Matty Evans Date: Wed, 15 Jan 2025 17:36:33 +1000 Subject: [PATCH 2/2] test: add service start prompt test cases --- install.bats | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/install.bats b/install.bats index a723ea0..4fd19e9 100644 --- a/install.bats +++ b/install.bats @@ -898,4 +898,90 @@ EOF grep -q "io.ethpandaops.contributoor" "$TEST_DIR/io.ethpandaops.contributoor.plist" grep -q "$CONTRIBUTOOR_BIN/sentry" "$TEST_DIR/io.ethpandaops.contributoor.plist" grep -q "$USER" "$TEST_DIR/io.ethpandaops.contributoor.plist" +} + +@test "service start prompt handles yes response" { + # Create test script + cat > "$TEST_DIR/prompt_test.sh" << 'EOF' +#!/bin/bash +source ./install.sh +contributoor() { return 0; } +export -f contributoor +CONTRIBUTOOR_BIN="$TEST_DIR/bin" +printf "\nWould you like to start contributoor now? [y/N]: " +read -r START_SERVICE +case "$(echo "$START_SERVICE" | tr "[:upper:]" "[:lower:]")" in + y|yes) + contributoor --config-path "$TEST_DIR" restart + ;; + *) + printf "You can start contributoor later by running: contributoor start" + ;; +esac +EOF + chmod +x "$TEST_DIR/prompt_test.sh" + + # Run test with yes input + printf 'y\n' | "$TEST_DIR/prompt_test.sh" + local result=$? + + [ "$result" -eq 0 ] +} + +@test "service start prompt handles no response" { + # Create test script + cat > "$TEST_DIR/prompt_test.sh" << 'EOF' +#!/bin/bash +source ./install.sh +contributoor() { return 0; } +export -f contributoor +CONTRIBUTOOR_BIN="$TEST_DIR/bin" +printf "\nWould you like to start contributoor now? [y/N]: " +read -r START_SERVICE +case "$(echo "$START_SERVICE" | tr "[:upper:]" "[:lower:]")" in + y|yes) + contributoor --config-path "$TEST_DIR" restart + ;; + *) + printf "You can start contributoor later by running: contributoor start" + ;; +esac +EOF + chmod +x "$TEST_DIR/prompt_test.sh" + + # Run test with no input + output=$(printf 'n\n' | "$TEST_DIR/prompt_test.sh") + local result=$? + + [ "$result" -eq 0 ] + echo "$output" | grep -q "You can start contributoor later" +} + +@test "service start prompt handles empty response" { + # Create test script + cat > "$TEST_DIR/prompt_test.sh" << 'EOF' +#!/bin/bash +source ./install.sh +contributoor() { return 0; } +export -f contributoor +CONTRIBUTOOR_BIN="$TEST_DIR/bin" +printf "\nWould you like to start contributoor now? [y/N]: " +read -r START_SERVICE +case "$(echo "$START_SERVICE" | tr "[:upper:]" "[:lower:]")" in + y|yes) + contributoor --config-path "$TEST_DIR" restart + ;; + *) + printf "You can start contributoor later by running: contributoor start" + ;; +esac +EOF + chmod +x "$TEST_DIR/prompt_test.sh" + + # Run test with empty input + output=$(printf '\n' | "$TEST_DIR/prompt_test.sh") + local result=$? + + [ "$result" -eq 0 ] + echo "$output" | grep -q "You can start contributoor later" } \ No newline at end of file