Skip to content

Commit 7589021

Browse files
authored
fix useResults no default value bug (#91)
Signed-off-by: LiHeng <henrytlh@hotmail.com> Signed-off-by: LiHeng <henrytlh@hotmail.com>
1 parent b4eb66f commit 7589021

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

model/action.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,21 @@ type Action struct {
4141
Condition string `json:"condition,omitempty"`
4242
}
4343

44+
type actionForUnmarshal Action
45+
46+
// UnmarshalJSON ...
47+
func (a *Action) UnmarshalJSON(data []byte) error {
48+
v := actionForUnmarshal{
49+
ActionDataFilter: ActionDataFilter{UseResults: true},
50+
}
51+
err := json.Unmarshal(data, &v)
52+
if err != nil {
53+
return err
54+
}
55+
*a = Action(v)
56+
return nil
57+
}
58+
4459
// FunctionRef ...
4560
type FunctionRef struct {
4661
// Name of the referenced function

parser/parser_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ import (
1919
"path/filepath"
2020
"testing"
2121

22-
"github.com/serverlessworkflow/sdk-go/v2/model"
2322
"github.com/stretchr/testify/assert"
23+
24+
"github.com/serverlessworkflow/sdk-go/v2/model"
2425
)
2526

2627
func TestBasicValidation(t *testing.T) {
@@ -63,6 +64,14 @@ func TestFromFile(t *testing.T) {
6364
assert.IsType(t, &model.OperationState{}, w.States[0])
6465
assert.Equal(t, "greetingFunction", w.States[0].(*model.OperationState).Actions[0].FunctionRef.RefName)
6566
},
67+
}, {
68+
"./testdata/workflows/actiondata-defaultvalue.yaml",
69+
func(t *testing.T, w *model.Workflow) {
70+
assert.Equal(t, "greeting", w.ID)
71+
assert.IsType(t, &model.OperationState{}, w.States[0].(*model.OperationState))
72+
assert.Equal(t, true, w.States[0].(*model.OperationState).Actions[0].ActionDataFilter.UseResults)
73+
assert.Equal(t, "greeting", w.States[0].(*model.OperationState).Actions[0].Name)
74+
},
6675
}, {
6776
"./testdata/workflows/greetings.sw.yaml",
6877
func(t *testing.T, w *model.Workflow) {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright 2020 The Serverless Workflow Specification Authors
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+
15+
id: greeting
16+
version: '1.0'
17+
name: Greeting Workflow
18+
description: Greet Someone
19+
specVersion: "0.8"
20+
start:
21+
stateName: Greet
22+
functions:
23+
- name: greetingFunction
24+
operation: file://myapis/greetingapis.json#greeting
25+
states:
26+
- id: greetingId
27+
name: Greet
28+
type: operation
29+
actions:
30+
- name: greeting
31+
functionRef:
32+
refName: greetingFunction
33+
end:
34+
terminate: true

0 commit comments

Comments
 (0)