Skip to content

Commit b45a36f

Browse files
committed
Introduces 'cast' library for type conversion issues in test
1 parent c599a12 commit b45a36f

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

internal/test/workflow_integration_test.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/serverledge-faas/serverledge/internal/function"
1212
"github.com/serverledge-faas/serverledge/internal/workflow"
1313
u "github.com/serverledge-faas/serverledge/utils"
14+
"github.com/spf13/cast"
1415
)
1516

1617
func TestMarshalingFunctionWorkflow(t *testing.T) {
@@ -114,8 +115,8 @@ func TestInvokeFC(t *testing.T) {
114115
u.AssertNil(t, err2)
115116

116117
// check result
117-
output := resultMap.Result[f.Signature.GetOutputs()[0].Name]
118-
if length != int(output.(float64)) {
118+
output := cast.ToInt(resultMap.Result[f.Signature.GetOutputs()[0].Name])
119+
if length != output {
119120
t.FailNow()
120121
}
121122

@@ -169,8 +170,8 @@ func TestInvokeChoiceFC(t *testing.T) {
169170
resultMap, err2 := wflow.Invoke(request)
170171
u.AssertNil(t, err2)
171172
// checking the result, should be input + 1
172-
output := resultMap.Result[f.Signature.GetOutputs()[0].Name]
173-
u.AssertEquals(t, input*2, output.(int))
173+
output := cast.ToInt(resultMap.Result[f.Signature.GetOutputs()[0].Name])
174+
u.AssertEquals(t, input*2, output)
174175

175176
// cleaning up function composition and function
176177
err3 := wflow.Delete()
@@ -223,13 +224,11 @@ func TestInvokeFC_DifferentFunctions(t *testing.T) {
223224
u.AssertNil(t, err2)
224225

225226
// check result
226-
output := resultMap.Result[fInc.Signature.GetOutputs()[0].Name]
227+
output := cast.ToInt(resultMap.Result[fInc.Signature.GetOutputs()[0].Name])
227228
if output != 11 {
228229
t.FailNow()
229230
}
230231

231-
u.AssertEquals(t, (2*2+1)*2+1, output.(int))
232-
233232
// cleaning up function composition and function
234233
err3 := wflow.Delete()
235234
u.AssertNil(t, err3)
@@ -386,11 +385,10 @@ func TestInvokeFC_ScatterFanOut(t *testing.T) {
386385

387386
// check multiple result
388387
output := resultMap.Result
389-
fmt.Println(output)
390388
u.AssertNonNil(t, output)
391389
for i := 0; i < width; i++ {
392390
currOutput := output[fmt.Sprintf("%d", i)].(map[string]interface{})
393-
u.AssertEquals(t, (i+1)*2, currOutput["result"].(int))
391+
u.AssertEquals(t, (i+1)*2, cast.ToInt(currOutput["result"]))
394392
}
395393

396394
// cleaning up function composition and functions
@@ -618,8 +616,8 @@ func TestResumeWorkflow(t *testing.T) {
618616
u.AssertNil(t, err2)
619617

620618
// check result
621-
output := resultMap.Result[f.Signature.GetOutputs()[0].Name]
622-
if length != int(output.(float64)) {
619+
output := cast.ToInt(resultMap.Result[f.Signature.GetOutputs()[0].Name])
620+
if length != output {
623621
t.FailNow()
624622
}
625623

0 commit comments

Comments
 (0)