Skip to content

Commit 87a1e4e

Browse files
committed
simpler
1 parent 2bd394a commit 87a1e4e

File tree

4 files changed

+5
-31
lines changed

4 files changed

+5
-31
lines changed

dbos/admin_server_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,12 @@ func TestAdminServer(t *testing.T) {
347347
// Empty string workflow: both input and output are empty strings
348348
// According to the logic, empty strings should not have Input/Output fields
349349
input, hasInput := wf["Input"]
350-
require.Equal(t, "", input)
350+
require.Equal(t, "\"\"", input)
351351
require.True(t, hasInput, "Empty string workflow should have Input field")
352352

353353
output, hasOutput := wf["Output"]
354354
require.True(t, hasOutput, "Empty string workflow should have Output field")
355-
require.Equal(t, "", output)
355+
require.Equal(t, "\"\"", output)
356356

357357
} else if wfID == structHandle.GetWorkflowID() {
358358
// Struct workflow: input and output should be marshaled as JSON strings
@@ -876,7 +876,7 @@ func TestAdminServer(t *testing.T) {
876876
case "emptyStep":
877877
// Empty string is returned as an empty JSON string
878878
output := step["output"]
879-
require.Equal(t, "", output, "Empty step output should be an empty string")
879+
require.Equal(t, "\"\"", output, "Empty step output should be an empty string")
880880
assert.Nil(t, step["error"], "Empty step should have no error")
881881
}
882882
}

dbos/serialization.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@ func (j *jsonSerializer[T]) Encode(data T) (*string, error) {
2626
}
2727

2828
// Check if the value is a zero value (but not nil)
29-
if isZeroValue(data) {
30-
// For zero values, encode an empty byte slice directly to base64
31-
emptyStr := base64.StdEncoding.EncodeToString([]byte{})
32-
return &emptyStr, nil
33-
}
34-
3529
jsonBytes, err := json.Marshal(data)
3630
if err != nil {
3731
return nil, fmt.Errorf("failed to encode data: %w", err)
@@ -48,10 +42,6 @@ func (j *jsonSerializer[T]) Decode(data *string) (T, error) {
4842

4943
// If *data is an empty string, return zero value
5044
var result T
51-
if *data == "" {
52-
return result, nil
53-
}
54-
5545
dataBytes, err := base64.StdEncoding.DecodeString(*data)
5646
if err != nil {
5747
return result, fmt.Errorf("failed to decode base64 data: %w", err)
@@ -77,21 +67,6 @@ func isNilValue(v any) bool {
7767
return false
7868
}
7969

80-
// isZeroValue checks if a value is a zero value (but not nil).
81-
func isZeroValue(v any) bool {
82-
val := reflect.ValueOf(v)
83-
if !val.IsValid() {
84-
return false
85-
}
86-
// For pointer-like types, if it's not nil, it's not a zero value
87-
switch val.Kind() {
88-
case reflect.Pointer, reflect.Slice, reflect.Map, reflect.Chan, reflect.Func, reflect.Interface:
89-
return false
90-
}
91-
// For other types, check if it's the zero value
92-
return val.IsZero()
93-
}
94-
9570
// getNilOrZeroValue returns nil for pointer types, or zero value for non-pointer types.
9671
func getNilOrZeroValue[T any]() T {
9772
var result T

dbos/serialization_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ func TestSerializer(t *testing.T) {
548548
})
549549

550550
t.Run("Int", func(t *testing.T) {
551-
testAllSerializationPaths(t, executor, recoveryIntWorkflow, 42, "recovery-int-wf")
551+
testAllSerializationPaths(t, executor, recoveryIntWorkflow, 0, "recovery-int-wf")
552552
})
553553

554554
t.Run("EmptyString", func(t *testing.T) {

dbos/workflows_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3223,8 +3223,7 @@ func TestWorkflowTimeout(t *testing.T) {
32233223

32243224
// Wait for the workflow to complete and check the result. Should we AwaitedWorkflowCancelled
32253225
result, err := recoveredHandle.GetResult()
3226-
// Recovery handles are of type any, so when the handle decoded the result into any, it returned a zero value of any, which is nil, not an empty string.
3227-
assert.Nil(t, result, "expected result to be nil")
3226+
assert.Equal(t, "", result, "expected result to be an empty string")
32283227
// Check the error type
32293228
dbosErr, ok := err.(*DBOSError)
32303229
require.True(t, ok, "expected error to be of type *DBOSError, got %T", err)

0 commit comments

Comments
 (0)