Use loadModules and askUserModuleQuestions

This commit is contained in:
Rezart Qelibari
2022-03-08 12:42:48 +01:00
parent 79693877b2
commit 322a2aa757
14 changed files with 77 additions and 628 deletions

View File

@@ -1,78 +0,0 @@
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

View File

@@ -1,6 +1,7 @@
Describe 'askNecessaryQuestions'
Include ./install.sh
lop setoutput -l panic tostdout
askUserModuleQuestions() {}
It 'sets config app name'
appname=''
@@ -9,7 +10,7 @@ Describe 'askNecessaryQuestions'
The variable 'appname' should eq 'de.astzweig.macos.system-setup'
End
It 'sets config file path'
It 'sets config file path in config_only mode'
configpath=''
config() { [ "$1" = setconfigfile ] && configpath="$2" }
config_only='/my/file/path'
@@ -17,15 +18,11 @@ Describe 'askNecessaryQuestions'
The variable 'configpath' should eq '/my/file/path'
End
It 'writes config to given file'
declare -A answers
config_only="`mktemp`"
modulesToInstall=('mymodule')
populateQuestionsWithModuleRequiredInformation() { questions+=('my-question' $'What is my question?\ninfo') }
readConfig() { config read mymodule questions my_question }
Data 'myanswer'
It 'sets config file path in if -c option is given'
configpath=''
config() { [ "$1" = setconfigfile ] && configpath="$2" }
config='/my/file/path'
When call askNecessaryQuestions
The variable answers should eq 'myanswer'
The result of function readConfig should eq 'myanswer'
The variable 'configpath' should eq '/my/file/path'
End
End

View File

@@ -1,71 +0,0 @@
Describe 'convertQuestionArgsToAskUserArgs'
Include ./install.sh
It 'converts info to info'
args=()
choices=()
questionArgs='info'
When call convertQuestionArgsToAskUserArgs
The output should eq ''
The variable args should eq 'info'
The variable choices should eq ''
The status should be success
End
It 'converts info with default arg to info with default arg'
args=()
choices=()
questionArgs='info;default:Mario Kart'
When call convertQuestionArgsToAskUserArgs
The output should eq ''
The variable args should eq '-d Mario Kart info'
The variable choices should eq ''
The status should be success
End
It 'converts password to -p info'
args=() choices=() questionArgs='password'
When call convertQuestionArgsToAskUserArgs
The variable args should eq '-p info'
The variable choices should eq ''
End
It 'converts confirm to confirm'
args=() choices=() questionArgs='confirm'
When call convertQuestionArgsToAskUserArgs
The variable args should eq 'confirm'
The variable choices should eq ''
End
It 'returns if type is select but no choose from arg is provided'
args=() choices=() questionArgs='select'
When call convertQuestionArgsToAskUserArgs
The variable args should eq ''
The variable choices should eq ''
The status should eq 10
End
It 'converts select to choose'
args=() choices=() questionArgs='select;choose from:blue,light green,red'
When call convertQuestionArgsToAskUserArgs
The variable args should eq 'choose'
The variable choices should eq 'blue light green red'
The variable '#choices' should eq 3
End
It 'converts validator to -v option for choose'
args=() choices=() questionArgs='select;validator:is_file;choose from:blue,light green,red'
When call convertQuestionArgsToAskUserArgs
The variable args should eq 'choose -v is_file'
The variable choices should eq 'blue light green red'
The variable '#choices' should eq 3
End
It 'finds choose from arg even if many args are provided'
args=() choices=() questionArgs='select;first arg:red;choose from:blue,light green,red;after arg:nine;after arg:nine;'
When call convertQuestionArgsToAskUserArgs
The variable args should eq 'choose'
The variable choices should eq 'blue light green red'
The variable '#choices' should eq 3
End
End

View File

@@ -1,36 +0,0 @@
Describe 'filterModules'
Include ./install.sh
lop setoutput -l panic tostdout
It 'returns all modules if no module arg is given'
allModules=(module1 module2 'module3 with space') modulesToInstall=()
When call filterModules
The variable modulesToInstall should eq 'module1 module2 module3 with space'
The status should be success
End
It 'returns only mentioned modules'
allModules=(module1 module2 'module3 with space') modulesToInstall=()
module=('module3 with space' module2)
When call filterModules
The variable modulesToInstall should eq 'module2 module3 with space'
The status should be success
End
It 'matches modules by ending pattern'
allModules=(dir1/module1 dir2/module1 /dir/module1/'module3 with space') modulesToInstall=()
module=(module1)
When call filterModules
The variable modulesToInstall should eq 'dir1/module1 dir2/module1'
The status should be success
End
It 'returns only not mentioned modules if inversed'
allModules=(module1 module2 'module3 with space') modulesToInstall=()
module=('module3 with space' module1)
inverse=true
When call filterModules
The variable modulesToInstall should eq 'module2'
The status should be success
End
End

