Browse Source

feat(test): remove the dependency of mock in source node

Only compile mock when test tag is set
Print out error if go test without test tag

Signed-off-by: ngjaying <ngjaying@gmail.com>
ngjaying 3 years atrás
parent
commit
f5e301219e

+ 1 - 1
.github/workflows/run_test_case.yaml

@@ -36,7 +36,7 @@ jobs:
             go build -modfile extensions.mod --buildmode=plugin -o plugins/functions/Echo.so extensions/functions/echo/echo.go
             go build -modfile extensions.mod --buildmode=plugin -o plugins/functions/CountPlusOne@v1.0.0.so extensions/functions/countPlusOne/countPlusOne.go
             go build -modfile extensions.mod --buildmode=plugin -o plugins/functions/AccumulateWordCount@v1.0.0.so extensions/functions/accumulateWordCount/accumulateWordCount.go
-            go test --tags=edgex ./...
+            go test --tags="edgex test" ./...
         - uses: actions/upload-artifact@v1
           if: failure()
           with:

+ 0 - 3
xstream/nodes/source_node.go

@@ -6,7 +6,6 @@ import (
 	"github.com/emqx/kuiper/xsql"
 	"github.com/emqx/kuiper/xstream/api"
 	"github.com/emqx/kuiper/xstream/extensions"
-	"github.com/emqx/kuiper/xstream/topotest/mocknodes"
 	"sync"
 )
 
@@ -156,8 +155,6 @@ func doGetSource(t string) (api.Source, error) {
 		s = &extensions.HTTPPullSource{}
 	case "file":
 		s = &extensions.FileSource{}
-	case "mock":
-		s = &mocknodes.MockSource{}
 	default:
 		s, err = plugins.GetSource(t)
 		if err != nil {

+ 32 - 0
xstream/nodes/sources_for_test_with_edgex.go

@@ -0,0 +1,32 @@
+// +build test
+// +build edgex
+
+package nodes
+
+import (
+	"github.com/emqx/kuiper/xstream/api"
+	"github.com/emqx/kuiper/xstream/extensions"
+	"github.com/emqx/kuiper/xstream/sinks"
+	"github.com/emqx/kuiper/xstream/topotest/mocknodes"
+)
+
+func getSource(t string) (api.Source, error) {
+	if t == "edgex" {
+		return &extensions.EdgexSource{}, nil
+	} else if t == "mock" {
+		return &mocknodes.MockSource{}, nil
+	}
+	return doGetSource(t)
+}
+
+func getSink(name string, action map[string]interface{}) (api.Sink, error) {
+	if name == "edgex" {
+		s := &sinks.EdgexMsgBusSink{}
+		if err := s.Configure(action); err != nil {
+			return nil, err
+		} else {
+			return s, nil
+		}
+	}
+	return doGetSink(name, action)
+}

+ 20 - 0
xstream/nodes/sources_for_test_without_edgex.go

@@ -0,0 +1,20 @@
+// +build !edgex
+// +build test
+
+package nodes
+
+import (
+	"github.com/emqx/kuiper/xstream/api"
+	"github.com/emqx/kuiper/xstream/topotest/mocknodes"
+)
+
+func getSource(t string) (api.Source, error) {
+	if t == "mock" {
+		return &mocknodes.MockSource{}, nil
+	}
+	return doGetSource(t)
+}
+
+func getSink(name string, action map[string]interface{}) (api.Sink, error) {
+	return doGetSink(name, action)
+}

+ 1 - 0
xstream/nodes/with_edgex.go

@@ -1,4 +1,5 @@
 // +build edgex
+// +build !test
 
 package nodes
 

+ 1 - 0
xstream/nodes/without_edgex.go

@@ -1,4 +1,5 @@
 // +build !edgex
+// +build !test
 
 package nodes
 

+ 7 - 0
xstream/topotest/warning_test.go

@@ -0,0 +1,7 @@
+// +build !test
+
+package topotest
+
+func init() {
+	panic("please rerun go test with -tags test")
+}