From 707c127b598f88eadf3d9192a181fb57cc1378e4 Mon Sep 17 00:00:00 2001 From: Karin Touchie Date: Wed, 8 May 2024 11:05:00 +0100 Subject: [PATCH] fix(SXMC-198): Use declared ctx variable to bypass compiler error --- checkers/unused/check.go | 4 +-- wrapper.go | 1 + wrappers/mockingjay/graph/mockingjay.go | 45 +++++++++++++++++++++++++ wrappers/mockingjay/mockingjay.go | 4 +-- wrappers/mockingjay/mockingjay.yml | 7 ++++ 5 files changed, 57 insertions(+), 4 deletions(-) diff --git a/checkers/unused/check.go b/checkers/unused/check.go index 055184a..6777e0a 100644 --- a/checkers/unused/check.go +++ b/checkers/unused/check.go @@ -16,8 +16,8 @@ func (e Error) Error() string { } // Check checks that all nodes are used in one way or another: -// - have only one error output -// - are used explicitly +// - have only one error output +// - are used explicitly func Check(graph goflow.GraphRenderer) error { nodes := graph.Nodes() diff --git a/wrapper.go b/wrapper.go index d8eded4..a222f5a 100644 --- a/wrapper.go +++ b/wrapper.go @@ -8,6 +8,7 @@ package goflow // - NodeWrapper // - Linter // - Checker +// // goflow provides functions to use those simpler types as GraphWrappers. type GraphWrapper func(unmarshal func(interface{}) error, graph GraphRenderer) (GraphRenderer, error) diff --git a/wrappers/mockingjay/graph/mockingjay.go b/wrappers/mockingjay/graph/mockingjay.go index 084854c..e1633be 100644 --- a/wrappers/mockingjay/graph/mockingjay.go +++ b/wrappers/mockingjay/graph/mockingjay.go @@ -42,6 +42,9 @@ func (g *Mockingjay) Run(ctx context.Context, a int, b int) (sum int) { // __output_sum_builder outputs var __output_sum_builder_sum int + // __print_values outputs + var __print_values_aggregated []interface{} + // add outputs var add_sum int @@ -49,6 +52,8 @@ func (g *Mockingjay) Run(ctx context.Context, a int, b int) (sum int) { var inputs_a int var inputs_b int + // print outputs + igniteNodeID := "ignite" doneNodeID := "done" @@ -106,6 +111,18 @@ func (g *Mockingjay) Run(ctx context.Context, a int, b int) (sum int) { }, alreadyDone: false, }, + "__print_values": { + deps: map[string]struct{}{ + "add": {}, + igniteNodeID: {}, + }, + run: func() { + __print_values_aggregated = append(__print_values_aggregated, "sum") + __print_values_aggregated = append(__print_values_aggregated, add_sum) + done <- "__print_values" + }, + alreadyDone: false, + }, "add": { deps: map[string]struct{}{ "__ctx": {}, @@ -159,6 +176,32 @@ func (g *Mockingjay) Run(ctx context.Context, a int, b int) (sum int) { }, alreadyDone: false, }, + "print": { + deps: map[string]struct{}{ + "__ctx": {}, + "__print_values": {}, + igniteNodeID: {}, + }, + run: func() { + + var _mock []interface{} + if _mocks, ok := ctx.Value(mockingjay.ContextKey).(map[string][]interface{}); ok && _mocks != nil { + m, ok := _mocks["print"] + if ok { + _mock = m + } + } + + if _mock != nil { + + } else { + nodes.PrinterCtx(__ctx_ctx, __print_values_aggregated) + } + + done <- "print" + }, + alreadyDone: false, + }, igniteNodeID: { deps: map[string]struct{}{}, run: func() { @@ -172,8 +215,10 @@ func (g *Mockingjay) Run(ctx context.Context, a int, b int) (sum int) { "__add_b": {}, "__ctx": {}, "__output_sum_builder": {}, + "__print_values": {}, "add": {}, "inputs": {}, + "print": {}, }, run: func() { done <- doneNodeID diff --git a/wrappers/mockingjay/mockingjay.go b/wrappers/mockingjay/mockingjay.go index 543d0ab..c2a3b04 100644 --- a/wrappers/mockingjay/mockingjay.go +++ b/wrappers/mockingjay/mockingjay.go @@ -31,8 +31,8 @@ func WithMock(ctx context.Context, nodeID string, values ...interface{}) context // // The WithMock helper function is provided to make it easier to mock node: // -// ctx := mockingjay.WithMock(ctx, "myNode", 42) -// graph.Run(ctx, ...) +// ctx := mockingjay.WithMock(ctx, "myNode", 42) +// graph.Run(ctx, ...) func Mock(_ func(interface{}) error, node goflow.NodeRenderer) (goflow.NodeRenderer, error) { return mocker{ NodeRenderer: ctx.Injector{ diff --git a/wrappers/mockingjay/mockingjay.yml b/wrappers/mockingjay/mockingjay.yml index e765583..b8ad588 100644 --- a/wrappers/mockingjay/mockingjay.yml +++ b/wrappers/mockingjay/mockingjay.yml @@ -11,5 +11,12 @@ nodes: a: inputs.a b: inputs.b + - id: print + type: nodes.PrinterCtx + bind: + values: + - '"sum"' + - add.sum + outputs: sum: add.sum