Skip to content

Commit abcab12

Browse files
committed
Add RedisError parsing unit test
1 parent d2fed4f commit abcab12

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

Sources/NIORedis/Data/RedisData.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,12 @@ extension RedisData {
7777
default: return false
7878
}
7979
}
80+
81+
/// Extracts an error from this data
82+
var error: RedisError? {
83+
switch self {
84+
case .error(let error): return error
85+
default: return nil
86+
}
87+
}
8088
}

Tests/NIORedisTests/RedisDataDecoder+ParsingTests.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,22 @@ final class RedisDataDecoderParsingTests: XCTestCase {
101101
}
102102
}
103103

104+
func testParsing_error() {
105+
let expectedContent = "ERR unknown command 'foobar'"
106+
let testString = "-\(expectedContent)\r\n"
107+
let result = runParse(offset: 0) { decoder, position, buffer in
108+
buffer.write(string: testString)
109+
guard
110+
case .parsed(let data) = try decoder._parse(at: &position, from: &buffer),
111+
case .error = data
112+
else { return nil }
113+
114+
return data
115+
}
116+
XCTAssertNotNil(result)
117+
XCTAssertEqual(result?.error?.description.contains(expectedContent), true)
118+
}
119+
104120
/// See parse_Test_singleValue(input:) String
105121
private func parseTest_singleValue(input: String) -> RedisData? {
106122
return parseTest_singleValue(input: input.convertedToData())

0 commit comments

Comments
 (0)