From 098ad83ba473c9dae57b87e454d1ad4a0b5f65a5 Mon Sep 17 00:00:00 2001 From: bacnd Date: Sat, 29 Oct 2022 16:28:42 +0700 Subject: [PATCH] fix test --- rules/arithmetic/match_rule_test.go | 96 ++++++++++++++++++++++ rules/conditional/conditional_rule_test.go | 3 +- 2 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 rules/arithmetic/match_rule_test.go diff --git a/rules/arithmetic/match_rule_test.go b/rules/arithmetic/match_rule_test.go new file mode 100644 index 0000000..1ca2e09 --- /dev/null +++ b/rules/arithmetic/match_rule_test.go @@ -0,0 +1,96 @@ +package arithmetic + +import ( + "context" + "github.com/dipper-iot/dipper-engine/data" + "github.com/dipper-iot/dipper-engine/queue" + "testing" +) + +func TestMatchRule_Run(t *testing.T) { + a := NewArithmetic() + a.Infinity() + a.Initialize(context.TODO(), map[string]interface{}{}) + qsub := queue.NewDefaultQueue[*data.InputEngine]("qsub") + qpub := queue.NewDefaultQueue[*data.OutputEngine]("qpub") + + qsub.Publish(context.TODO(), &data.InputEngine{ + SessionId: 1, + ChanId: "1", + IdNode: "noed1", + FromEngine: "test", + ToEngine: "test", + Node: &data.NodeRule{ + Option: map[string]interface{}{ + "operator": map[string]interface{}{ + "right": map[string]interface{}{ + "value": "default.a", + "type": "val", + }, + "left": map[string]interface{}{ + "type": "val", + "value": "default.b", + }, + "operator": "+", + "type": "operator", + }, + "set_param_result_to": "default.cond_a_b", + "next_error": "4", + "next_true": "4", + "next_false": "4", + }, + End: false, + Debug: false, + RuleId: "1", + NodeId: "1", + }, + Data: map[string]interface{}{ + "default": map[string]interface{}{ + "a": 2, + "b": 2, + "x": 3, + }, + }, + BranchMain: "default", + }) + qsub.Publish(context.TODO(), &data.InputEngine{ + SessionId: 1, + ChanId: "1", + IdNode: "noed1", + FromEngine: "test", + ToEngine: "test", + Node: &data.NodeRule{ + Option: map[string]interface{}{ + "operator": map[string]interface{}{ + "right": map[string]interface{}{ + "value": "default.f", + "type": "val", + }, + "left": map[string]interface{}{ + "type": "val", + "value": "default.b", + }, + "operator": "-", + "type": "operator", + }, + "set_param_result_to": "default.cond_a_b", + "next_error": "4", + "next_true": "4", + "next_false": "4", + }, + End: false, + Debug: false, + RuleId: "1", + NodeId: "1", + }, + Data: map[string]interface{}{ + "default": map[string]interface{}{ + "a": 2, + "b": 2, + "x": 3, + }, + }, + BranchMain: "default", + }) + a.Run(context.TODO(), qsub.Subscribe, qpub.Publish) +} diff --git a/rules/conditional/conditional_rule_test.go b/rules/conditional/conditional_rule_test.go index 3370a05..19ea162 100644 --- a/rules/conditional/conditional_rule_test.go +++ b/rules/conditional/conditional_rule_test.go @@ -8,7 +8,8 @@ import ( ) func TestConditionalRule_Run(t *testing.T) { - a := ConditionalRule{} + a := NewConditionalRule() + a.Infinity() a.Initialize(context.TODO(), map[string]interface{}{}) qsub := queue.NewDefaultQueue[*data.InputEngine]("qsub") qpub := queue.NewDefaultQueue[*data.OutputEngine]("qpub")