Skip to content

A native macOS / windows / Linux database IDE built with Swift and AppKit. Connect to PostgreSQL, MySQL, SQLite, and Redis from a single app with a fast, keyboard-driven interface.

C++

test(redis): retain context after rejected CLI select

Tobi401e51c1aa32
diff --git a/macos/Tests/GridexTests/RedisAppStateTests.swift b/macos/Tests/GridexTests/RedisAppStateTests.swift
index b6da0d5..43c3382 100644
--- a/macos/Tests/GridexTests/RedisAppStateTests.swift
+++ b/macos/Tests/GridexTests/RedisAppStateTests.swift
@@ -956,6 +956,33 @@ final class RedisAppStateTests: XCTestCase {
XCTAssertNil(state.activeRedisAdapter(for: oldContext))
}
+ func test_redisCLISelectServerErrorKeepsThePreviouslySelectedDatabase() async throws {
+ let state = AppState()
+ establishRedisContext(
+ on: state,
+ adapter: RedisAdapter(),
+ connectionID: UUID(uuidString: "11111111-1111-1111-1111-111111111111")!,
+ databaseName: "db0"
+ )
+
+ let result = await state.performRedisCLIStatement("SELECT 999") { _, _ in
+ QueryResult(
+ columns: [ColumnHeader(name: "error", dataType: "string")],
+ rows: [[.string("ERR DB index is out of range")]],
+ rowsAffected: 0,
+ executionTime: 0.01,
+ queryType: .select
+ )
+ }
+
+ guard case .success(let queryResult)? = result else {
+ return XCTFail("Expected the Redis error response to remain displayable")
+ }
+ XCTAssertEqual(queryResult.columns.first?.name, "error")
+ XCTAssertEqual(state.currentDatabaseName, "db0")
+ XCTAssertEqual(state.currentRedisContext?.databaseName, "db0")
+ }
+
func test_redisCLINonSelectSerializesWithTransitionAndDiscardsStaleResult() async throws {
let state = AppState()
establishRedisContext(