Write config only in config-only mode

This commit is contained in:
Rezart Qelibari
2022-02-14 13:38:42 +01:00
parent 1011552725
commit 713d994ff1
2 changed files with 17 additions and 3 deletions

View File

@@ -177,7 +177,7 @@ function answerQuestionsFromConfigOrAskUser() {
lop debug 'Asking user' lop debug 'Asking user'
askUserQuestion askUserQuestion
lop debug "User answer is: ${value}" lop debug "User answer is: ${value}"
config write "${value}" "${configkeys[@]}" [ -n "${config_only}" ] && config write "${value}" "${configkeys[@]}"
fi fi
lop debug "Adding answer: ${mod}_${questionID}=${value}" lop debug "Adding answer: ${mod}_${questionID}=${value}"
answers+=("${mod}_${questionID}" "${value}") answers+=("${mod}_${questionID}" "${value}")

View File

@@ -49,7 +49,7 @@ Describe 'answerQuestionsFromConfigOrAskUser'
The status should be success The status should be success
End End
It 'stores the user answer to config' It 'does not store the user answer to config'
declare -A answers declare -A answers
declare -A questions=([question-one]=$'What is your favorite color?\ninfo') declare -A questions=([question-one]=$'What is your favorite color?\ninfo')
writtenValue="" writtenValue=""
@@ -58,7 +58,21 @@ Describe 'answerQuestionsFromConfigOrAskUser'
When call answerQuestionsFromConfigOrAskUser When call answerQuestionsFromConfigOrAskUser
The output should eq "What is your favorite color? " The output should eq "What is your favorite color? "
The variable "answers[${mod}_question-one]" should eq 'red' 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 The status should be success
End End
End End