Files
macos-system/spec/answerQuestionsFromConfigOrAskUser_spec.sh
2022-02-14 17:22:25 +01:00

79 lines
2.8 KiB
Bash

Describe 'answerQuestionsFromConfigOrAskUser'
Include ./install.sh
lop setoutput -l panic tostdout
mod="testmod"
It 'does nothing if module has no questions'
declare -A questions=()
When call answerQuestionsFromConfigOrAskUser
The output should eq ''
The variable 'questions' should eq ''
The status should be success
End
It 'asks the user if the question is not in the config'
declare -A questions=([question-one]=$'What is your favorite color?\ninfo')
Data 'blue'
config() {}
When call answerQuestionsFromConfigOrAskUser
The output should eq "What is your favorite color? "
The status should be success
End
It 'does not ask the user if the question is stored in the config'
declare -A questions=([question-one]=$'What is your favorite color?\ninfo')
config() { [ "${1}" = read ] && echo red; }
When call answerQuestionsFromConfigOrAskUser
The output should eq ''
The status should be success
End
It 'stores the answer in the answers array if asking user'
declare -A answers
declare -A questions=([question-one]=$'What is your favorite color?\ninfo')
config() {}
Data 'blue'
When call answerQuestionsFromConfigOrAskUser
The output should eq "What is your favorite color? "
The variable "answers[${mod}_question-one]" should eq 'blue'
The status should be success
End
It 'stores the answer in the answers array if retrieving from config'
declare -A answers
declare -A questions=([question-one]=$'What is your favorite color?\ninfo')
config() { [ "${1}" = read ] && echo red; }
When call answerQuestionsFromConfigOrAskUser
The output should eq ''
The variable "answers[${mod}_question-one]" should eq 'red'
The status should be success
End
It 'does not store the user answer to config'
declare -A answers
declare -A questions=([question-one]=$'What is your favorite color?\ninfo')
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 ''
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