@ -20,6 +20,7 @@ function teardown {
@test "run 'add' normally" {
# Preparations:
local filename="local_file"
echo "content" > "$filename"
echo "$filename" > ".gitignore"
@ -27,41 +28,42 @@ function teardown {
run git secret add "$filename"
[ "$status" -eq 0 ]
rm -f "$filename" ".gitignore"
# Ensuring that path mappings was set correctly:
local path_mappings
path_mappings=$(_get_secrets_dir_paths_mapping)
local files_list=$(cat "$path_mappings")
[ "$files_list" = "$filename" ]
# Cleaning up:
rm "$filename" ".gitignore"
}
@test "run 'add' for unignored file" {
local TEST_FILE ='test_file'
touch "$TEST_FILE "
echo "content" > "$TEST_FILE "
local test_file ='test_file'
touch "$test_file "
echo "content" > "$test_file "
run git secret add "$TEST_FILE "
run git secret add "$test_file "
[ "$status" -eq 1 ]
rm "$TEST_FILE "
rm "$test_file "
}
@test "run 'add' for unignored file with '-i'" {
local TEST_FILE ='test_file.auto_ignore'
touch "$TEST_FILE "
echo "content" > "$TEST_FILE "
local test_file ='test_file.auto_ignore'
touch "$test_file "
echo "content" > "$test_file "
run git secret add -i "$TEST_FILE "
run git secret add -i "$test_file "
[ "$status" -eq 0 ]
run _file_has_line "$TEST_FILE " ".gitignore"
run _file_has_line "$test_file " ".gitignore"
[ "$status" -eq 0 ]
rm "$TEST_FILE "
rm "$test_file "
}
@ -81,15 +83,15 @@ function teardown {
mkdir -p "$nested_dir"
cd "$nested_dir"
local TEST_FILE ='test_file.auto_ignore'
touch "$TEST_FILE "
echo "content" > "$TEST_FILE "
local test_file ='test_file.auto_ignore'
touch "$test_file "
echo "content" > "$test_file "
# Test commands:
run git secret add -i "$TEST_FILE "
run git secret add -i "$test_file "
[ "$status" -eq 0 ]
run _file_has_line "$TEST_FILE " "../.gitignore"
run _file_has_line "$test_file " "../.gitignore"
[ "$status" -eq 0 ]
# .gitignore was not created:
@ -101,36 +103,75 @@ function teardown {
}
@test "run 'add' for relative path" {
if [[ "$BATS_RUNNING_FROM_GIT" -eq 1 ]]; then
skip "this test is skiped while 'git commmit'"
fi
# Prepations:
local root='test_dir'
local node="$root/node"
local sibling="$root/sibling"
local test_file="$node/test_file"
local current_dir=$(pwd)
mkdir -p "$node"
mkdir -p "$sibling"
echo "content" > "$test_file"
echo "$test_file" > ".gitignore"
cd "$sibling"
# Testing:
run git secret add "../node/test_file"
[ "$status" -eq 0 ]
[[ "$output" == *"1 item(s) added."* ]]
# Testing mappings content:
local path_mappings
path_mappings=$(_get_secrets_dir_paths_mapping)
local files_list=$(cat "$path_mappings")
[ "$files_list" = "$test_file" ]
# Cleaning up:
cd "$current_dir"
rm -r "$root"
}
@test "run 'add' for file in subfolder" {
local TEST_FILE='test_file'
local TEST_DIR='test_dir'
# Preparations:
local test_file='test_file'
local test_dir='test_dir'
mkdir -p "$TEST_DIR"
touch "$TEST_DIR/$TEST_FILE"
echo "content" > "$TEST_DIR/$TEST_FILE"
echo "$TEST_DIR/$TEST_FILE" > ".gitignore"
mkdir -p "$test_dir "
touch "$test_dir/$test_file "
echo "content" > "$test_dir/$test_file "
echo "$test_dir/$test_file " > ".gitignore"
run git secret add "$TEST_DIR/$TEST_FILE"
# Testing:
run git secret add "$test_dir/$test_file"
[ "$status" -eq 0 ]
[[ "$output" == *"1 items added."* ]]
[[ "$output" == *"1 item( s) added."* ]]
rm -r "$TEST_DIR"
# Cleaning up:
rm -r "$test_dir"
}
@test "run 'add' twice for one file" {
# Preparations:
local filename="local_file"
echo "content" > "$filename"
echo "$filename" > ".gitignore"
# Testing:
run git secret add "$filename"
run git secret add "$filename"
[ "$status" -eq 0 ]
echo "$output"
echo "dance"
[ "$output" = "1 items added." ]
rm "$filename" ".gitignore"
[ "$output" = "1 item(s) added." ]
# Ensuring that path mappings was set correctly:
local path_mappings
@ -138,10 +179,14 @@ function teardown {
local files_list=$(cat "$path_mappings")
[ "$files_list" = "$filename" ]
# Cleaning up:
rm "$filename" ".gitignore"
}
@test "run 'add' for multiple files" {
# Preparations:
local filename1="local_file1"
echo "content1" > "$filename1"
echo "$filename1" > ".gitignore"
@ -150,9 +195,11 @@ function teardown {
echo "content2" > "$filename2"
echo "$filename2" >> ".gitignore"
# Testing:
run git secret add "$filename1" "$filename2"
[ "$status" -eq 0 ]
[ "$output" = "2 items added." ]
[ "$output" = "2 item( s) added." ]
# Cleaning up:
rm "$filename1" "$filename2" ".gitignore"
}