@@ -149,4 +149,88 @@ var _ = Describe("curl Command", func() {
149149 })
150150 })
151151
152+ When ("the response contains binary data" , func () {
153+ var binaryData []byte
154+
155+ BeforeEach (func () {
156+ // Create binary data with null bytes (like a droplet file)
157+ binaryData = []byte {0x50 , 0x4B , 0x03 , 0x04 , 0x00 , 0x00 , 0x08 , 0x00 , 0x00 , 0x00 }
158+ fakeActor .MakeCurlRequestReturns (binaryData , & http.Response {
159+ Header : http.Header {
160+ "Content-Type" : []string {"application/octet-stream" },
161+ },
162+ }, nil )
163+ })
164+
165+ It ("writes binary data directly to stdout without string conversion" , func () {
166+ Expect (executeErr ).NotTo (HaveOccurred ())
167+ Expect (testUI .Out ).To (Say (string (binaryData )))
168+ })
169+
170+ When ("Content-Type is not a known binary MIME type" , func () {
171+ BeforeEach (func () {
172+ // Create binary data with null bytes (like a droplet file)
173+ binaryData = []byte {0x50 , 0x4B , 0x03 , 0x04 , 0x00 , 0x00 , 0x08 , 0x00 , 0x00 , 0x00 }
174+ fakeActor .MakeCurlRequestReturns (binaryData , & http.Response {
175+ Header : http.Header {
176+ "Content-Type" : []string {"text/plain" },
177+ },
178+ }, nil )
179+ })
180+ It ("inspects the response data and writes binary data directly to stdout without string conversion" , func () {
181+ Expect (executeErr ).NotTo (HaveOccurred ())
182+ Expect (testUI .Out ).To (Say (string (binaryData )))
183+ })
184+ })
185+
186+ When ("include-response-headers flag is set" , func () {
187+ BeforeEach (func () {
188+ cmd .IncludeResponseHeaders = true
189+ })
190+
191+ It ("writes headers as text and binary data separately" , func () {
192+ Expect (executeErr ).NotTo (HaveOccurred ())
193+
194+ // Check that headers are written as text (using DisplayTextLiteral)
195+ Expect (testUI .Out ).To (Say ("Content-Type: application/octet-stream" ))
196+
197+ // Check that binary data is preserved
198+ Expect (testUI .Out ).To (Say (string (binaryData )))
199+ })
200+ })
201+
202+ When ("output file is specified" , func () {
203+ BeforeEach (func () {
204+ outputFile , err := os .CreateTemp ("" , "binary-output" )
205+ Expect (err ).NotTo (HaveOccurred ())
206+ cmd .OutputFile = flag .Path (outputFile .Name ())
207+ })
208+
209+ AfterEach (func () {
210+ os .RemoveAll (string (cmd .OutputFile ))
211+ })
212+
213+ It ("writes binary data to the file correctly" , func () {
214+ Expect (executeErr ).NotTo (HaveOccurred ())
215+
216+ fileContents , err := os .ReadFile (string (cmd .OutputFile ))
217+ Expect (err ).ToNot (HaveOccurred ())
218+ Expect (fileContents ).To (Equal (binaryData ))
219+ })
220+ })
221+ })
222+
223+ When ("the response is empty" , func () {
224+ BeforeEach (func () {
225+ fakeActor .MakeCurlRequestReturns ([]byte {}, & http.Response {
226+ Header : http.Header {},
227+ }, nil )
228+ })
229+
230+ It ("handles empty response correctly" , func () {
231+ Expect (executeErr ).NotTo (HaveOccurred ())
232+ Expect (testUI .Out ).To (Say ("" ))
233+ })
234+ })
235+
152236})
0 commit comments