diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 99cc13c..f2bd7bd 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -19,7 +19,7 @@ jobs: with: # list of Docker images to use as base name for tags images: | - name/app + dipperhub/dipper-engine # generate Docker tags based on the following events/attributes tags: | type=ref,event=branch diff --git a/Dockerfile b/Dockerfile index 13e347b..5b494b9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,18 @@ -FROM golang:1.19-alpine as builder +FROM alpine:3.12.1 as builder -ENV GO111MODULE=on -ENV GOFLAGS=" -ldflags '-w'" -ENV GOPROXY=direct -ENV GOSUMDB=off - -COPY . . +COPY --from=golang:1.19-alpine /usr/local/go/ /usr/local/go/ +ENV PATH="/usr/local/go/bin:${PATH}" +RUN apk --no-cache add make git gcc libtool musl-dev +COPY go.mod . +COPY go.sum . RUN go mod download -RUN GOOS=linux GOARCH=amd64 go build +COPY . / +RUN make build; rm -rf $GOPATH/pkg/mod + -FROM alpine:3.14 as run +FROM alpine:3.12.1 RUN apk add --no-progress --no-cache ca-certificates -COPY --from=builder dipper-engine /dipper-engine +COPY --from=builder /dipper-engine /dipper-engine ADD config.json /config.json ENTRYPOINT [ "/dipper-engine" ] \ No newline at end of file diff --git a/Makefile b/Makefile index fd5e179..6c5de56 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ GO111MODULE=on build: - go build + go build -ldflags "-s" test: build go test -cover ./... -covermode=count -coverprofile=coverage.out diff --git a/rules/conditional/conditional_rule_test.go b/rules/conditional/conditional_rule_test.go new file mode 100644 index 0000000..ee61eb8 --- /dev/null +++ b/rules/conditional/conditional_rule_test.go @@ -0,0 +1,97 @@ +package conditional + +import ( + "context" + "github.com/dipper-iot/dipper-engine/data" + "github.com/dipper-iot/dipper-engine/queue" + "testing" +) + +func TestConditionalRule_Run(t *testing.T) { + a := ConditionalRule{} + 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, + Infinite: 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, + Infinite: 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) +}