source_test.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2022 EMQ Technologies Co., Ltd.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package neuron
  15. import (
  16. "github.com/lf-edge/ekuiper/internal/topo/mock"
  17. "github.com/lf-edge/ekuiper/pkg/api"
  18. _ "go.nanomsg.org/mangos/v3/transport/ipc"
  19. "testing"
  20. )
  21. func TestRun(t *testing.T) {
  22. exp := []api.SourceTuple{
  23. api.NewDefaultSourceTuple(map[string]interface{}{"group_name": "group1", "timestamp": 1646125996000.0, "node_name": "node1", "values": map[string]interface{}{"tag_name1": 11.22, "tag_name2": "yellow"}, "errors": map[string]interface{}{"tag_name3": 122.0}}, map[string]interface{}{"topic": "$$neuron"}),
  24. api.NewDefaultSourceTuple(map[string]interface{}{"group_name": "group1", "timestamp": 1646125996000.0, "node_name": "node1", "values": map[string]interface{}{"tag_name1": 11.22, "tag_name2": "green", "tag_name3": 60.0}, "errors": map[string]interface{}{}}, map[string]interface{}{"topic": "$$neuron"}),
  25. api.NewDefaultSourceTuple(map[string]interface{}{"group_name": "group1", "timestamp": 1646125996000.0, "node_name": "node1", "values": map[string]interface{}{"tag_name1": 15.4, "tag_name2": "green", "tag_name3": 70.0}, "errors": map[string]interface{}{}}, map[string]interface{}{"topic": "$$neuron"}),
  26. }
  27. s := GetSource()
  28. err := s.Configure("new", nil)
  29. if err != nil {
  30. t.Errorf(err.Error())
  31. return
  32. }
  33. server, _ := mockNeuron(true, false)
  34. defer server.Close()
  35. mock.TestSourceOpen(s, exp, t)
  36. }