-
Notifications
You must be signed in to change notification settings - Fork 30
/
XcodeServerConfigTests.swift
115 lines (94 loc) · 4.26 KB
/
XcodeServerConfigTests.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//
// XcodeServerConfigTests.swift
// XcodeServerSDK
//
// Created by Mateusz Zając on 20/06/15.
// Copyright © 2015 Honza Dvorsky. All rights reserved.
//
import XCTest
import XcodeServerSDK
class XcodeServerConfigTests: XCTestCase {
// MARK: AvailabilityCheckState testing
func testEqualityOfUncheckedStates() {
XCTAssertEqual(AvailabilityCheckState.Unchecked, AvailabilityCheckState.Unchecked)
}
func testEqualityOfCheckingStates() {
XCTAssertEqual(AvailabilityCheckState.Checking, AvailabilityCheckState.Checking)
}
func testEqualityOfFailedStates() {
let error1 = ConfigurationErrors.InvalidSchemeProvided("http") as NSError
let error2 = ConfigurationErrors.InvalidSchemeProvided("ftp") as NSError
XCTAssertEqual(AvailabilityCheckState.Failed(error1), AvailabilityCheckState.Failed(error2))
}
func testInequalityOfFailedStates() {
let error1 = ConfigurationErrors.NoHostProvided as NSError
let error2 = ConfigurationErrors.InvalidSchemeProvided("ftp") as NSError
XCTAssertNotEqual(AvailabilityCheckState.Failed(error1), AvailabilityCheckState.Failed(error2))
}
func testEqualityOfSucceededStates() {
XCTAssertEqual(AvailabilityCheckState.Succeeded, AvailabilityCheckState.Succeeded)
}
func testInequalityOfUncheckedAndSucceededStates() {
XCTAssertNotEqual(AvailabilityCheckState.Unchecked, AvailabilityCheckState.Succeeded)
}
// MARK: Initialization testing
func testManualInit() {
XCTempAssertNoThrowError("Failed to initialize the server configuration") {
let config = try XcodeServerConfig(host: "127.0.0.1", user: "ICanCreateBots", password: "superSecr3t")
XCTAssertEqual(config.host, "https://127.0.0.1", "Should create proper host address")
XCTAssertEqual(config.user!, "ICanCreateBots")
XCTAssertEqual(config.password!, "superSecr3t")
XCTAssertTrue(config.availabilityState == AvailabilityCheckState.Unchecked)
}
}
func testInvalidHostProvidingForManualInit() {
XCTempAssertThrowsSpecificError(ConfigurationErrors.InvalidHostProvided("Invalid host name provided, please double check your host name")) {
_ = try XcodeServerConfig(host: "<>127.0.0.1", user: "ICanCreateBots", password: "superSecr3t")
}
}
func testDictionaryInit() {
XCTempAssertNoThrowError("Failed to initialize the server configuration") {
let json = [
"host": "https://127.0.0.1",
"user": "ICanCreateBots",
"password": "superSecr3t"
]
let config = try XcodeServerConfig(json: json)
XCTAssertEqual(config.host, "https://127.0.0.1", "Should create proper host address")
XCTAssertEqual(config.user!, "ICanCreateBots")
XCTAssertEqual(config.password!, "superSecr3t")
}
}
func testInvalidDictionaryInit() {
let json = [
"user": "ICanCreateBots",
"password": "superSecr3t"
]
XCTempAssertThrowsSpecificError(ConfigurationErrors.NoHostProvided) {
_ = try XcodeServerConfig(json: json)
}
}
func testInvalidSchemeProvided() {
XCTempAssertThrowsSpecificError(ConfigurationErrors.InvalidSchemeProvided("Xcode Server generally uses https, please double check your hostname")) {
_ = try XcodeServerConfig(host: "http://127.0.0.1")
}
}
// MARK: Returning JSON
func testJsonify() {
XCTempAssertNoThrowError("Failed to initialize the server configuration") {
let config = try XcodeServerConfig(host: "127.0.0.1", user: "ICanCreateBots", password: "superSecr3t")
let expected = [
"host": "https://127.0.0.1",
"user": "ICanCreateBots",
"password": "superSecr3t"
]
XCTAssertEqual(config.jsonify(), expected)
}
}
//just to have a perf test
func testPerformance() {
self.measureBlock { () -> Void in
_ = try! XcodeServerConfig(host: "127.0.0.1", user: "ICanCreateBots", password: "superSecr3t")
}
}
}