Skip to content

Commit 9be886b

Browse files
committed
add tests for file_fill_template function
1 parent 21ae6e6 commit 9be886b

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

test/file.bats

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,38 @@ load "test-helper"
203203
assert_equal "$expected" "$actual"
204204

205205
rm -f "$tmp_file"
206-
}
206+
}
207+
208+
@test "file_fill_template non empty file, nothing to replace" {
209+
local -r tmp_file=$(mktemp)
210+
local -ar auto_fill=("<__PLACEHOLDER__>=hello")
211+
local -r file_contents=$(echo -e "abc\nhey world\nbaz")
212+
213+
echo "$file_contents" > "$tmp_file"
214+
215+
run file_fill_template "$tmp_file" "${auto_fill[@]}"
216+
assert_success
217+
218+
local -r actual=$(cat "$tmp_file")
219+
local -r expected=$file_contents
220+
assert_equal "$expected" "$actual"
221+
222+
rm -f "$tmp_file"
223+
}
224+
225+
@test "file_fill_template non empty file, replace text" {
226+
local -r tmp_file=$(mktemp)
227+
local -ar auto_fill=("<__PLACEHOLDER__>=hello")
228+
local -r file_contents=$(echo -e "abc\n<__PLACEHOLDER__> world\nbaz")
229+
230+
echo "$file_contents" > "$tmp_file"
231+
232+
run file_fill_template "$tmp_file" "${auto_fill[@]}"
233+
assert_success
234+
235+
local -r actual=$(cat "$tmp_file")
236+
local -r expected=$(echo -e "abc\nhello world\nbaz")
237+
assert_equal "$expected" "$actual"
238+
239+
rm -f "$tmp_file"
240+
}

0 commit comments

Comments
 (0)