-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix list command and create its test
- Loading branch information
Jakub Surdej
committed
Jan 23, 2024
1 parent
0575a48
commit 5a4c401
Showing
2 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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-list" | ||
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" | ||
} | ||
|
||
@test "List profiles when none exist" { | ||
run bash "$LIB_DIR/list.sh" | ||
[ "$status" -eq 1 ] | ||
[[ "$output" == "No profiles found." ]] | ||
} | ||
|
||
@test "List single profile" { | ||
create_test_profile "testProfile" | ||
run bash "$LIB_DIR/list.sh" | ||
[ "$status" -eq 0 ] | ||
[[ "$output" == *"Available profiles:"* ]] | ||
[[ "$output" == *" - testProfile"* ]] | ||
} | ||
|
||
@test "List multiple profiles" { | ||
create_test_profile "profileOne" | ||
create_test_profile "profileTwo" | ||
run bash "$LIB_DIR/list.sh" | ||
[ "$status" -eq 0 ] | ||
[[ "$output" == *"Available profiles:"* ]] | ||
[[ "$output" == *" - profileOne"* ]] | ||
[[ "$output" == *" - profileTwo"* ]] | ||
} |