-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a failable iterator when selecting records (#1917)
* Use a failable iterator when selecting records * Add test to verify failable iterator behaviour
- Loading branch information
1 parent
550f1b1
commit 45d382d
Showing
3 changed files
with
31 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
Tests/ApolloTests/SQLiteDotSwiftDatabaseBehaviorTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import XCTest | ||
@testable import ApolloSQLite | ||
import ApolloTestSupport | ||
import SQLite | ||
|
||
class SQLiteDotSwiftDatabaseBehaviorTests: XCTestCase { | ||
|
||
func testSelection_withForcedError_shouldThrow() throws { | ||
let sqliteFileURL = SQLiteTestCacheProvider.temporarySQLiteFileURL() | ||
let db = try! SQLiteDotSwiftDatabase(fileURL: sqliteFileURL) | ||
|
||
try! db.createRecordsTableIfNeeded() | ||
try! db.addOrUpdateRecordString("record", for: "key") | ||
|
||
var rows = [DatabaseRow]() | ||
XCTAssertNoThrow(rows = try db.selectRawRows(forKeys: ["key"])) | ||
XCTAssertEqual(rows.count, 1) | ||
|
||
// Use SQLite directly to manipulate the database (cannot be done with SQLiteDotSwiftDatabase) | ||
let connection = try Connection(.uri(sqliteFileURL.absoluteString), readonly: false) | ||
let table = Table(SQLiteDotSwiftDatabase.tableName) | ||
try! connection.run(table.drop(ifExists: false)) | ||
|
||
XCTAssertThrowsError(try db.selectRawRows(forKeys: ["key"])) | ||
} | ||
} |