From 713d994ff16f7773c0b88ca86d2a533efcd27db4 Mon Sep 17 00:00:00 2001 From: Rezart Qelibari Date: Mon, 14 Feb 2022 13:38:42 +0100 Subject: [PATCH] Write config only in config-only mode --- install.sh | 2 +- .../answerQuestionsFromConfigOrAskUser_spec.sh | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index e5301ad..3306f99 100755 --- a/install.sh +++ b/install.sh @@ -177,7 +177,7 @@ function answerQuestionsFromConfigOrAskUser() { lop debug 'Asking user' askUserQuestion lop debug "User answer is: ${value}" - config write "${value}" "${configkeys[@]}" + [ -n "${config_only}" ] && config write "${value}" "${configkeys[@]}" fi lop debug "Adding answer: ${mod}_${questionID}=${value}" answers+=("${mod}_${questionID}" "${value}") diff --git a/spec/answerQuestionsFromConfigOrAskUser_spec.sh b/spec/answerQuestionsFromConfigOrAskUser_spec.sh index 66a86ff..b681e5d 100644 --- a/spec/answerQuestionsFromConfigOrAskUser_spec.sh +++ b/spec/answerQuestionsFromConfigOrAskUser_spec.sh @@ -49,7 +49,7 @@ Describe 'answerQuestionsFromConfigOrAskUser' The status should be success End - It 'stores the user answer to config' + It 'does not store the user answer to config' declare -A answers declare -A questions=([question-one]=$'What is your favorite color?\ninfo') writtenValue="" @@ -58,7 +58,21 @@ Describe 'answerQuestionsFromConfigOrAskUser' When call answerQuestionsFromConfigOrAskUser The output should eq "What is your favorite color? " The variable "answers[${mod}_question-one]" should eq 'red' - Assert test "${writtenValue}" = 'red' + The variable writtenValue should eq '' + The status should be success + End + + It 'does store the user answer to config in config-only mode' + declare -A answers + declare -A questions=([question-one]=$'What is your favorite color?\ninfo') + config_only="yes" + writtenValue="" + Data 'red' + config() { [ "${1}" = read ] && return; [ "${1}" = write ] && writtenValue="${2}" } + When call answerQuestionsFromConfigOrAskUser + The output should eq "What is your favorite color? " + The variable "answers[${mod}_question-one]" should eq 'red' + The variable writtenValue should eq 'red' The status should be success End End