Skip to content

Commit d10c1c7

Browse files
grussorussomatnar
andcommitted
Avoid workaround to accept non-matching input-output names
Co-authored-by: Matteo Nardelli <matnar@gmail.com>
1 parent 1b4deb7 commit d10c1c7

12 files changed

Lines changed: 74 additions & 90 deletions

examples/double.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
def handler(params, context):
2-
return int(params["input"]) * 2
2+
return int(params["n"]) * 2

examples/inc.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function handler(params, context) {
22
console.log(params);
3-
console.log("" + params["input"]);
4-
return parseInt(params["input"], 10) + 1
3+
console.log("" + params["n"]);
4+
return parseInt(params["n"], 10) + 1
55
}
66

7-
module.exports = handler;
7+
module.exports = handler;

examples/inc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
def handler(params, context):
22
print(f"Invoked inc with input: {params}")
3-
return int(params["input"]) + 1
3+
return int(params["n"]) + 1

examples/workflow-with-choice-task.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
"Type": "Choice",
1313
"Choices": [
1414
{
15-
"Variable": "$.result",
15+
"Variable": "$.n",
1616
"NumericLessThan": 10,
1717
"Next": "BranchOneSecondState"
1818
},
1919
{
20-
"Variable": "$.result",
20+
"Variable": "$.n",
2121
"NumericGreaterThanEquals": 10,
2222
"Next": "BranchTwoSecondState"
2323
}

internal/function/signature.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -189,23 +189,11 @@ func (s *Signature) CheckOrMatchInputs(inputMap map[string]interface{}) error {
189189
for _, def := range s.Inputs {
190190
err := def.CheckInput(inputMap)
191191

192-
if err != nil && len(s.Inputs) == 1 {
193-
// TODO: Consider a better solution. If there is a single input parameter, we just try to match type
194-
key, ok := def.FindEntryThatTypeChecks(inputMap)
195-
if ok {
196-
val := inputMap[key]
197-
delete(inputMap, key)
198-
inputMap[def.Name] = val
199-
err = nil
200-
} else {
201-
err = fmt.Errorf("no output entry input-checks with the next function")
202-
}
203-
}
204-
205192
if err != nil {
206-
errors += fmt.Sprintf("type-error: %v", err)
193+
errors += fmt.Sprintf("no output entry input-checks with the next function")
207194
}
208195
}
196+
209197
if errors != "" {
210198
return fmt.Errorf("%s", errors)
211199
}

internal/test/api_test.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ func TestContainerPool(t *testing.T) {
2323
funcs := []string{"inc", "double"}
2424
for _, name := range funcs {
2525
fn, err := InitializePyFunction(name, "handler", function.NewSignature().
26-
AddInput("input", function.Int{}).
27-
AddOutput("result", function.Int{}).
26+
AddInput("n", function.Int{}).
27+
AddOutput("n", function.Int{}).
2828
Build())
2929
utils.AssertNil(t, err)
3030

@@ -36,7 +36,7 @@ func TestContainerPool(t *testing.T) {
3636
for i := 0; i < n; i++ {
3737
for _, name := range funcs {
3838
x := make(map[string]interface{})
39-
x["input"] = 1
39+
x["n"] = 1
4040
fnName := name
4141
go func() {
4242
time.Sleep(50 * time.Millisecond)
@@ -70,8 +70,8 @@ func TestCreateWorkflow(t *testing.T) {
7070
}
7171

7272
fn, err := InitializePyFunction("inc", "handler", function.NewSignature().
73-
AddInput("input", function.Int{}).
74-
AddOutput("result", function.Int{}).
73+
AddInput("n", function.Int{}).
74+
AddOutput("n", function.Int{}).
7575
Build())
7676
utils.AssertNilMsg(t, err, "failed to initialize function")
7777
wflow, err := CreateSequenceWorkflow(fn, fn, fn)
@@ -99,8 +99,8 @@ func TestInvokeWorkflow(t *testing.T) {
9999
}
100100
fcName := "sequence"
101101
fn, err := initializeJsFunction("inc", function.NewSignature().
102-
AddInput("input", function.Int{}).
103-
AddOutput("result", function.Int{}).
102+
AddInput("n", function.Int{}).
103+
AddOutput("n", function.Int{}).
104104
Build())
105105
utils.AssertNilMsg(t, err, "failed to initialize function")
106106
wflow, err := CreateSequenceWorkflow(fn, fn, fn)
@@ -114,7 +114,7 @@ func TestInvokeWorkflow(t *testing.T) {
114114

115115
// === this is the test ===
116116
params := make(map[string]interface{})
117-
params["input"] = 1
117+
params["n"] = 1
118118
invokeWorkflowApiTest(t, params, fcName, HOST, PORT, false)
119119

120120
// here we do not use REST API
@@ -133,13 +133,13 @@ func TestInvokeWorkflow_DifferentFunctions(t *testing.T) {
133133
}
134134
fcName := "sequence"
135135
fnJs, err := initializeJsFunction("inc", function.NewSignature().
136-
AddInput("input", function.Int{}).
137-
AddOutput("result", function.Int{}).
136+
AddInput("n", function.Int{}).
137+
AddOutput("n", function.Int{}).
138138
Build())
139139
utils.AssertNilMsg(t, err, "failed to initialize javascript function")
140140
fnPy, err := InitializePyFunction("double", "handler", function.NewSignature().
141-
AddInput("input", function.Int{}).
142-
AddOutput("result", function.Int{}).
141+
AddInput("n", function.Int{}).
142+
AddOutput("n", function.Int{}).
143143
Build())
144144
utils.AssertNilMsg(t, err, "failed to initialize python function")
145145
wflow, err := CreateSequenceWorkflow(fnPy, fnJs, fnPy, fnJs)
@@ -153,7 +153,7 @@ func TestInvokeWorkflow_DifferentFunctions(t *testing.T) {
153153

154154
// === this is the test ===
155155
params := make(map[string]interface{})
156-
params["input"] = 1
156+
params["n"] = 1
157157
invokeWorkflowApiTest(t, params, fcName, HOST, PORT, false)
158158

159159
// here we do not use REST API
@@ -172,16 +172,16 @@ func TestDeleteWorkflow(t *testing.T) {
172172
}
173173
fcName := "sequence"
174174
fn, err := InitializePyFunction("inc", "handler", function.NewSignature().
175-
AddInput("input", function.Int{}).
176-
AddOutput("result", function.Int{}).
175+
AddInput("n", function.Int{}).
176+
AddOutput("n", function.Int{}).
177177
Build())
178178
if err != nil {
179179
fmt.Printf("inc creation failed: %v\n", err)
180180
t.Fail()
181181
}
182182
db, err := InitializePyFunction("double", "handler", function.NewSignature().
183-
AddInput("input", function.Int{}).
184-
AddOutput("result", function.Int{}).
183+
AddInput("n", function.Int{}).
184+
AddOutput("n", function.Int{}).
185185
Build())
186186
utils.AssertNilMsg(t, err, "failed to initialize function")
187187
wflow, err := CreateSequenceWorkflow(fn, db, fn)
@@ -212,8 +212,8 @@ func TestAsyncInvokeWorkflow(t *testing.T) {
212212
fcName := "sequence"
213213

214214
fn, err := InitializePyFunction("inc", "handler", function.NewSignature().
215-
AddInput("input", function.Int{}).
216-
AddOutput("result", function.Int{}).
215+
AddInput("n", function.Int{}).
216+
AddOutput("n", function.Int{}).
217217
Build())
218218
utils.AssertNilMsg(t, err, "failed to initialize function")
219219
wflow, err := CreateSequenceWorkflow(fn, fn, fn)
@@ -227,7 +227,7 @@ func TestAsyncInvokeWorkflow(t *testing.T) {
227227

228228
// === this is the test ===
229229
params := make(map[string]interface{})
230-
params["input"] = 1
230+
params["n"] = 1
231231
invocationResult := invokeWorkflowApiTest(t, params, fcName, HOST, PORT, true)
232232

233233
reqIdStruct := &function.AsyncResponse{}
@@ -251,7 +251,7 @@ func TestAsyncInvokeWorkflow(t *testing.T) {
251251
i++
252252
time.Sleep(200 * time.Millisecond)
253253
} else {
254-
utils.AssertEquals(t, 4, cast.ToInt(response.Result["result"]))
254+
utils.AssertEquals(t, 4, cast.ToInt(response.Result["n"]))
255255
break
256256
}
257257
}

internal/test/asl/choice_boolexpr.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@
1515
{
1616
"And": [
1717
{
18-
"Variable": "$.value",
18+
"Variable": "$.n",
1919
"IsPresent": true
2020
},
2121
{
22-
"Variable": "$.value",
22+
"Variable": "$.n",
2323
"IsNumeric": true
2424
},
2525
{
26-
"Variable": "$.value",
26+
"Variable": "$.n",
2727
"NumericGreaterThanEquals": 20
2828
},
2929
{
30-
"Variable": "$.value",
30+
"Variable": "$.n",
3131
"NumericLessThan": 30
3232
}
3333
],

internal/test/asl/choice_datatestexpr.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
"Type": "Choice",
77
"Choices": [
88
{
9-
"Variable": "$.input",
9+
"Variable": "$.n",
1010
"NumericEquals": 1,
1111
"Next": "FirstMatchState"
1212
},
1313
{
14-
"Variable": "$.input",
14+
"Variable": "$.n",
1515
"NumericEquals": 2,
1616
"Next": "SecondMatchState"
1717
},
1818
{
19-
"Variable": "$.input",
19+
"Variable": "$.n",
2020
"NumericEquals": 3,
2121
"Next": "ThirdMatchState"
2222
}
@@ -45,7 +45,7 @@
4545
"DefaultState": {
4646
"Comment": "Lang=Python",
4747
"Type": "Task",
48-
"Resource": "hello",
48+
"Resource": "inc",
4949
"End": true
5050
},
5151

internal/test/aslparser_test.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func TestParsedWorkflowName(t *testing.T) {
3232

3333
// commonTest creates a function, parses a json AWS State Language file producing a function composition,
3434
// then checks if the composition is saved onto ETCD. Lastly, it runs the composition and expects the correct result.
35-
func commonTest(t *testing.T, name string, expectedResult int) {
35+
func commonTest(t *testing.T, name string, paramName string, paramValue string) {
3636
all, err := workflow.GetAllWorkflows()
3737
utils.AssertNil(t, err)
3838

@@ -60,7 +60,7 @@ func commonTest(t *testing.T, name string, expectedResult int) {
6060

6161
// runs the workflow
6262
params := make(map[string]interface{})
63-
params["input"] = "0"
63+
params[paramName] = paramValue
6464
request := workflow.NewRequest(shortuuid.New(), comp, params, approximateMapSize(params))
6565
err2 := comp.Invoke(request)
6666
utils.AssertNil(t, err2)
@@ -74,7 +74,7 @@ func TestParsingSimple(t *testing.T) {
7474
}
7575

7676
initializeAllPyFunctionFromNames(t, "hello")
77-
commonTest(t, "simple", 2)
77+
commonTest(t, "simple", "input", "0")
7878
deleteApiTest(t, "hello", HOST, PORT)
7979
}
8080

@@ -86,7 +86,7 @@ func TestParsingSequence(t *testing.T) {
8686

8787
InitializePyFunction("noop", "handler", function.NewSignature().Build())
8888

89-
commonTest(t, "sequence", 5)
89+
commonTest(t, "sequence", "input", "0")
9090
deleteApiTest(t, "noop", HOST, PORT)
9191

9292
}
@@ -98,7 +98,7 @@ func TestParsingMixedUpSequence(t *testing.T) {
9898
}
9999

100100
initializeAllPyFunctionFromNames(t, "double", "inc")
101-
commonTest(t, "mixed_sequence", 5)
101+
commonTest(t, "mixed_sequence", "n", "0")
102102
deleteApiTest(t, "double", HOST, PORT)
103103
deleteApiTest(t, "inc", HOST, PORT)
104104
}
@@ -155,7 +155,7 @@ func TestParsingChoiceWorkflowWithDataTestExpr(t *testing.T) {
155155
t.Skip("Skipping integration test")
156156
}
157157
// Creates "inc", "double" and "hello" python functions
158-
funcs := initializeAllPyFunctionFromNames(t, "inc", "double", "hello")
158+
funcs := initializeAllPyFunctionFromNames(t, "inc", "double")
159159

160160
// reads the file
161161
body, err := os.ReadFile("asl/choice_datatestexpr.json")
@@ -190,13 +190,12 @@ func TestParsingChoiceWorkflowWithDataTestExpr(t *testing.T) {
190190

191191
// runs the workflow (default choice branch)
192192
paramsDefault := make(map[string]interface{})
193-
paramsDefault[incFn.Signature.GetInputs()[0].Name] = "Giacomo"
193+
paramsDefault[incFn.Signature.GetInputs()[0].Name] = 3
194194
requestDefault := workflow.NewRequest(shortuuid.New(), comp, paramsDefault, approximateMapSize(paramsDefault))
195195
errDef := comp.Invoke(requestDefault)
196196
utils.AssertNil(t, errDef)
197197

198198
deleteApiTest(t, "inc", HOST, PORT)
199-
deleteApiTest(t, "hello", HOST, PORT)
200199
deleteApiTest(t, "double", HOST, PORT)
201200
}
202201

@@ -218,7 +217,7 @@ func TestParsingChoiceWorkflowWithBoolExpr(t *testing.T) {
218217
// 1st branch (type != "Private")
219218
params := make(map[string]interface{})
220219
params["type"] = "Public"
221-
params["value"] = 1
220+
params["n"] = 1
222221
//params["input"] = 1
223222
request := workflow.NewRequest(shortuuid.New(), comp, params, approximateMapSize(params))
224223
err1 := comp.Invoke(request)
@@ -232,7 +231,7 @@ func TestParsingChoiceWorkflowWithBoolExpr(t *testing.T) {
232231
// 2nd branch (type == "Private", value is present, value is numeric, value >= 20, value < 30)
233232
params2 := make(map[string]interface{})
234233
params2["type"] = "Private"
235-
params2["value"] = 20
234+
params2["n"] = 20
236235
request2 := workflow.NewRequest(shortuuid.New(), comp, params2, approximateMapSize(params2))
237236
err2 := comp.Invoke(request2)
238237
utils.AssertNil(t, err2)

internal/test/main_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,12 @@ func startReliably(startScript string) error {
118118

119119
// run the bash script to initialize serverledge
120120
func setupServerledge(outboundIp string) (*echo.Echo, error) {
121-
_ = startReliably("../../scripts/start-etcd" + getShellExt())
122121
echoServer := testStartServerledge(false, outboundIp)
123122
return echoServer, nil
124123
}
125124

126125
// run the bash script to stop serverledge
127126
func teardownServerledge(e *echo.Echo) error {
128-
cmd1 := exec.CommandContext(context.Background(), getShell(), "../../scripts/stop-etcd"+getShellExt())
129127

130128
node.ShutdownAllContainers()
131129

@@ -136,6 +134,5 @@ func teardownServerledge(e *echo.Echo) error {
136134
errEcho := e.Shutdown(ctx)
137135

138136
errRegistry := registration.Deregister()
139-
err1 := cmd1.Run()
140-
return u.ReturnNonNilErr(errEcho, errRegistry, err1)
137+
return u.ReturnNonNilErr(errEcho, errRegistry)
141138
}

0 commit comments

Comments
 (0)