88 "os"
99 "testing"
1010
11- "github.com/cornelk/hashmap"
1211 "github.com/serverledge-faas/serverledge/internal/cli"
1312 "github.com/serverledge-faas/serverledge/internal/client"
1413 "github.com/serverledge-faas/serverledge/internal/function"
@@ -197,8 +196,7 @@ func createApiIfNotExistsTest(t *testing.T, fn *function.Function, host string,
197196
198197func invokeApiTest (fn string , params map [string ]interface {}, host string , port int ) error {
199198 request := client.InvocationRequest {
200- Params : params ,
201- // QoSClass: qosClass,
199+ Params : params ,
202200 QoSMaxRespT : 250 ,
203201 CanDoOffloading : true ,
204202 Async : false ,
@@ -212,7 +210,6 @@ func invokeApiTest(fn string, params map[string]interface{}, host string, port i
212210 if err2 != nil {
213211 return err2
214212 }
215- // utils.PrintJsonResponse(resp.Body)
216213 return nil
217214}
218215
@@ -276,22 +273,11 @@ func pollWorkflowTest(t *testing.T, requestId string, host string, port int) str
276273 return utils .GetJsonResponse (resp .Body )
277274}
278275
279- func newWorkflowRequestTest () * workflow.Request {
280-
281- return & workflow.Request {
282- Id : "test" ,
283- ExecReport : workflow.ExecutionReport {
284- Reports : hashmap .New [workflow.ExecutionReportId , * function.ExecutionReport ](), // make(map[workflow.ExecutionReportId]*function.ExecutionReport),
285- },
286- }
287- }
288-
289276func IsWindows () bool {
290277 return os .PathSeparator == '\\' && os .PathListSeparator == ';'
291278}
292279
293280// CreateSequenceWorkflow if successful, returns a workflow pointer with a sequence of Simple Nodes
294- // TODO: do we need this utility function?
295281func CreateSequenceWorkflow (funcs ... * function.Function ) (* workflow.Workflow , error ) {
296282 builder := workflow .NewBuilder ()
297283 for _ , f := range funcs {
@@ -301,7 +287,6 @@ func CreateSequenceWorkflow(funcs ...*function.Function) (*workflow.Workflow, er
301287}
302288
303289// CreateChoiceWorkflow if successful, returns a workflow with one Choice Node with each branch consisting of the same sub-workflow
304- // TODO: why is a 'dagger' needed?
305290func CreateChoiceWorkflow (dagger func () (* workflow.Workflow , error ), condArr ... workflow.Condition ) (* workflow.Workflow , error ) {
306291 return workflow .NewBuilder ().
307292 AddChoiceNode (condArr ... ).
@@ -311,7 +296,6 @@ func CreateChoiceWorkflow(dagger func() (*workflow.Workflow, error), condArr ...
311296
312297// CreateScatterSingleFunctionWorkflow if successful, returns a workflow with one fan out, N simple node with the same function
313298// and then a fan in node that merges all the result in an array.
314- // TODO: This appears to be used only in tests. Move away from the workflow package
315299func CreateScatterSingleFunctionWorkflow (fun * function.Function , fanOutDegree int ) (* workflow.Workflow , error ) {
316300 return workflow .NewBuilder ().
317301 AddScatterFanOutNode (fanOutDegree ).
@@ -322,7 +306,6 @@ func CreateScatterSingleFunctionWorkflow(fun *function.Function, fanOutDegree in
322306
323307// CreateBroadcastWorkflow if successful, returns a workflow with one fan out node, N simple nodes with different functions and a fan in node
324308// The number of branches is defined by the number of given functions
325- // TODO: This appears to be used only in tests. Move away from the workflow package
326309func CreateBroadcastWorkflow (dagger func () (* workflow.Workflow , error ), fanOutDegree int ) (* workflow.Workflow , error ) {
327310 return workflow .NewBuilder ().
328311 AddBroadcastFanOutNode (fanOutDegree ).
@@ -333,8 +316,6 @@ func CreateBroadcastWorkflow(dagger func() (*workflow.Workflow, error), fanOutDe
333316
334317// CreateBroadcastMultiFunctionWorkflow if successful, returns a workflow with one fan out node, each branch chained with a different workflow that run in parallel, and a fan in node.
335318// The number of branch is defined as the number of dagger functions.
336- // TODO: why is a 'dagger' needed?
337- // TODO: This appears to be used only in tests. Move away from the workflow package
338319func CreateBroadcastMultiFunctionWorkflow (dagger ... func () (* workflow.Workflow , error )) (* workflow.Workflow , error ) {
339320 builder := workflow .NewBuilder ().
340321 AddBroadcastFanOutNode (len (dagger ))
@@ -345,3 +326,25 @@ func CreateBroadcastMultiFunctionWorkflow(dagger ...func() (*workflow.Workflow,
345326 AddFanInNode ().
346327 Build ()
347328}
329+
330+ func GetSingleResult (cer * workflow.ExecutionReport ) (string , error ) {
331+ if len (cer .Result ) == 1 {
332+ for _ , value := range cer .Result {
333+ return fmt .Sprintf ("%v" , value ), nil
334+ }
335+ }
336+ return "" , fmt .Errorf ("there is not exactly one result: there are %d result(s)" , len (cer .Result ))
337+ }
338+
339+ func GetIntSingleResult (cer * workflow.ExecutionReport ) (int , error ) {
340+ if len (cer .Result ) == 1 {
341+ for _ , value := range cer .Result {
342+ valueInt , ok := value .(int )
343+ if ! ok {
344+ return 0 , fmt .Errorf ("value %v cannot be casted to int" , value )
345+ }
346+ return valueInt , nil
347+ }
348+ }
349+ return 0 , fmt .Errorf ("there is not exactly one result: there are %d result(s)" , len (cer .Result ))
350+ }
0 commit comments