Skip to content

Commit

Permalink
Fix list command 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 0575a48 commit 5a4c401
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/list.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
48 changes: 48 additions & 0 deletions tests/list_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-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"* ]]
}

0 comments on commit 5a4c401

Please sign in to comment.