Unverified Commit 2bca4891 authored by Jeremy Morrell's avatar Jeremy Morrell Committed by GitHub

Fix two issues with kvstore (#637)

parent 9fa61ce1
......@@ -45,9 +45,17 @@ kv_keys() {
local keys=()
if [[ -f $f ]]; then
# get list of keys
while IFS="=" read -r key value; do
# Iterate over each line, splitting on the '=' character
#
# The || [[ -n "$key" ]] statement addresses an issue with reading the last line
# of a file when there is no newline at the end. This will not happen if the file
# is created with this module, but can happen if it is written by hand.
# See: https://stackoverflow.com/questions/12916352/shell-script-read-missing-last-line
while IFS="=" read -r key value || [[ -n "$key" ]]; do
# if there are any empty lines in the store, skip them
if [[ -n $key ]]; then
keys+=("$key")
fi
done < "$f"
echo "${keys[@]}" | tr ' ' '\n' | sort -u
......
......@@ -108,6 +108,26 @@ testKeyValue() {
assertEquals "" "$(kv_list $store)"
}
testKeyValueNoNewLine() {
local store
# use a fixture that does not have an empty line after the final entry
store="$(pwd)/test/unit-fixtures/kvstore/no-new-line"
assertEquals "$(printf "%s\n" a=b b=c)" "$(kv_list $store)"
assertEquals "$(printf "%s\n" a b)" "$(kv_keys $store)"
}
testKeyValueEmptyLine() {
local store
# use a fixture that has an extra empty line
store="$(pwd)/test/unit-fixtures/kvstore/empty-line"
assertEquals "$(printf "%s\n" a=b b=c)" "$(kv_list $store)"
assertEquals "$(printf "%s\n" a b)" "$(kv_keys $store)"
}
testKeyValueEscaping() {
local store=$(mktemp)
......
a=b
b=c
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment