Skip to content

Commit

Permalink
Catch error and return.
Browse files Browse the repository at this point in the history
  • Loading branch information
jigar-f committed Sep 27, 2023
1 parent 0919d4b commit 5352475
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,19 @@ class TransactionManager: NSObject, MinisqlTxProtocol {
try begin()
}

try statement.run(bindings)
do {
try statement.run(bindings)
} catch let error {
// Check if the error is a UNIQUE constraint error
//Show how if we return same error go is not abel to catch it

let errorMessage = String(describing: error)
if errorMessage.contains("UNIQUE constraint failed") {
throw NSError(domain: "UNIQUE constraint failed", code: 19, userInfo: nil)
} else {
throw error
}
}
return QueryResult(changes: database.totalChanges)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,77 @@

import XCTest
@testable import DatabaseFramework
import Internalsdk

final class DatabaseFrameworkTests: XCTestCase {

override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
final class DatabaseFrameworkTests: XCTestCase,TestsupportTestingTProtocol {
func errorf(_ text: String?) {
XCTFail(text!)
}

override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.

func failNow() {
XCTFail("failing now!")
}

override func setUp() {
super.setUp()
continueAfterFailure = false
}


func testTransactions() throws {
let db = try newDB()
TestsupportTestTransactions(self, db)
}


func testSubscriptions() throws {
let db = try newDB()
TestsupportTestSubscriptions(self, db)
}


func testExample() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
// Any test you write for XCTest can be annotated as throws and async.
// Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
// Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
func testSubscribeToInitialDetails() throws {
let db = try newDB()
TestsupportTestSubscribeToInitialDetails(self, db)
}


func testList() throws {
let db = try newDB()
TestsupportTestList(self, db)
}


func testSearch() throws {
let db = try newDB()
TestsupportTestSearch(self, db)
}

func testSearchChinese() throws {
let db = try newDB()
TestsupportTestSearchChinese(self, db)
}


// Utils methods
private func newDB() throws -> MinisqlDBProtocol {
return try DatabaseFactory.getDbManager(databasePath: newDBPath())
}

func testPerformanceExample() throws {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
private func newDBPath() -> String {
let fileManager = FileManager.default
let directory = fileManager.temporaryDirectory
let subdirectory = UUID().uuidString
let dbDir = directory.appendingPathComponent(subdirectory)

do {
try fileManager.createDirectory(at: dbDir, withIntermediateDirectories: true, attributes: nil)
let dbLocation = dbDir.appendingPathComponent("db").path
return dbLocation
} catch {
return "" // Return an empty string or handle the error accordingly.
}
}

}

0 comments on commit 5352475

Please sign in to comment.