Skip to content

Commit

Permalink
Fix remove.sh script and create its test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Surdej committed Jan 23, 2024
1 parent 5a4c401 commit bacffde
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/remove.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

set -euo pipefail
set -eo pipefail

source "${BASH_SOURCE%/*}/shared/utils.sh"

Expand Down
Empty file modified tests/clone_test.sh
100644 → 100755
Empty file.
48 changes: 48 additions & 0 deletions tests/remove_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bats

LIB_DIR="./lib"
TEST_MGC_BASE_DIR="./tmp-test-remove"
PROFILE_DIR="$TEST_MGC_BASE_DIR/.mgc/profiles"

setup() {
MGC_DIR="$TEST_MGC_BASE_DIR/.mgc"
export MGC_DIR

mkdir -p "$PROFILE_DIR"
}

teardown() {
rm -rf "$TEST_MGC_BASE_DIR"
}

create_test_profile() {
local profile_name=$1
mkdir -p "$PROFILE_DIR/$profile_name"
echo "/path/to/test/id_rsa" > "$PROFILE_DIR/$profile_name/ssh_key"
echo "test@example.com" > "$PROFILE_DIR/$profile_name/email"
echo "testuser" > "$PROFILE_DIR/$profile_name/username"
}

simulate_remove_profile() {
local profile_name=$1
local confirmation=$2
echo $confirmation | bash "$LIB_DIR/remove.sh" "$profile_name"
}

@test "Remove existing profile" {
create_test_profile "testProfile"
simulate_remove_profile "testProfile" "y"
[ ! -d "$PROFILE_DIR/testProfile" ]
}

@test "Fail to remove non-existent profile" {
run simulate_remove_profile "nonExistentProfile" "y"
[ "$status" -eq 1 ]
[[ "$output" == *"Error: Profile 'nonExistentProfile' does not exist."* ]]
}

@test "Cancel profile removal" {
create_test_profile "testProfile"
simulate_remove_profile "testProfile" "n"
[ -d "$PROFILE_DIR/testProfile" ]
}

0 comments on commit bacffde

Please sign in to comment.