-
Notifications
You must be signed in to change notification settings - Fork 0
/
QminderResultTests.swift
58 lines (47 loc) · 1.33 KB
/
QminderResultTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//
// QminderResultTests.swift
// QminderApiTests
//
// Created by Kristaps Grinbergs on 27/02/2018.
// Copyright © 2018 Qminder. All rights reserved.
//
import XCTest
@testable import QminderAPI
class QminderResultTests: XCTestCase {
func testResultSucess() {
let value = UUID().uuidString
let result = Result<String, QminderError>(value)
XCTAssertFalse(result.isFailure)
XCTAssertTrue(result.isSuccess)
XCTAssertEqual(result.value, value)
XCTAssertNil(result.error)
XCTAssertNotNil(result.result)
XCTAssertNotNil(result.description)
switch result {
case let .success(value):
XCTAssertEqual(value, value)
case let .failure(error):
XCTFail("Result should be success \(error)")
}
}
func testResultFailure() {
let result = Result<Int, QminderError>(.apiKeyNotSet)
XCTAssertTrue(result.isFailure)
XCTAssertFalse(result.isSuccess)
XCTAssertNil(result.value)
XCTAssertNotNil(result.error)
XCTAssertNotNil(result.result)
XCTAssertNotNil(result.description)
switch result {
case .success:
XCTFail("Result should be failure")
case let .failure(error):
switch error {
case .apiKeyNotSet:
print("Error set correctly")
default:
XCTFail("Error not correctly set")
}
}
}
}