@@ -21,7 +21,6 @@ package internal
21
21
22
22
import (
23
23
"context"
24
- "encoding/json"
25
24
"errors"
26
25
"fmt"
27
26
"log"
@@ -32,6 +31,7 @@ import (
32
31
"github.com/golang/mock/gomock"
33
32
"github.com/pborman/uuid"
34
33
"github.com/stretchr/testify/assert"
34
+ "github.com/stretchr/testify/require"
35
35
"github.com/stretchr/testify/suite"
36
36
"go.uber.org/yarpc"
37
37
@@ -1143,8 +1143,7 @@ func (s *workflowClientTestSuite) TestStartWorkflow_WithContext() {
1143
1143
1144
1144
func (s * workflowClientTestSuite ) TestStartWorkflow_WithDataConverter () {
1145
1145
dc := newTestDataConverter ()
1146
- s .client = NewClient (s .service , domain , & ClientOptions {DataConverter : dc })
1147
- client := s .client .(* workflowClient )
1146
+ client := NewClient (s .service , domain , & ClientOptions {DataConverter : dc })
1148
1147
options := StartWorkflowOptions {
1149
1148
ID : workflowID ,
1150
1149
TaskList : tasklist ,
@@ -1156,21 +1155,23 @@ func (s *workflowClientTestSuite) TestStartWorkflow_WithDataConverter() {
1156
1155
}
1157
1156
input := []byte ("test" )
1158
1157
1158
+ correctlyEncoded , err := dc .ToData ([]interface {}{input })
1159
+ require .NoError (s .T (), err , "test data converter should not fail on simple inputs" )
1160
+ defaultEncoded , err := getDefaultDataConverter ().ToData ([]interface {}{input })
1161
+ require .NoError (s .T (), err , "default data converter should not fail on simple inputs" )
1162
+
1163
+ // sanity check: we must be able to tell right from wrong
1164
+ require .NotEqual (s .T (), correctlyEncoded , defaultEncoded , "test data converter should encode differently or the test is not valid" )
1165
+
1159
1166
createResponse := & shared.StartWorkflowExecutionResponse {
1160
1167
RunId : common .StringPtr (runID ),
1161
1168
}
1162
1169
s .service .EXPECT ().StartWorkflowExecution (gomock .Any (), gomock .Any (), gomock .Any ()).Return (createResponse , nil ).
1163
1170
Do (func (_ interface {}, req * shared.StartWorkflowExecutionRequest , _ ... interface {}) {
1164
- dc := client .dataConverter
1165
- encodedArg , _ := dc .ToData (input )
1166
- s .Equal (req .Input , encodedArg )
1167
- var decodedArg []byte
1168
- dc .FromData (req .Input , & decodedArg )
1169
- s .Equal (input , decodedArg )
1171
+ assert .Equal (s .T (), correctlyEncoded , req .Input , "client-encoded data should use the customized data converter" )
1170
1172
})
1171
1173
1172
1174
resp , err := client .StartWorkflow (context .Background (), options , f1 , input )
1173
- s .Equal (newTestDataConverter (), client .dataConverter )
1174
1175
s .NoError (err )
1175
1176
s .Equal (createResponse .GetRunId (), resp .RunID )
1176
1177
}
@@ -1197,14 +1198,8 @@ func (s *workflowClientTestSuite) TestStartWorkflow_WithMemoAndSearchAttr() {
1197
1198
1198
1199
s .service .EXPECT ().StartWorkflowExecution (gomock .Any (), gomock .Any (), gomock .Any ()).Return (startResp , nil ).
1199
1200
Do (func (_ interface {}, req * shared.StartWorkflowExecutionRequest , _ ... interface {}) {
1200
- var resultMemo , resultAttr string
1201
- err := json .Unmarshal (req .Memo .Fields ["testMemo" ], & resultMemo )
1202
- s .NoError (err )
1203
- s .Equal ("memo value" , resultMemo )
1204
-
1205
- err = json .Unmarshal (req .SearchAttributes .IndexedFields ["testAttr" ], & resultAttr )
1206
- s .NoError (err )
1207
- s .Equal ("attr value" , resultAttr )
1201
+ s .Equal (`"memo value"` , req .Memo .Fields ["testMemo" ], "memos must be JSON-encoded" )
1202
+ s .Equal (`"attr value"` , req .SearchAttributes .IndexedFields ["testAttr" ], "search attributes must be JSON-encoded" )
1208
1203
})
1209
1204
1210
1205
_ , err := s .client .StartWorkflow (context .Background (), options , wf )
@@ -1271,14 +1266,8 @@ func (s *workflowClientTestSuite) TestSignalWithStartWorkflow_WithMemoAndSearchA
1271
1266
s .service .EXPECT ().SignalWithStartWorkflowExecution (gomock .Any (), gomock .Any (), gomock .Any (),
1272
1267
gomock .Any (), gomock .Any (), gomock .Any ()).Return (startResp , nil ).
1273
1268
Do (func (_ interface {}, req * shared.SignalWithStartWorkflowExecutionRequest , _ ... interface {}) {
1274
- var resultMemo , resultAttr string
1275
- err := json .Unmarshal (req .Memo .Fields ["testMemo" ], & resultMemo )
1276
- s .NoError (err )
1277
- s .Equal ("memo value" , resultMemo )
1278
-
1279
- err = json .Unmarshal (req .SearchAttributes .IndexedFields ["testAttr" ], & resultAttr )
1280
- s .NoError (err )
1281
- s .Equal ("attr value" , resultAttr )
1269
+ s .Equal (`"memo value"` , req .Memo .Fields ["testMemo" ], "memos must be JSON-encoded" )
1270
+ s .Equal (`"attr value"` , req .SearchAttributes .IndexedFields ["testAttr" ], "search attributes must be JSON-encoded" )
1282
1271
})
1283
1272
1284
1273
_ , err := s .client .SignalWithStartWorkflow (context .Background (), "wid" , "signal" , "value" , options , wf )
@@ -1308,14 +1297,8 @@ func (s *workflowClientTestSuite) TestSignalWithStartWorkflowAsync_WithMemoAndSe
1308
1297
gomock .Any (), gomock .Any (), gomock .Any ()).Return (nil , nil ).
1309
1298
Do (func (_ interface {}, asyncReq * shared.SignalWithStartWorkflowExecutionAsyncRequest , _ ... interface {}) {
1310
1299
req := asyncReq .Request
1311
- var resultMemo , resultAttr string
1312
- err := json .Unmarshal (req .Memo .Fields ["testMemo" ], & resultMemo )
1313
- s .NoError (err )
1314
- s .Equal ("memo value" , resultMemo )
1315
-
1316
- err = json .Unmarshal (req .SearchAttributes .IndexedFields ["testAttr" ], & resultAttr )
1317
- s .NoError (err )
1318
- s .Equal ("attr value" , resultAttr )
1300
+ s .Equal (`"memo value"` , req .Memo .Fields ["testMemo" ], "memos must be JSON-encoded" )
1301
+ s .Equal (`"attr value"` , req .SearchAttributes .IndexedFields ["testAttr" ], "search attributes must be JSON-encoded" )
1319
1302
})
1320
1303
1321
1304
_ , err := s .client .SignalWithStartWorkflowAsync (context .Background (), "wid" , "signal" , "value" , options , wf )
@@ -1394,8 +1377,7 @@ func (s *workflowClientTestSuite) TestStartWorkflowAsync() {
1394
1377
1395
1378
func (s * workflowClientTestSuite ) TestStartWorkflowAsync_WithDataConverter () {
1396
1379
dc := newTestDataConverter ()
1397
- s .client = NewClient (s .service , domain , & ClientOptions {DataConverter : dc })
1398
- client := s .client .(* workflowClient )
1380
+ client := NewClient (s .service , domain , & ClientOptions {DataConverter : dc })
1399
1381
options := StartWorkflowOptions {
1400
1382
ID : workflowID ,
1401
1383
TaskList : tasklist ,
@@ -1407,19 +1389,22 @@ func (s *workflowClientTestSuite) TestStartWorkflowAsync_WithDataConverter() {
1407
1389
}
1408
1390
input := []byte ("test" )
1409
1391
1392
+ // this test requires that the overridden test-data-converter is used, so we need to make sure the encoded input looks correct.
1393
+ // the test data converter's output doesn't actually matter as long as it's noticeably different.
1394
+ correctlyEncoded , err := dc .ToData ([]interface {}{input })
1395
+ require .NoError (s .T (), err , "test data converter should not fail on simple inputs" )
1396
+ wrongDefaultEncoding , err := getDefaultDataConverter ().ToData ([]interface {}{input })
1397
+ require .NoError (s .T (), err , "default data converter should not fail on simple inputs" )
1398
+
1399
+ // sanity check: we must be able to tell right from wrong
1400
+ require .NotEqual (s .T (), correctlyEncoded , wrongDefaultEncoding , "test data converter should encode differently or the test is not valid" )
1401
+
1410
1402
s .service .EXPECT ().StartWorkflowExecutionAsync (gomock .Any (), gomock .Any (), gomock .Any ()).Return (nil , nil ).
1411
1403
Do (func (_ interface {}, asyncReq * shared.StartWorkflowExecutionAsyncRequest , _ ... interface {}) {
1412
- req := asyncReq .Request
1413
- dc := client .dataConverter
1414
- encodedArg , _ := dc .ToData (input )
1415
- s .Equal (req .Input , encodedArg )
1416
- var decodedArg []byte
1417
- dc .FromData (req .Input , & decodedArg )
1418
- s .Equal (input , decodedArg )
1404
+ assert .Equal (s .T (), correctlyEncoded , asyncReq .Request .Input , "client-encoded data should use the customized data converter" )
1419
1405
})
1420
1406
1421
- _ , err := client .StartWorkflowAsync (context .Background (), options , f1 , input )
1422
- s .Equal (newTestDataConverter (), client .dataConverter )
1407
+ _ , err = client .StartWorkflowAsync (context .Background (), options , f1 , input )
1423
1408
s .NoError (err )
1424
1409
}
1425
1410
@@ -1445,14 +1430,8 @@ func (s *workflowClientTestSuite) TestStartWorkflowAsync_WithMemoAndSearchAttr()
1445
1430
s .service .EXPECT ().StartWorkflowExecutionAsync (gomock .Any (), gomock .Any (), gomock .Any ()).Return (nil , nil ).
1446
1431
Do (func (_ interface {}, asyncReq * shared.StartWorkflowExecutionAsyncRequest , _ ... interface {}) {
1447
1432
req := asyncReq .Request
1448
- var resultMemo , resultAttr string
1449
- err := json .Unmarshal (req .Memo .Fields ["testMemo" ], & resultMemo )
1450
- s .NoError (err )
1451
- s .Equal ("memo value" , resultMemo )
1452
-
1453
- err = json .Unmarshal (req .SearchAttributes .IndexedFields ["testAttr" ], & resultAttr )
1454
- s .NoError (err )
1455
- s .Equal ("attr value" , resultAttr )
1433
+ s .Equal (`"memo value"` , req .Memo .Fields ["testMemo" ], "memos must be JSON-encoded" )
1434
+ s .Equal (`"attr value"` , req .SearchAttributes .IndexedFields ["testAttr" ], "search attributes must be JSON-encoded" )
1456
1435
})
1457
1436
1458
1437
_ , err := s .client .StartWorkflowAsync (context .Background (), options , wf )
0 commit comments