Skip to content

Commit

Permalink
optimize ut to verify bom header
Browse files Browse the repository at this point in the history
  • Loading branch information
dsdashun committed Jan 29, 2023
1 parent de2faf1 commit 9749703
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE TABLE testtbl (
id INTEGER,
val1 VARCHAR(40) NOT NULL,
INDEX `idx_val1` (`val1`)
);
6 changes: 6 additions & 0 deletions br/tests/lightning_bom_file/original_data/mytest.testtbl.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
id,val1
1,"aaa01"
2,"aaa01"
3,"aaa02"
4,"aaa02"
5,"aaa05"
20 changes: 19 additions & 1 deletion br/tests/lightning_bom_file/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,25 @@ set -eux

mydir=$(dirname "${BASH_SOURCE[0]}")

data_file="${mydir}/data/mytest.testtbl.csv"
original_schema_file="${mydir}/original_data/mytest.testtbl-schema.sql"
original_data_file="${mydir}/original_data/mytest.testtbl.csv"
schema_file="${original_schema_file/original_data/data}"
data_file="${original_data_file/original_data/data}"

# add the BOM header
printf '\xEF\xBB\xBF' | cat - <( sed '1s/^\xEF\xBB\xBF//' "${original_schema_file}" ) > "${schema_file}"
printf '\xEF\xBB\xBF' | cat - <( sed '1s/^\xEF\xBB\xBF//' "${original_data_file}" ) > "${data_file}"

# verify the BOM header
if ! [[ $(xxd -p "${schema_file}" | head -c 6 ) == "efbbbf" ]]; then
echo "schema file doesn't contain the BOM header" >&2
exit 1
fi

if ! [[ $(xxd -p "${data_file}" | head -c 6 ) == "efbbbf" ]]; then
echo "data file doesn't contain the BOM header" >&2
exit 1
fi

row_count=$( sed '1d' "${data_file}" | wc -l | xargs echo )

Expand Down

0 comments on commit 9749703

Please sign in to comment.