mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 10:58:35 +08:00
规则引擎
This commit is contained in:
@@ -2,6 +2,8 @@ package rule_engine
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"pandax/pkg/rule_engine/message"
|
||||
"pandax/pkg/rule_engine/nodes"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -15,3 +17,26 @@ func TestNewRuleChainInstance(t *testing.T) {
|
||||
t.Error(errs[0])
|
||||
}
|
||||
}
|
||||
|
||||
func TestScriptEngine(t *testing.T) {
|
||||
metadata := message.NewDefaultMetadata(map[string]interface{}{"device": "aa"})
|
||||
msg := message.NewMessageWithDetail("1", message.MessageTypeConnectEvent, []byte{}, metadata)
|
||||
scriptEngine := nodes.NewScriptEngine()
|
||||
const script = `
|
||||
function Switch(msg, metadata, msgType) {
|
||||
function nextRelation(metadata, msg) {
|
||||
return ['one','nine'];
|
||||
}
|
||||
if(msgType === 'Post telemetry') {
|
||||
return ['two'];
|
||||
}
|
||||
return nextRelation(metadata, msg);
|
||||
}
|
||||
`
|
||||
SwitchResults, err := scriptEngine.ScriptOnSwitch(msg, script)
|
||||
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
t.Log(SwitchResults)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user