-
Notifications
You must be signed in to change notification settings - Fork 30
/
XcodeServerConfigTests.swift
98 lines (81 loc) · 3.49 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
//
// 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: 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")
}
}
func testInvalidCredentials_MissingPassword() {
XCTempAssertThrowsSpecificError(ConfigurationErrors.InvalidCredentialsProvided) {
_ = try XcodeServerConfig(host: "127.0.0.1", user: "ICanCreateBots", password: nil)
}
}
func testInvalidCredentials_MissingUsername() {
XCTempAssertThrowsSpecificError(ConfigurationErrors.InvalidCredentialsProvided) {
_ = try XcodeServerConfig(host: "127.0.0.1", user: "", password: "hello")
}
}
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", id: "12345")
let expected = [
"host": "https://127.0.0.1",
"user": "ICanCreateBots",
"password": "superSecr3t",
"id": "12345"
]
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")
}
}
}