Skip to content

Commit 827fe42

Browse files
committed
Add Bot Configuration tests
1 parent 0ae378e commit 827fe42

File tree

3 files changed

+160
-37
lines changed

3 files changed

+160
-37
lines changed

XcodeServerSDK.xcodeproj/project.pbxproj

+5-1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
707D089E1B2C6A1F003900F3 /* TriggerConditions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 707D089D1B2C6A1F003900F3 /* TriggerConditions.swift */; };
7979
709ED67C1B35FD3F00A06038 /* XcodeServerEntityTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 709ED67B1B35FD3F00A06038 /* XcodeServerEntityTests.swift */; };
8080
709ED6801B3608FC00A06038 /* XcodeServerConfigTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 709ED67F1B3608FC00A06038 /* XcodeServerConfigTests.swift */; };
81+
70B21FF81B3AFB1D00EAD4EB /* BotConfigurationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70B21FF71B3AFB1D00EAD4EB /* BotConfigurationTests.swift */; };
8182
/* End PBXBuildFile section */
8283

8384
/* Begin PBXContainerItemProxy section */
@@ -141,6 +142,7 @@
141142
707D089D1B2C6A1F003900F3 /* TriggerConditions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TriggerConditions.swift; sourceTree = "<group>"; };
142143
709ED67B1B35FD3F00A06038 /* XcodeServerEntityTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XcodeServerEntityTests.swift; sourceTree = "<group>"; };
143144
709ED67F1B3608FC00A06038 /* XcodeServerConfigTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XcodeServerConfigTests.swift; sourceTree = "<group>"; };
145+
70B21FF71B3AFB1D00EAD4EB /* BotConfigurationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BotConfigurationTests.swift; sourceTree = "<group>"; };
144146
/* End PBXFileReference section */
145147

146148
/* Begin PBXFrameworksBuildPhase section */
@@ -247,8 +249,9 @@
247249
709ED67B1B35FD3F00A06038 /* XcodeServerEntityTests.swift */,
248250
3A058A8D1B31595A0077FD47 /* BotParsingTests.swift */,
249251
3A058A921B315BB50077FD47 /* TestUtils.swift */,
250-
3A7B48CA1B2A5AC40077ABEA /* Supporting Files */,
251252
705D59A01B3AE502002521BA /* HTTPUtilsTests.swift */,
253+
70B21FF71B3AFB1D00EAD4EB /* BotConfigurationTests.swift */,
254+
3A7B48CA1B2A5AC40077ABEA /* Supporting Files */,
252255
);
253256
path = XcodeServerSDKTests;
254257
sourceTree = "<group>";
@@ -568,6 +571,7 @@
568571
3A058A931B315BB50077FD47 /* TestUtils.swift in Sources */,
569572
3A7B48CD1B2A5AC40077ABEA /* XcodeServerTests.swift in Sources */,
570573
709ED6801B3608FC00A06038 /* XcodeServerConfigTests.swift in Sources */,
574+
70B21FF81B3AFB1D00EAD4EB /* BotConfigurationTests.swift in Sources */,
571575
);
572576
runOnlyForDeploymentPostprocessing = 0;
573577
};

XcodeServerSDK/Server Entities/BotConfiguration.swift

+68-36
Original file line numberDiff line numberDiff line change
@@ -10,71 +10,103 @@ import Foundation
1010

