Skip to content

Commit

Permalink
fix: Change signature of readBufferFromFile method (box/box-codegen…
Browse files Browse the repository at this point in the history
  • Loading branch information
box-sdk-build authored Sep 30, 2024
1 parent d5b93b5 commit 21e08ff
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .codegen.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "engineHash": "a8a741c", "specHash": "6b64d06", "version": "0.5.0" }
{ "engineHash": "244ba36", "specHash": "6b64d06", "version": "0.5.0" }
3 changes: 2 additions & 1 deletion Sources/Internal/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ public enum Utils {
/// - Parameters:
/// - url: URL for a file to read.
/// - Returns: Data.
public static func readBufferFromFile(url: URL) -> Data {
public static func readBufferFromFile(filePath: String) -> Data {
let url: URL = URL(string: filePath)!
return try! Data(contentsOf: url)
}

Expand Down
5 changes: 3 additions & 2 deletions Tests/Avatars/AvatarsManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ class AvatarsManagerTests: XCTestCase {
XCTAssertTrue(createdAvatar.picUrls!.small != nil)
XCTAssertTrue(createdAvatar.picUrls!.large != nil)
XCTAssertTrue(createdAvatar.picUrls!.preview != nil)
let destinationPath: URL = URL(path: "\(Utils.temporaryDirectoryPath())\(Utils.getUUID())")
let destinationPathString: String = "\(Utils.temporaryDirectoryPath())\(Utils.getUUID())"
let destinationPath: URL = URL(path: destinationPathString)
try await client.avatars.getUserAvatar(userId: user.id, downloadDestinationURL: destinationPath)
XCTAssertTrue(Utils.bufferEquals(buffer1: Utils.readBufferFromFile(url: destinationPath), buffer2: Utils.generateByteBuffer(size: 0)) == false)
XCTAssertTrue(Utils.bufferEquals(buffer1: Utils.readBufferFromFile(filePath: destinationPathString), buffer2: Utils.generateByteBuffer(size: 0)) == false)
try await client.avatars.deleteUserAvatar(userId: user.id)
await XCTAssertThrowsErrorAsync(try await client.avatars.getUserAvatar(userId: user.id, downloadDestinationURL: URL(path: "\(Utils.temporaryDirectoryPath())\(Utils.getUUID())")))
}
Expand Down
6 changes: 3 additions & 3 deletions Tests/Downloads/DownloadsManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class DownloadsManagerTests: XCTestCase {
let fileContentStream: InputStream = Utils.generateByteStreamFromBuffer(buffer: fileBuffer)
let uploadedFiles: Files = try await client.uploads.uploadFile(requestBody: UploadFileRequestBody(attributes: UploadFileRequestBodyAttributesField(name: newFileName, parent: UploadFileRequestBodyAttributesParentField(id: "0")), file: fileContentStream))
let uploadedFile: FileFull = uploadedFiles.entries![0]
let destinationPath: URL = URL(path: "\(Utils.temporaryDirectoryPath())\(Utils.getUUID())")
try await client.downloads.downloadFile(fileId: uploadedFile.id, downloadDestinationURL: destinationPath)
XCTAssertTrue(Utils.bufferEquals(buffer1: Utils.readBufferFromFile(url: destinationPath), buffer2: fileBuffer))
let destinationPathString: String = "\(Utils.temporaryDirectoryPath())\(Utils.getUUID())"
try await client.downloads.downloadFile(fileId: uploadedFile.id, downloadDestinationURL: URL(path: destinationPathString))
XCTAssertTrue(Utils.bufferEquals(buffer1: Utils.readBufferFromFile(filePath: destinationPathString), buffer2: fileBuffer))
try await client.files.deleteFileById(fileId: uploadedFile.id)
}
}
5 changes: 3 additions & 2 deletions Tests/Files/FilesManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ class FilesManagerTests: XCTestCase {
let thumbnailFileName: String = Utils.getUUID()
let thumbnailContentStream: InputStream = Utils.generateByteStream(size: 1024 * 1024)
let thumbnailFile: FileFull = try await uploadFile(fileName: thumbnailFileName, fileStream: thumbnailContentStream)
let destinationPath: URL = URL(path: "\(Utils.temporaryDirectoryPath())\(Utils.getUUID())")
let destinationPathString: String = "\(Utils.temporaryDirectoryPath())\(Utils.getUUID())"
let destinationPath: URL = URL(path: destinationPathString)
try await client.files.getFileThumbnailById(fileId: thumbnailFile.id, extension_: GetFileThumbnailByIdExtension.png, downloadDestinationURL: destinationPath)
XCTAssertTrue(Utils.bufferEquals(buffer1: Utils.readBufferFromFile(url: destinationPath), buffer2: Utils.readByteStream(byteStream: thumbnailContentStream)) == false)
XCTAssertTrue(Utils.bufferEquals(buffer1: Utils.readBufferFromFile(filePath: destinationPathString), buffer2: Utils.readByteStream(byteStream: thumbnailContentStream)) == false)
try await client.files.deleteFileById(fileId: thumbnailFile.id)
}

Expand Down

0 comments on commit 21e08ff

Please sign in to comment.