Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
feudalScripts
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
feudal
feudalScripts
Commits
15164ca0
Commit
15164ca0
authored
May 02, 2020
by
lukas.burgey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix answer checking in stubScript
parent
86276497
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
12 deletions
+34
-12
stubScript/stub-script.go
stubScript/stub-script.go
+34
-12
No files found.
stubScript/stub-script.go
View file @
15164ca0
package
main
import
(
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"reflect"
"time"
scripts
"git.scc.kit.edu/feudal/feudalScripts/v3"
...
...
@@ -49,13 +49,41 @@ func deploy(input scripts.Input) (output scripts.Output, err error) {
}
func
questionnaire
(
input
scripts
.
Input
)
(
output
scripts
.
Output
,
err
error
)
{
qa
:=
map
[
string
]
interface
{}{
"question_name"
:
"question"
,
// string default value
"age_question"
:
18
,
// age_question must be an integer, defaulting to 18
"list_question"
:
[]
string
{
"person_a"
,
"person_b"
},
// list_question must be one of the listed options
"list_question_2"
:
[]
int
{
1
,
2
},
// list_question_2 must be one of the listed options
"are_you_sure"
:
false
,
// are_you_sure must be a boolean, with false being the default value
}
time
.
Sleep
(
time
.
Second
)
if
input
.
Answers
!=
nil
{
_
,
fooOK
:=
input
.
Answers
[
"Question-Foo"
]
_
,
barOK
:=
input
.
Answers
[
"Question-Bar"
]
missing
:=
false
falseType
:=
false
// check Answers against QuestionnaireAnswers
for
key
,
qAnswer
:=
range
qa
{
if
answer
,
ok
:=
input
.
Answers
[
key
];
ok
{
//check type of answer against reference
var
referenceAnswer
interface
{}
if
qaList
,
ok
:=
qAnswer
.
([]
interface
{});
ok
{
referenceAnswer
=
qaList
[
0
]
}
else
{
referenceAnswer
=
qaList
}
if
reflect
.
TypeOf
(
referenceAnswer
)
!=
reflect
.
TypeOf
(
answer
)
{
falseType
=
true
break
}
}
else
{
missing
=
true
break
}
}
if
fooOK
&&
barOK
{
if
!
missing
||
!
falseType
{
output
.
State
=
scripts
.
Deployed
output
.
Msg
=
"I got all the answers"
return
...
...
@@ -70,13 +98,7 @@ func questionnaire(input scripts.Input) (output scripts.Output, err error) {
"list_question_2"
:
"How many do you want?"
,
"are_you_sure"
:
"What you are trying is wrong. Are you sure?"
,
}
output
.
QuestionnaireAnswers
=
map
[
string
]
interface
{}{
"question_name"
:
"question"
,
// string default value
"age_question"
:
18
,
// age_question must be an integer, defaulting to 18
"list_question"
:
[]
string
{
"person_a"
,
"person_b"
},
// list_question must be one of the listed options
"list_question_2"
:
[]
int
{
1
,
2
},
// list_question_2 must be one of the listed options
"are_you_sure"
:
false
,
// are_you_sure must be a boolean, with false being the default value
}
output
.
QuestionnaireAnswers
=
qa
return
}
...
...
@@ -146,6 +168,6 @@ func main() {
}
}
outputBytes
,
err
:=
json
.
MarshalIndent
(
output
,
""
,
" "
)
outputBytes
,
err
:=
output
.
Marshal
(
)
fmt
.
Fprintf
(
os
.
Stdout
,
"%s"
,
outputBytes
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment