Skip to content

Commit

Permalink
update tests to Swift 5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
deeje committed Aug 20, 2019
1 parent 99bc204 commit a9b2157
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ class CoreDataAttributeTests: CoreDataTestCase {
do {
// External binary
if let recordExternalValue = try externalAttribute?.makeRecordValue() as? CKAsset {
let recordData = try Data(contentsOf: recordExternalValue.fileURL)
let recordData = try Data(contentsOf: recordExternalValue.fileURL!)
XCTAssertEqual(recordData, externalData)
} else {
XCTFail("External binary isn't stored correctly")
}

// External big binary
if let recordExternalValue = try externalBigAttribute?.makeRecordValue() as? CKAsset {
let recordData = try Data(contentsOf: recordExternalValue.fileURL)
let recordData = try Data(contentsOf: recordExternalValue.fileURL!)
XCTAssertEqual(recordData, externalBigData)
} else {
XCTFail("External big binary isn't stored correctly")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CoreDataRelationshipTests: CoreDataTestCase {
let filledObjectRecord = try! object.restoreRecordWithSystemFields(for: .private)!

var manyUsers = [UserEntity]()
var manyUsersRecordsIDs = [CKRecordID]()
var manyUsersRecordsIDs = [CKRecord.ID]()
for _ in 0...2 {
let user = UserEntity(context: context)
try! user.setRecordInformation(for: .private)
Expand Down Expand Up @@ -56,12 +56,12 @@ class CoreDataRelationshipTests: CoreDataTestCase {
}

// Check single relationship
let singleReference = filledObjectRecord.value(forKey: "singleRelationship") as! CKReference
let singleReference = filledObjectRecord.value(forKey: "singleRelationship") as! CKRecord.Reference
XCTAssertEqual(manyUsersRecordsIDs[0], singleReference.recordID)

// Check many relationships
let multipleReferences = filledObjectRecord.value(forKey: "manyRelationship") as! [CKReference]
var filledRecordRelationshipIDs = [CKRecordID]()
let multipleReferences = filledObjectRecord.value(forKey: "manyRelationship") as! [CKRecord.Reference]
var filledRecordRelationshipIDs = [CKRecord.ID]()

for recordReference in multipleReferences {
filledRecordRelationshipIDs.append(recordReference.recordID)
Expand Down
2 changes: 1 addition & 1 deletion Tests/CloudCoreTests/CustomFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import XCTest

func XCTAssertThrowsSpecific<T>(_ expression: @autoclosure () throws -> T, _ error: Error) {
XCTAssertThrowsError(expression) { (throwedError) in
XCTAssertThrowsError(try expression()) { (throwedError) in
XCTAssertEqual("\(throwedError)", "\(error)", "XCTAssertThrowsSpecific: errors are not equal")
}
}
Expand Down
5 changes: 3 additions & 2 deletions Tests/CloudCoreTests/Model/CKRecordTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import CloudKit

class CKRecordTests: XCTestCase {
func testEncodeAndInit() {
let zoneID = CKRecordZoneID(zoneName: "zone", ownerName: CKCurrentUserDefaultName)
let record = CKRecord(recordType: "type", zoneID: zoneID)
let zoneID = CKRecordZone.ID(zoneName: "zone", ownerName: CKCurrentUserDefaultName)
let recordID = CKRecord.ID(recordName: "name", zoneID: zoneID)
let record = CKRecord(recordType: "type", recordID: recordID)
record.setValue("testValue", forKey: "testKey")

let encodedData = record.encdodedSystemFields
Expand Down
7 changes: 4 additions & 3 deletions Tests/Shared/CorrectObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ struct CorrectObject {
}

func makeRecord() -> CKRecord {
let record = CKRecord(recordType: "TestEntity", zoneID: CloudCore.config.privateZoneID())

let recordID = CKRecord.ID(recordName: UUID().uuidString, zoneID: CloudCore.config.privateZoneID())
let record = CKRecord(recordType: "TestEntity", recordID: recordID)

let asset = try? CoreDataAttribute.createAsset(for: externalBinary)
XCTAssertNotNil(asset)
record.setValue(asset, forKey: "externalBinary")
Expand Down Expand Up @@ -143,7 +144,7 @@ func assertEqualPlainTextAttributes(_ managedObject: TestEntity, _ record: CKRec

func assertEqualBinaryAttributes(_ managedObject: TestEntity, _ record: CKRecord) {
if let recordAsset = record.value(forKey: "externalBinary") as! CKAsset? {
let downloadedData = try! Data(contentsOf: recordAsset.fileURL)
let downloadedData = try! Data(contentsOf: recordAsset.fileURL!)
XCTAssertEqual(managedObject.externalBinary, downloadedData)
}

Expand Down

0 comments on commit a9b2157

Please sign in to comment.