From b519a971e53c9c11136c33076cf7b7bcc4cef9d3 Mon Sep 17 00:00:00 2001 From: Felix Lohmeier Date: Tue, 4 Aug 2020 15:45:35 +0200 Subject: [PATCH] tests for templating; renamed to fit options exactly --- ...utf8.sh => create-txt-fixed-width-utf8.sh} | 0 ...txt-fixed.sh => create-txt-fixed-width.sh} | 0 tests/{template => new} | 0 tests/template-facets.sh | 58 +++++++++++++++++++ ...r-utf8.sh => template-filterQuery-utf8.sh} | 0 ...ting-filter.sh => template-filterQuery.sh} | 0 tests/template-splitToFiles-mode.sh | 58 +++++++++++++++++++ ... template-splitToFiles-suffixById-utf8.sh} | 0 ...sh => template-splitToFiles-suffixById.sh} | 0 ...-utf8.sh => template-splitToFiles-utf8.sh} | 0 ...ting-split.sh => template-splitToFiles.sh} | 0 .../{templating-utf8.sh => template-utf8.sh} | 0 tests/{templating.sh => template.sh} | 0 13 files changed, 116 insertions(+) rename tests/{create-txt-fixed-utf8.sh => create-txt-fixed-width-utf8.sh} (100%) rename tests/{create-txt-fixed.sh => create-txt-fixed-width.sh} (100%) rename tests/{template => new} (100%) create mode 100644 tests/template-facets.sh rename tests/{templating-filter-utf8.sh => template-filterQuery-utf8.sh} (100%) rename tests/{templating-filter.sh => template-filterQuery.sh} (100%) create mode 100644 tests/template-splitToFiles-mode.sh rename tests/{templating-split-id-utf8.sh => template-splitToFiles-suffixById-utf8.sh} (100%) rename tests/{templating-split-id.sh => template-splitToFiles-suffixById.sh} (100%) rename tests/{templating-split-utf8.sh => template-splitToFiles-utf8.sh} (100%) rename tests/{templating-split.sh => template-splitToFiles.sh} (100%) rename tests/{templating-utf8.sh => template-utf8.sh} (100%) rename tests/{templating.sh => template.sh} (100%) diff --git a/tests/create-txt-fixed-utf8.sh b/tests/create-txt-fixed-width-utf8.sh similarity index 100% rename from tests/create-txt-fixed-utf8.sh rename to tests/create-txt-fixed-width-utf8.sh diff --git a/tests/create-txt-fixed.sh b/tests/create-txt-fixed-width.sh similarity index 100% rename from tests/create-txt-fixed.sh rename to tests/create-txt-fixed-width.sh diff --git a/tests/template b/tests/new similarity index 100% rename from tests/template rename to tests/new diff --git a/tests/template-facets.sh b/tests/template-facets.sh new file mode 100644 index 0000000..e35e192 --- /dev/null +++ b/tests/template-facets.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +# =============================== ENVIRONMENT ================================ # + +if [[ ${1} ]]; then + cmd="${1}" +else + echo 1>&2 "execute tests.sh to run all tests"; exit 1 +fi + +t="$(basename "${BASH_SOURCE[0]}" .sh)" +cd "${BASH_SOURCE%/*}/" || exit 1 +mkdir -p "tmp/${t}" + +# =================================== DATA =================================== # + +cat << "DATA" > "tmp/${t}/${t}.csv" +email,name,state,gender,purchase +danny.baron@example1.com,Danny Baron,CA,M,TV +melanie.white@example2.edu,Melanie White,NC,F,iPhone +danny.baron@example1.com,D. Baron,CA,M,Winter jacket +ben.tyler@example3.org,Ben Tyler,NV,M,Flashlight +arthur.duff@example4.com,Arthur Duff,OR,M,Dining table +danny.baron@example1.com,Daniel Baron,CA,M,Bike +jean.griffith@example5.org,Jean Griffith,WA,F,Power drill +melanie.white@example2.edu,Melanie White,NC,F,iPad +ben.morisson@example6.org,Ben Morisson,FL,M,Amplifier +arthur.duff@example4.com,Arthur Duff,OR,M,Night table +DATA + +# ================================= ASSERTION ================================ # + +cat << "DATA" > "tmp/${t}/${t}.assert" +{ "events" : [ + { "name" : "Melanie White", "purchase" : "iPhone" }, + { "name" : "Jean Griffith", "purchase" : "Power drill" }, + { "name" : "Melanie White", "purchase" : "iPad" } +] } +DATA + +# ================================== ACTION ================================== # + +${cmd} --create "tmp/${t}/${t}.csv" +${cmd} --export "${t}" \ +--prefix '{ "events" : [ +' \ +--template ' { "name" : {{jsonize(cells["name"].value)}}, "purchase" : {{jsonize(cells["purchase"].value)}} }' \ +--rowSeparator ', +' \ +--suffix ' +] } +' \ +--facets '{"type":"list","name":"gender","columnName":"gender","expression":"value","omitBlank":false,"omitError":false,"selection":[{"v":{"v":"F","l":"F"}}],"selectBlank":false,"selectError":false,"invert":false}' \ +--output "tmp/${t}/${t}.output" + +# =================================== TEST =================================== # + +diff -u "tmp/${t}/${t}.assert" "tmp/${t}/${t}.output" diff --git a/tests/templating-filter-utf8.sh b/tests/template-filterQuery-utf8.sh similarity index 100% rename from tests/templating-filter-utf8.sh rename to tests/template-filterQuery-utf8.sh diff --git a/tests/templating-filter.sh b/tests/template-filterQuery.sh similarity index 100% rename from tests/templating-filter.sh rename to tests/template-filterQuery.sh diff --git a/tests/template-splitToFiles-mode.sh b/tests/template-splitToFiles-mode.sh new file mode 100644 index 0000000..9f999e5 --- /dev/null +++ b/tests/template-splitToFiles-mode.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +# =============================== ENVIRONMENT ================================ # + +if [[ ${1} ]]; then + cmd="${1}" +else + echo 1>&2 "execute tests.sh to run all tests"; exit 1 +fi + +t="$(basename "${BASH_SOURCE[0]}" .sh)" +cd "${BASH_SOURCE%/*}/" || exit 1 +mkdir -p "tmp/${t}" + +# =================================== DATA =================================== # + +cat << "DATA" > "tmp/${t}/${t}.csv" +email,name,state,gender,purchase +arthur.duff@example4.com,Arthur Duff,OR,M,Dining table +,Arthur Duff,OR,M,Night table +ben.morisson@example6.org,Ben Morisson,FL,M,Amplifier +ben.tyler@example3.org,Ben Tyler,NV,M,Flashlight +danny.baron@example1.com,Daniel Baron,CA,M,Bike +,Danny Baron,CA,M,TV +,D. Baron,CA,M,Winter jacket +jean.griffith@example5.org,Jean Griffith,WA,F,Power drill +melanie.white@example2.edu,Melanie White,NC,F,iPad +,Melanie White,NC,F,iPhone +DATA + +# ================================= ASSERTION ================================ # + +cat << "DATA" > "tmp/${t}/${t}.assert" +{ "events" : [ + { "name" : "Melanie White", "purchase" : "iPad" } { "name" : "Melanie White", "purchase" : "iPhone" } +] } +DATA + +# ================================== ACTION ================================== # + +${cmd} --create "tmp/${t}/${t}.csv" +${cmd} --export "${t}" \ +--prefix '{ "events" : [ +' \ +--template ' { "name" : {{jsonize(cells["name"].value)}}, "purchase" : {{jsonize(cells["purchase"].value)}} }' \ +--rowSeparator ', +' \ +--suffix ' +] } +' \ +--mode "record-based" \ +--splitToFiles true \ +--output "tmp/${t}/${t}.output" + +# =================================== TEST =================================== # + +ls "tmp/${t}" +diff -u "tmp/${t}/${t}.assert" "tmp/${t}/${t}_6.output" diff --git a/tests/templating-split-id-utf8.sh b/tests/template-splitToFiles-suffixById-utf8.sh similarity index 100% rename from tests/templating-split-id-utf8.sh rename to tests/template-splitToFiles-suffixById-utf8.sh diff --git a/tests/templating-split-id.sh b/tests/template-splitToFiles-suffixById.sh similarity index 100% rename from tests/templating-split-id.sh rename to tests/template-splitToFiles-suffixById.sh diff --git a/tests/templating-split-utf8.sh b/tests/template-splitToFiles-utf8.sh similarity index 100% rename from tests/templating-split-utf8.sh rename to tests/template-splitToFiles-utf8.sh diff --git a/tests/templating-split.sh b/tests/template-splitToFiles.sh similarity index 100% rename from tests/templating-split.sh rename to tests/template-splitToFiles.sh diff --git a/tests/templating-utf8.sh b/tests/template-utf8.sh similarity index 100% rename from tests/templating-utf8.sh rename to tests/template-utf8.sh diff --git a/tests/templating.sh b/tests/template.sh similarity index 100% rename from tests/templating.sh rename to tests/template.sh