View File

@@ -1,40 +0,0 @@
Describe 'findQuestionArgInInstruction'
Include ./install.sh
instructions=('somearg:somevalue' 'default:one' 'choose from:blue,light green,red')
It 'finds nothing if no arg name given'
argValue=''
When call findQuestionArgInInstruction
The variable argValue should eq ''
The status should be success
End
It 'finds nothing if arg name does not exist'
argValue=''
When call findQuestionArgInInstruction 'arg name that does not exist'
The variable argValue should eq ''
The status should be failure
End
It 'finds nothing if instructions is empty'
instructions=()
argValue=''
When call findQuestionArgInInstruction 'some arg name'
The variable argValue should eq ''
The status should be failure
End
It 'finds arg value if instructions contains arg as first item'
argValue=''
When call findQuestionArgInInstruction 'somearg'
The variable argValue should eq 'somevalue'
The status should be success
End
It 'finds arg value if instructions contains arg among other items'
argValue=''
When call findQuestionArgInInstruction 'choose from'
The variable argValue should eq 'blue,light green,red'
The status should be success
End
End

View File

@@ -1,59 +0,0 @@
Describe 'generateConfigKeysFromQuestionID'
Include ./install.sh
It 'does nothing if given no arguments'
declare -A configkeys=()
When call generateConfigKeysFromQuestionID ''
The output should eq ''
The variable 'configkeys' should eq ''
The status should be success
End
It 'does nothing if question id is empty'
declare configkeys=()
When call generateConfigKeysFromQuestionID 'somemod' ''
The output should eq ''
The variable 'configkeys' should eq ''
The status should be success
End
It 'generates key when given module name and question id'
declare configkeys=()
When call generateConfigKeysFromQuestionID 'somemod' 'somekey'
The output should eq ''
The variable 'configkeys' should eq 'somemod questions somekey'
The status should be success
End
It 'replaces minus with underscore'
declare configkeys=()
When call generateConfigKeysFromQuestionID 'some-mod' 'somekey'
The output should eq ''
The variable 'configkeys' should eq 'some_mod questions somekey'
The status should be success
End
It 'replaces multiple minus with single underscore'
declare configkeys=()
When call generateConfigKeysFromQuestionID 'some---mod' 'so--mekey'
The output should eq ''
The variable 'configkeys' should eq 'some_mod questions so_mekey'
The status should be success
End
It 'replaces underscores at the begin and end of string'
declare configkeys=()
When call generateConfigKeysFromQuestionID '--some-mod' '--somekey-'
The output should eq ''
The variable 'configkeys' should eq 'some_mod questions somekey'
The status should be success
End
It 'removes all chars but [A-Za-z_]'
declare configkeys=()
When call generateConfigKeysFromQuestionID '*some≠{mod' '?`somekey'
The output should eq ''
The variable 'configkeys' should eq 'somemod questions somekey'
The status should be success
End
End

View File

@@ -2,7 +2,7 @@ Describe 'generateModuleOptions'
Include ./install.sh
It 'does nothing if answers array is empty'
declare -A answers=()
declare -A moduleAnswers=()
moduleOptions=()
When call generateModuleOptions
The output should eq ''
@@ -11,7 +11,7 @@ Describe 'generateModuleOptions'
End
It 'does nothing if answers does not contain module answers'
declare -A answers=('some-module_name' 'answer')
declare -A moduleAnswers=('some-module_name' 'answer')
mod='module/my-module'
moduleOptions=()
When call generateModuleOptions
@@ -21,7 +21,7 @@ Describe 'generateModuleOptions'
End
It 'prefixes single char option names with a dash'
declare -A answers=('mymodule_n' 'my name')
declare -A moduleAnswers=('mymodule_n' 'my name')
mod='mymodule'
moduleOptions=()
When call generateModuleOptions
@@ -31,7 +31,7 @@ Describe 'generateModuleOptions'
End
It 'does not prefix single char option name with dash if it is already a dash'
declare -A answers=('mymodule_-' 'my name')
declare -A moduleAnswers=('mymodule_-' 'my name')
mod='mymodule'
moduleOptions=()
When call generateModuleOptions
@@ -41,7 +41,7 @@ Describe 'generateModuleOptions'
End
It 'prefixes multi char option names with double dash'
declare -A answers=('mymodule_your-name' 'my name')
declare -A moduleAnswers=('mymodule_your-name' 'my name')
mod='mymodule'
moduleOptions=()
When call generateModuleOptions
@@ -51,7 +51,7 @@ Describe 'generateModuleOptions'
End
It 'does not prefix multi char option names with double dash if it starts with a dash'
declare -A answers=('mymodule_-your-name' 'my name')
declare -A moduleAnswers=('mymodule_-your-name' 'my name')
mod='mymodule'
moduleOptions=()
When call generateModuleOptions
@@ -61,7 +61,7 @@ Describe 'generateModuleOptions'
End
It 'works with modules that contains slashes'
declare -A answers=('/some/dir/mymodule_your-name' 'my name')
declare -A moduleAnswers=('/some/dir/mymodule_your-name' 'my name')
mod='/some/dir/mymodule'
moduleOptions=()
When call generateModuleOptions
@@ -71,7 +71,7 @@ Describe 'generateModuleOptions'
End
It 'works with modules that contains spaces'
declare -A answers=('/some/dir with spaces/mymodule with spaces_your-name' 'my name')
declare -A moduleAnswers=('/some/dir with spaces/mymodule with spaces_your-name' 'my name')
mod='/some/dir with spaces/mymodule with spaces'
moduleOptions=()
When call generateModuleOptions

