@@ -7,12 +7,41 @@ import (
77 "go.temporal.io/api/common/v1"
88 "go.temporal.io/api/enums/v1"
99 "go.temporal.io/api/history/v1"
10- "go.temporal.io/api/sdk/v1"
1110 "go.temporal.io/server/api/adminservice/v1"
1211 "go.temporal.io/server/api/persistence/v1"
1312 replicationspb "go.temporal.io/server/api/replication/v1"
1413 "go.temporal.io/server/common/persistence/serialization"
15- "google.golang.org/protobuf/types/known/timestamppb"
14+ )
15+
16+ type (
17+ Other struct {}
18+ SAWithTwoFields struct {
19+ Other * Other
20+ SearchAttributes * common.SearchAttributes
21+ }
22+
23+ SAWithTwoFieldsSwapped struct {
24+ SearchAttributes * common.SearchAttributes
25+ Other * Other
26+ }
27+
28+ SAWithOneField struct {
29+ SearchAttributes * common.SearchAttributes
30+ }
31+
32+ SAWithOneMap struct {
33+ SearchAttributes map [string ]* common.Payload
34+ }
35+
36+ SAWithOneMapAndOneField struct {
37+ Other * Other
38+ SearchAttributes map [string ]* common.Payload
39+ }
40+
41+ SAWithOneMapAndOneFieldSwapped struct {
42+ SearchAttributes map [string ]* common.Payload
43+ Other * Other
44+ }
1645)
1746
1847func TestTranslateSearchAttribute (t * testing.T ) {
@@ -21,6 +50,58 @@ func TestTranslateSearchAttribute(t *testing.T) {
2150
2251func generateSearchAttributeObjs () []objCase {
2352 return []objCase {
53+ {
54+ objName : "nil" ,
55+ containsObj : false ,
56+ makeType : func (name string ) any {
57+ return nil
58+ },
59+ },
60+ {
61+ objName : "nil SearchAttributes" ,
62+ containsObj : false ,
63+ makeType : func (name string ) any {
64+ return & persistence.WorkflowExecutionInfo {
65+ NamespaceId : name ,
66+ SearchAttributes : map [string ]* common.Payload (nil ),
67+ }
68+ },
69+ },
70+ {
71+ objName : "nil two fields" ,
72+ makeType : func (name string ) any { return & SAWithTwoFields {} },
73+ },
74+ {
75+ objName : "nil two fields different order" ,
76+ makeType : func (name string ) any { return & SAWithTwoFieldsSwapped {} },
77+ },
78+ {
79+ objName : "nil one field" ,
80+ makeType : func (name string ) any { return & SAWithOneField {} },
81+ },
82+ {
83+ objName : "nil map" ,
84+ makeType : func (name string ) any { return & SAWithOneMap {} },
85+ },
86+ {
87+ objName : "nil map and field" ,
88+ makeType : func (name string ) any { return & SAWithOneMapAndOneField {} },
89+ },
90+ {
91+ objName : "nil map and field different order" ,
92+ makeType : func (name string ) any { return & SAWithOneMapAndOneFieldSwapped {} },
93+ },
94+ {
95+ objName : "nil value in SearchAttributes" ,
96+ containsObj : true ,
97+ makeType : func (name string ) any {
98+ return & persistence.WorkflowExecutionInfo {
99+ SearchAttributes : map [string ]* common.Payload {
100+ name : nil ,
101+ },
102+ }
103+ },
104+ },
24105 {
25106 objName : "HistoryTaskAttributes" ,
26107 containsObj : true ,
@@ -97,18 +178,42 @@ func makeHistoryEventsBlobWithSearchAttribute(name string) *common.DataBlob {
97178 TaskId : 100 ,
98179 Attributes : & history.HistoryEvent_WorkflowExecutionStartedEventAttributes {
99180 WorkflowExecutionStartedEventAttributes : & history.WorkflowExecutionStartedEventAttributes {
100- WorkflowType : & common.WorkflowType {
101- Name : "some-wf-type" ,
102- },
181+ WorkflowType : & common.WorkflowType {Name : "some-wf-type-1" },
103182 SearchAttributes : & common.SearchAttributes {
104183 IndexedFields : makeTestIndexedFieldMap (name ),
105184 },
106185 },
107186 },
108- EventTime : & timestamppb.Timestamp {},
109- WorkerMayIgnore : false ,
110- UserMetadata : & sdk.UserMetadata {},
111- Links : []* common.Link {},
187+ },
188+ {
189+ Attributes : & history.HistoryEvent_WorkflowExecutionStartedEventAttributes {
190+ WorkflowExecutionStartedEventAttributes : & history.WorkflowExecutionStartedEventAttributes {
191+ WorkflowType : & common.WorkflowType {Name : "some-wf-type-2" },
192+ SearchAttributes : nil ,
193+ },
194+ },
195+ },
196+ {
197+ Attributes : & history.HistoryEvent_WorkflowExecutionStartedEventAttributes {
198+ WorkflowExecutionStartedEventAttributes : & history.WorkflowExecutionStartedEventAttributes {
199+ WorkflowType : & common.WorkflowType {Name : "some-wf-type-2" },
200+ SearchAttributes : & common.SearchAttributes {
201+ IndexedFields : nil ,
202+ },
203+ },
204+ },
205+ },
206+ {
207+ Attributes : & history.HistoryEvent_WorkflowExecutionStartedEventAttributes {
208+ WorkflowExecutionStartedEventAttributes : & history.WorkflowExecutionStartedEventAttributes {
209+ WorkflowType : & common.WorkflowType {Name : "some-wf-type-3" },
210+ SearchAttributes : & common.SearchAttributes {
211+ IndexedFields : map [string ]* common.Payload {
212+ name : nil ,
213+ },
214+ },
215+ },
216+ },
112217 },
113218 }
114219
0 commit comments