Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions flytecopilot/data/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,9 @@ func (d Downloader) handleScalar(ctx context.Context, scalar *core.Scalar, toFil
b := scalar.GetGeneric()
i, err := d.handleGeneric(ctx, b, toFilePath, writeToFile)
return i, scalar, err
case *core.Scalar_Union:
b := scalar.GetUnion()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if it's a non scalar

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, fixed to handle both scalar and non-scalar literals! Also added test cases for either case.

return d.handleScalar(ctx, b.Value.GetScalar(), toFilePath, writeToFile)
case *core.Scalar_NoneType:
if writeToFile {
return nil, scalar, os.WriteFile(toFilePath, []byte("null"), os.ModePerm) // #nosec G306
Expand Down
30 changes: 30 additions & 0 deletions flytecopilot/data/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,33 @@ func TestRecursiveDownload(t *testing.T) {
}
})
}

func TestHandleScalar(t *testing.T) {
t.Run("Handles Union Scalar", func(t *testing.T) {
d := Downloader{}

scalar := &core.Scalar{
Value: &core.Scalar_Union{
Union: &core.Union{
Value: &core.Literal{
Value: &core.Literal_Scalar{
Scalar: &core.Scalar{
Value: &core.Scalar_Primitive{
Primitive: &core.Primitive{
Value: &core.Primitive_StringValue{
StringValue: "string1",
},
},
},
},
},
},
},
},
}

result, _, err := d.handleScalar(context.Background(), scalar, "/inputs", false)
assert.NoError(t, err)
assert.Equal(t, "string1", result)
})
}
Loading