View File

@@ -1,10 +1,11 @@
Describe 'installModules'
Include ./install.sh
lop setoutput -l panic tostdout
output=()
runModule() { output=("$@") }
It 'does nothing if modules array is empty'
declare -A modulesToInstall=() answers=()
declare -A modulesToInstall=() moduleAnswers=()
called=false
generateModuleOptions() { called=true }
When call installModules
@@ -14,7 +15,7 @@ Describe 'installModules'
End
It 'calls the module without options if answers is empty'
declare -A answers=()
declare -A moduleAnswers=()
modulesToInstall=('/modules/my module')
When call installModules
The output should eq ''
@@ -23,7 +24,7 @@ Describe 'installModules'
End
It 'calls the module with given answers as options'
declare -A answers=('/modules/my module_name' 'hercules')
declare -A moduleAnswers=('/modules/my module_name' 'hercules')
modulesToInstall=('/modules/my module')
When call installModules
The output should eq ''

View File

@@ -1,97 +0,0 @@
Describe 'parseQuestionLine'
Include ./install.sh
It 'does nothing if the line is empty'
line=''
When call parseQuestionLine
The output should eq ''
The status should be success
End
It 'does nothing if the line does not have a question type'
line='some value here'
When call parseQuestionLine
The output should eq ''
The status should eq 10
End
It 'does nothing if the line does not have a valid question type'
line='z: some value here'
When call parseQuestionLine
The output should eq ''
The status should eq 11
End
It 'does nothing if the line does not have a parameter name'
line='i: '
When call parseQuestionLine
The output should eq ''
The status should eq 12
End
It 'does nothing if the parameter name starts with a dash'
line='i: -parameter-name=Is this my question?'
When call parseQuestionLine
The output should eq ''
The status should eq 13
End
It 'does nothing if the line does not have a question'
line='i: parameter-name='
When call parseQuestionLine
The output should eq ''
The status should eq 14
End
It 'extends outer questions associative array with question'
declare -A questions
line='i: parameter-name=What parameter do you like? #'
When call parseQuestionLine
The output should eq ''
The line 1 of variable 'questions[parameter-name]' should eq 'What parameter do you like?'
The line 2 of variable 'questions[parameter-name]' should eq info
The status should be success
End
It 'ignores empty arguments'
declare -A questions
line='i: parameter-name=What parameter do you like? # some arg: some value;;'
When call parseQuestionLine
The output should eq ''
The line 1 of variable 'questions[parameter-name]' should eq 'What parameter do you like?'
The status should eq 0
End
It 'does nothing if an argument does not contain a name'
declare -A questions
line='i: parameter-name=What parameter do you like? # some arg: some value;:some value;'
When call parseQuestionLine
The output should eq ''
The variable 'questions' should eq ''
The status should eq 15
End
It 'writes question type to outer questions associative array'
declare -A questions
line='s: parameter-name=What parameter do you like? # choose from: blue,red,light green; default: blue'
When call parseQuestionLine
The line 2 of variable 'questions[parameter-name]' should eq 'select;choose from:blue,red,light green;default:blue'
End
End
Describe "parseQuestionLine type renaming"
Include ./install.sh
Parameters
i info
p password
c confirm
s select
End
It "converts $1 to $2"
declare -A questions
line="${1}: parameter-name=What parameter do you like? #"
When call parseQuestionLine
The line 2 of variable 'questions[parameter-name]' should eq "$2"
End
End