Skip to content

Commit d02aa40

Browse files
Bugfix: get search attributes with more tests (#19)
1 parent fdda5b3 commit d02aa40

File tree

5 files changed

+59
-1
lines changed

5 files changed

+59
-1
lines changed

integ/persistence_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package integ
22

33
import (
44
"context"
5+
"fmt"
6+
"github.com/iworkflowio/iwf-golang-sdk/gen/iwfidl"
7+
"github.com/iworkflowio/iwf-golang-sdk/iwf"
58
"github.com/stretchr/testify/assert"
69
"strconv"
710
"testing"
@@ -20,4 +23,42 @@ func TestPersistenceWorkflow(t *testing.T) {
2023
assert.NotEmpty(t, runId)
2124
err = client.GetSimpleWorkflowResult(context.Background(), wfId, "", nil)
2225
assert.Nil(t, err)
26+
info, err := client.DescribeWorkflow(context.Background(), wfId, "")
27+
assert.Nil(t, err)
28+
assert.Equal(t, iwfidl.COMPLETED, info.Status)
29+
dos, err := client.GetWorkflowDataObjects(context.Background(), &persistenceWorkflow{}, wfId, "", []string{
30+
testDataObjectKey,
31+
})
32+
assert.Nil(t, err)
33+
assert.Equal(t, 1, len(dos))
34+
var do ExampleDataObjectModel
35+
dos[testDataObjectKey].Get(&do)
36+
assert.Equal(t, wfId, do.StrValue)
37+
38+
sas, err := client.GetWorkflowSearchAttributes(context.Background(), &persistenceWorkflow{}, wfId, "", []string{
39+
testSearchAttributeKeyword,
40+
testSearchAttributeText,
41+
testSearchAttributeBool,
42+
testSearchAttributeDatetime,
43+
testSearchAttributeInt,
44+
testSearchAttributeDouble,
45+
})
46+
assert.Nil(t, err)
47+
expectedSas := map[string]interface{}{
48+
testSearchAttributeKeyword: "iWF",
49+
testSearchAttributeText: "Hail iWF!",
50+
testSearchAttributeBool: true,
51+
testSearchAttributeDatetime: sas[testSearchAttributeDatetime], // skip this one
52+
testSearchAttributeInt: int64(1),
53+
testSearchAttributeDouble: 1.0,
54+
}
55+
assert.Equal(t, expectedSas, sas)
56+
57+
resp, err := client.SearchWorkflow(context.Background(), iwfidl.WorkflowSearchRequest{
58+
Query: fmt.Sprintf("IwfWorkflowType='%v'", iwf.GetDefaultWorkflowType(&persistenceWorkflow{})),
59+
PageSize: iwfidl.PtrInt32(1),
60+
NextPageToken: nil,
61+
})
62+
assert.Nil(t, err, iwf.GetOpenApiErrorDetailedMessage(err))
63+
assert.True(t, len(resp.WorkflowExecutions) > 0)
2364
}

integ/persistence_workflow_state2.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ func (b persistenceWorkflowState2) Start(ctx iwf.WorkflowContext, input iwf.Obje
3737
if err != nil {
3838
return nil, err
3939
}
40+
err = persistence.SetSearchAttributeDouble(testSearchAttributeDouble, 1.0)
41+
if err != nil {
42+
return nil, err
43+
}
4044
if dv.Unix() == do.Datetime.Unix() && bv == true {
4145
err := persistence.SetSearchAttributeText(testSearchAttributeText, testText)
4246
if err != nil {
@@ -45,6 +49,7 @@ func (b persistenceWorkflowState2) Start(ctx iwf.WorkflowContext, input iwf.Obje
4549
return iwf.EmptyCommandRequest(), nil
4650
}
4751
panic("the value of datatime or bool search attribute is incorrect")
52+
4853
}
4954

5055
func (b persistenceWorkflowState2) Decide(ctx iwf.WorkflowContext, input iwf.Object, commandResults iwf.CommandResults, persistence iwf.Persistence, communication iwf.Communication) (*iwf.StateDecision, error) {

iwf/client_impl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (c *clientImpl) GetWorkflowSearchAttributes(ctx context.Context, workflow W
6262
var keyAndTypes []iwfidl.SearchAttributeKeyAndType
6363
for _, k := range keys {
6464
keyAndTypes = append(keyAndTypes, iwfidl.SearchAttributeKeyAndType{
65-
Key: &k,
65+
Key: ptr.Any(k),
6666
ValueType: ptr.Any(allTypes[k]),
6767
})
6868
}

iwf/errors.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package iwf
22

33
import (
44
"fmt"
5+
"github.com/iworkflowio/iwf-golang-sdk/gen/iwfidl"
56
"log"
67
"net/http"
78
"runtime/debug"
@@ -90,4 +91,13 @@ func captureStateExecutionError(errPanic interface{}, retError *error) {
9091
}
9192
*retError = err
9293
}
94+
}
95+
96+
// GetOpenApiErrorDetailedMessage retrieve the API error body into a string to be human-readable
97+
func GetOpenApiErrorDetailedMessage(err error) string {
98+
oerr, ok := err.(*iwfidl.GenericOpenAPIError)
99+
if !ok {
100+
return "not an OpenAPI Generic Error type"
101+
}
102+
return string(oerr.Body())
93103
}

iwf/persistence_def.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ func getSearchAttributeValue(sa iwfidl.SearchAttribute) (interface{}, error) {
5454
return nil, err
5555
}
5656
return t, nil
57+
case iwfidl.INT:
58+
return *sa.IntegerValue, nil
5759
default:
5860
return nil, fmt.Errorf("unsupported search attribute type %v", sa.GetValueType())
5961
}

0 commit comments

Comments
 (0)