1111
public class BotConfiguration : XcodeServerEntity {
1212

13+
/**
14+
Enum with values describing when Bots history
15+
should be cleaned.
16+
17+
- Never: Never clean
18+
- Always: Clean always project is opened
19+
- Once_a_Day: Clean once a day on first build
20+
- Once_a_Week: Clean once a week on first build
21+
*/
1322
public enum CleaningPolicy : Int {
1423
case Never = 0
1524
case Always
1625
case Once_a_Day
1726
case Once_a_Week
1827

28+
/**
29+
Method for preinting in human readable Bots
30+
cleaning policy
31+
32+
- returns: String with cleaning policy description
33+
*/
1934
public func toString() -> String {
2035
switch self {
21-
case .Never:
22-
return "Never"
23-
case .Always:
24-
return "Always"
25-
case .Once_a_Day:
26-
return "Once a day (first build)"
27-
case .Once_a_Week:
28-
return "Once a week (first build)"
36+
case .Never:
37+
return "Never"
38+
case .Always:
39+
return "Always"
40+
case .Once_a_Day:
41+
return "Once a day (first build)"
42+
case .Once_a_Week:
43+
return "Once a week (first build)"
2944
}
3045
}
3146
}
3247

48+
/**
49+
Enum which describes type of available devices.
50+
51+
- Simulator: iOS simulator (can be any device running iOS)
52+
- Mac: Mac with installed OS X
53+
- iPhone: iOS device (includes iPhone, iPad and iPod Touch)
54+
*/
3355
public enum DeviceType : String {
3456
case Simulator = "com.apple.iphone-simulator"
3557
case Mac = "com.apple.mac"
36-
case iPhone = "com.apple.iphone" //also includes iPad and iPod Touch
58+
case iPhone = "com.apple.iphone"
3759
}
3860

61+
/**
62+
Enum which describes identifiers of devices on which test should be run.
63+
64+
- iOS_AllDevicesAndSimulators: iOS default - for build only
65+
- iOS_AllDevices: All iOS devices
66+
- iOS_AllSimulators: All iOS simulators
67+
- iOS_SelectedDevicesAndSimulators: Manually selected devices/simulators
68+
- Mac: Mac default (probably, crashes when saving in Xcode) - for build only
69+
- AllCompatible: All Compatible (default) - for build only
70+
*/
3971
public enum TestingDestinationIdentifier : Int {
40-
case iOS_AllDevicesAndSimulators = 0 //iOS default - for build only
72+
case iOS_AllDevicesAndSimulators = 0
4173
case iOS_AllDevices = 1
4274
case iOS_AllSimulators = 2
4375
case iOS_SelectedDevicesAndSimulators = 3
44-
case Mac = 7 //Mac default (probably, crashes when saving in Xcode) - for build only
45-
case AllCompatible = 8 //All Compatible default - for build only
76+
case Mac = 7
77+
case AllCompatible = 8
4678

4779
public func toString() -> String {
4880
switch self {
49-
case .iOS_AllDevicesAndSimulators:
50-
return "iOS: All Devices and Simulators"
51-
case .iOS_AllDevices:
52-
return "iOS: All Devices"
53-
case .iOS_AllSimulators:
54-
return "iOS: All Simulators"
55-
case .iOS_SelectedDevicesAndSimulators:
56-
return "iOS: Selected Devices and Simulators"
57-
case .Mac:
58-
return "Mac"
59-
case .AllCompatible:
60-
return "All Compatible (Mac + iOS)"
81+
case .iOS_AllDevicesAndSimulators:
82+
return "iOS: All Devices and Simulators"
83+
case .iOS_AllDevices:
84+
return "iOS: All Devices"
85+
case .iOS_AllSimulators:
86+
return "iOS: All Simulators"
87+
case .iOS_SelectedDevicesAndSimulators:
88+
return "iOS: Selected Devices and Simulators"
89+
case .Mac:
90+
return "Mac"
91+
case .AllCompatible:
92+
return "All Compatible (Mac + iOS)"
6193
}
6294
}
6395

6496
public func allowedDeviceTypes() -> [DeviceType] {
6597
switch self {
66-
case .iOS_AllDevicesAndSimulators:
67-
return [.iPhone, .Simulator]
68-
case .iOS_AllDevices:
69-
return [.iPhone]
70-
case .iOS_AllSimulators:
71-
return [.Simulator]
72-
case .iOS_SelectedDevicesAndSimulators:
73-
return [.iPhone, .Simulator]
74-
case .Mac:
75-
return [.Mac]
76-
case .AllCompatible:
77-
return [.iPhone, .Simulator, .Mac]
98+
case .iOS_AllDevicesAndSimulators:
99+
return [.iPhone, .Simulator]
100+
case .iOS_AllDevices:
101+
return [.iPhone]
102+
case .iOS_AllSimulators:
103+
return [.Simulator]
104+
case .iOS_SelectedDevicesAndSimulators:
105+
return [.iPhone, .Simulator]
106+
case .Mac:
107+
return [.Mac]
108+
case .AllCompatible:
109+
return [.iPhone, .Simulator, .Mac]
78110
}
79111
}
80112
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
//
2+
// BotConfigurationTests.swift
3+
// XcodeServerSDK
4+
//
5+
// Created by Mateusz Zając on 24.06.2015.
6+
// Copyright © 2015 Honza Dvorsky. All rights reserved.
7+
//
8+
9+
import XCTest
10+
import XcodeServerSDK
11+
12+
class BotConfigurationTests: XCTestCase {
13+
14+
override func setUp() {
15+
super.setUp()
16+
// Put setup code here. This method is called before the invocation of each test method in the class.
17+
}
18+
19+
override func tearDown() {
20+
// Put teardown code here. This method is called after the invocation of each test method in the class.
21+
super.tearDown()
22+
}
23+
24+
// MARK: Cleaning policy tests
25+
func testCleaningPolicyToString() {
26+
var policy: BotConfiguration.CleaningPolicy
27+
28+
policy = .Never
29+
XCTAssertEqual(policy.toString(), "Never")
30+
31+
policy = .Always
32+
XCTAssertEqual(policy.toString(), "Always")
33+
34+
policy = .Once_a_Day
35+
XCTAssertEqual(policy.toString(), "Once a day (first build)")
36+
37+
policy = .Once_a_Week
38+
XCTAssertEqual(policy.toString(), "Once a week (first build)")
39+
}
40+
41+
// MARK: Testing destination tests
42+
func testTestingDestinationToString() {
43+
var destination: BotConfiguration.TestingDestinationIdentifier
44+
45+
destination = .iOS_AllDevicesAndSimulators
46+
XCTAssertEqual(destination.toString(), "iOS: All Devices and Simulators")
47+
48+
destination = .iOS_AllDevices
49+
XCTAssertEqual(destination.toString(), "iOS: All Devices")
50+
51+
destination = .iOS_AllSimulators
52+
XCTAssertEqual(destination.toString(), "iOS: All Simulators")
53+
54+
destination = .iOS_SelectedDevicesAndSimulators
55+
XCTAssertEqual(destination.toString(), "iOS: Selected Devices and Simulators")
56+
57+
destination = .Mac
58+
XCTAssertEqual(destination.toString(), "Mac")
59+
60+
destination = .AllCompatible
61+
XCTAssertEqual(destination.toString(), "All Compatible (Mac + iOS)")
62+
}
63+
64+
func testAllowedDevicesTypes() {
65+
let allCompatible = BotConfiguration.TestingDestinationIdentifier.AllCompatible
66+
let selected = BotConfiguration.TestingDestinationIdentifier.iOS_SelectedDevicesAndSimulators
67+
let allDevicesAndSimulators = BotConfiguration.TestingDestinationIdentifier.iOS_AllDevicesAndSimulators
68+
let allDevices = BotConfiguration.TestingDestinationIdentifier.iOS_AllDevices
69+
let allSimulators = BotConfiguration.TestingDestinationIdentifier.iOS_AllSimulators
70+
let mac = BotConfiguration.TestingDestinationIdentifier.Mac
71+
72+
let allCompatibleExpected: [BotConfiguration.DeviceType] = [.iPhone, .Simulator, .Mac]
73+
let selectedExpected: [BotConfiguration.DeviceType] = [.iPhone, .Simulator]
74+
let allDevicesAndSimulatorsExpected: [BotConfiguration.DeviceType] = [.iPhone, .Simulator]
75+
let allDevicesExpected: [BotConfiguration.DeviceType] = [.iPhone]
76+
let allSimulatorsExpected: [BotConfiguration.DeviceType] = [.Simulator]
77+
let macExpected: [BotConfiguration.DeviceType] = [.Mac]
78+
79+
XCTAssertEqual(allCompatible.allowedDeviceTypes(), allCompatibleExpected)
80+
XCTAssertEqual(selected.allowedDeviceTypes(), selectedExpected)
81+
XCTAssertEqual(allDevices.allowedDeviceTypes(), allDevicesExpected)
82+
XCTAssertEqual(allSimulators.allowedDeviceTypes(), allSimulatorsExpected)
83+
XCTAssertEqual(allDevicesAndSimulators.allowedDeviceTypes(), allDevicesAndSimulatorsExpected)
84+
XCTAssertEqual(mac.allowedDeviceTypes(), macExpected)
85+
}
86+
87+
}

0 commit comments

Comments
 (0)