-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathXcodeServerTests.swift
133 lines (97 loc) · 4.61 KB
/
XcodeServerTests.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//
// XcodeServerTests.swift
// XcodeServerSDKTests
//
// Created by Honza Dvorsky on 11/06/2015.
// Copyright (c) 2015 Honza Dvorsky. All rights reserved.
//
import Foundation
import XCTest
@testable import XcodeServerSDK
class XcodeServerTests: XCTestCase {
var server: XcodeServer!
override func setUp() {
super.setUp()
do {
let config = try XcodeServerConfig(
host: "https://127.0.0.1",
user: "ICanCreateBots",
password: "superSecr3t")
self.server = XcodeServerFactory.server(config)
} catch {
XCTFail("Failed to initialize the server configuration: \(error)")
}
}
func testServerCreation() {
XCTAssertNotNil(self.server)
}
// MARK: Creadentials tests
func testCredentials() {
let user = server.credential?.user
let pass = server.credential?.password
XCTAssertEqual(user!, "ICanCreateBots")
XCTAssertEqual(pass!, "superSecr3t")
}
func testNoUserCredentials() {
let noUserConfig = try! XcodeServerConfig(host: "https://127.0.0.1")
let server = XcodeServerFactory.server(noUserConfig)
XCTAssertNil(server.credential)
}
func DEV_testLiveUpdates() {
let exp = self.expectationWithDescription("Network")
let stopHandler = self.server.startListeningForLiveUpdates({ (messages: [LiveUpdateMessage]) -> () in
print(messages)
})
let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(5000 * Double(NSEC_PER_SEC)))
dispatch_after(delayTime, dispatch_get_main_queue(), { () -> Void in
print("stopping")
stopHandler()
exp.fulfill()
})
self.waitForExpectationsWithTimeout(1000) { (_) -> Void in
stopHandler()
}
}
func DEV_testLive_GetBots() {
let exp = self.expectationWithDescription("Network")
self.server.getBots { (bots, error) in
exp.fulfill()
}
self.waitForExpectationsWithTimeout(10, handler: nil)
}
func DEV_testLive_FetchAndRecordBot() {
let exp = self.expectationWithDescription("Network")
let server = self.getRecordingXcodeServer("test_bot")
server.getBots { (bots, error) in
exp.fulfill()
}
self.waitForExpectationsWithTimeout(10, handler: nil)
}
func DEV_testLive_BotCreation() {
let exp = self.expectationWithDescription("wait")
let privateKey = self.stringAtPath("~/.ssh/id_rsa")
let publicKey = self.stringAtPath("~/.ssh/id_rsa.pub")
let blueprint = SourceControlBlueprint(branch: "swift-2", projectWCCIdentifier: "A36AEFA3F9FF1F738E92F0C497C14977DCE02B97", wCCName: "XcodeServerSDK", projectName: "XcodeServerSDK", projectURL: "git@github.com:czechboy0/XcodeServerSDK.git", projectPath: "XcodeServerSDK.xcworkspace", publicSSHKey: publicKey, privateSSHKey: privateKey, sshPassphrase: nil, certificateFingerprint: nil)
let scriptBody = "cd XcodeServerSDK; /usr/local/bin/carthage update --no-build"
let scriptTrigger = Trigger(config: TriggerConfig(phase: .Prebuild, kind: .RunScript, scriptBody: scriptBody, name: "Carthage", conditions: nil, emailConfiguration: nil)!)
let devices = [
"a85553a5b26a7c1a4998f3b237005ac7",
"a85553a5b26a7c1a4998f3b237004afd"
]
let deviceSpec = DeviceSpecification.iOS(.SelectedDevicesAndSimulators, deviceIdentifiers: devices)
let config = BotConfiguration(builtFromClean: BotConfiguration.CleaningPolicy.Once_a_Day, codeCoveragePreference: .UseSchemeSetting, buildConfiguration: .UseSchemeSetting, analyze: true, test: true, archive: true, exportsProductFromArchive: true, schemeName: "XcodeServerSDK - iOS", schedule: BotSchedule.commitBotSchedule(), triggers: [scriptTrigger], deviceSpecification: deviceSpec, sourceControlBlueprint: blueprint)
let bot = Bot(name: "TestBot From XcodeServerSDK", configuration: config)
self.server.createBot(bot) { (response) -> () in
print("")
switch response {
case .Success(let newBot):
self.server.postIntegration(newBot.id) { (integration, error) -> () in
print("")
exp.fulfill()
}
default: break
}
}
self.waitForExpectationsWithTimeout(1000, handler: nil)
}
}