Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start using Nimble matchers in tests #111

Merged
merged 2 commits into from
Sep 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ end

def tests
pod 'DVR', :git => "https://github.com/czechboy0/DVR.git", :tag => "v0.0.5-czechboy0"
pod 'Nimble', '2.0.0-rc.3'
end

target 'XcodeServerSDK' do
Expand Down
3 changes: 3 additions & 0 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
PODS:
- BuildaUtils (0.1.0)
- DVR (0.0.4-czechboy0)
- Nimble (2.0.0-rc.3)

DEPENDENCIES:
- BuildaUtils (= 0.1.0)
- DVR (from `https://github.com/czechboy0/DVR.git`, tag `v0.0.5-czechboy0`)
- Nimble (= 2.0.0-rc.3)

EXTERNAL SOURCES:
DVR:
Expand All @@ -19,5 +21,6 @@ CHECKOUT OPTIONS:
SPEC CHECKSUMS:
BuildaUtils: cf7756290492ca286935d996c8bf4a3085662514
DVR: 386f347071f55f3f9105239db6764483009ec875
Nimble: 9dff98ee195ffe7351d3b2fb01d3a1420fd97948

COCOAPODS: 0.38.2
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand Down
50 changes: 26 additions & 24 deletions XcodeServerSDKTests/IntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@
import Foundation
import XcodeServerSDK
import XCTest
import Nimble

class IntegrationTests: XCTestCase {

func test_GetIntegration() {

let exp = self.expectationWithDescription("Network")
let server = self.getRecordingXcodeServer("get_integration")
var done = false
server.getIntegration("ad2fac04895bd1bb06c1d50e3400fd35") { (integration, error) in
print("")
exp.fulfill()
expect(error).to(beNil())
expect(integration).toNot(beNil())
done = true
}
self.waitForExpectationsWithTimeout(10, handler: nil)
expect(done).toEventually(beTrue())
}

// MARK: Commits
Expand All @@ -34,57 +36,57 @@ class IntegrationTests: XCTestCase {

func testGetIntegrationCommits() {

let exp = self.expectationWithDescription("Network")
var done = false
let server = self.getRecordingXcodeServer("get_integration_commits")
server.getIntegrationCommits("56ad016e2e3993ca0b8ed276050150e8") { (integrationCommits, error) in
XCTAssertNil(error, "Error should be nil")
server.getIntegrationCommits("56ad016e2e3993ca0b8ed276050150e8") {

(integrationCommits, error) in

expect(error).to(beNil())
guard let integrationCommits = integrationCommits,
let expectationDate = integrationCommits.endedTimeDate,
let commits = integrationCommits.commits["A36AEFA3F9FF1F738E92F0C497C14977DCE02B97"] else {
XCTFail("Integration commits are empty")
fail("Integration commits are empty")
return
}

XCTAssertEqual(expectationDate, self.expectedDate)
XCTAssertEqual(commits.count, 6)
expect(expectationDate) == self.expectedDate
expect(commits.count) == 6

let commiters = Set(commits.map { $0.contributor.name })
XCTAssertEqual(commiters.count, 2)
expect(commiters.count) == 2

exp.fulfill()
done = true
}

self.waitForExpectationsWithTimeout(10, handler: nil)

expect(done).toEventually(beTrue())
}

// MARK: Issues

func testGetIntegrationIssues() {

let exp = self.expectationWithDescription("Network")
var done = false
let server = self.getRecordingXcodeServer("get_integration_issues")
server.getIntegrationIssues("960f6989b4c7289433ff04db71033d28") { (integrationIssues, error) -> () in
XCTAssertNil(error, "Error should be nil")

expect(error).to(beNil())

guard let issues = integrationIssues else {
XCTFail("Integration issues should be present")
fail("Integration issues should be present")
return
}

XCTAssertEqual(issues.errors.count, 1)
expect(issues.errors.count) == 1

let expectation = issues.warnings.filter { $0.status == .Fresh }
XCTAssertEqual(expectation.count, 2)
expect(expectation.count) == 2
expect(issues.analyzerWarnings.isEmpty).to(beTrue())

XCTAssertTrue(issues.analyzerWarnings.isEmpty)

exp.fulfill()
done = true
}

self.waitForExpectationsWithTimeout(10, handler: nil)

expect(done).toEventually(beTrue())
}

}
37 changes: 19 additions & 18 deletions XcodeServerSDKTests/LiveUpdatesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,54 +9,55 @@
import XCTest
import Foundation
@testable import XcodeServerSDK
import Nimble

class LiveUpdatesTests: XCTestCase {

func testParsing_ConnectPacket() {

let message = "1::"
let packets: [SocketIOPacket] = SocketIOHelper.parsePackets(message)
XCTAssertEqual(packets.count, 1)
expect(packets.count) == 1
let packet = packets.first!
XCTAssertEqual(packet.type, SocketIOPacket.PacketType.Connect)
XCTAssertNil(packet.jsonPayload)
XCTAssertEqual(packet.stringPayload, "")
expect(packet.type) == SocketIOPacket.PacketType.Connect
expect(packet.jsonPayload).to(beNil())
expect(packet.stringPayload) == ""
}

func testParsing_ErrorPacket() {
let message = "7:::1+0"
let packets: [SocketIOPacket] = SocketIOHelper.parsePackets(message)
XCTAssertEqual(packets.count, 1)
expect(packets.count) == 1
let packet = packets.first!
XCTAssertEqual(packet.type, SocketIOPacket.PacketType.Error)
expect(packet.type) == SocketIOPacket.PacketType.Error
let (reason, advice) = packet.parseError()
XCTAssertEqual(reason, SocketIOPacket.ErrorReason.ClientNotHandshaken)
XCTAssertEqual(advice, SocketIOPacket.ErrorAdvice.Reconnect)
expect(reason) == SocketIOPacket.ErrorReason.ClientNotHandshaken
expect(advice) == SocketIOPacket.ErrorAdvice.Reconnect
}

func testParsing_SingleEventMessage() {

let message = "5:::{\"name\":\"advisoryIntegrationStatus\",\"args\":[{\"message\":\"BuildaKit : Linking\",\"_id\":\"07a63fae4ff2d5a37eee830be556d143\",\"percentage\":0.7578125,\"botId\":\"07a63fae4ff2d5a37eee830be50c502a\"},null]}"
let packets: [SocketIOPacket] = SocketIOHelper.parsePackets(message)
XCTAssertEqual(packets.count, 1)
expect(packets.count) == 1
let packet = packets.first!
XCTAssertNotNil(packet.jsonPayload)
expect(packet.jsonPayload).toNot(beNil())
let msg = LiveUpdateMessage(json: packet.jsonPayload!)
XCTAssertEqual(msg.type, LiveUpdateMessage.MessageType.AdvisoryIntegrationStatus)
XCTAssertEqual(msg.message, "BuildaKit : Linking")
XCTAssertEqual(msg.integrationId, "07a63fae4ff2d5a37eee830be556d143")
XCTAssertEqual(msg.progress, 0.7578125)
XCTAssertEqual(msg.botId, "07a63fae4ff2d5a37eee830be50c502a")
expect(msg.type) == LiveUpdateMessage.MessageType.AdvisoryIntegrationStatus
expect(msg.message) == "BuildaKit : Linking"
expect(msg.integrationId) == "07a63fae4ff2d5a37eee830be556d143"
expect(msg.progress) == 0.7578125
expect(msg.botId) == "07a63fae4ff2d5a37eee830be50c502a"
}

func testParsing_MultipleEventMessages() {
let message = "�205�5:::{\"name\":\"advisoryIntegrationStatus\",\"args\":[{\"message\":\"Buildasaur : Linking\",\"_id\":\"07a63fae4ff2d5a37eee830be556d143\",\"percentage\":0.8392857360839844,\"botId\":\"07a63fae4ff2d5a37eee830be50c502a\"},null]}�218�5:::{\"name\":\"advisoryIntegrationStatus\",\"args\":[{\"message\":\"Buildasaur : Copying 1 of 3 files\",\"_id\":\"07a63fae4ff2d5a37eee830be556d143\",\"percentage\":0.8571428680419921,\"botId\":\"07a63fae4ff2d5a37eee830be50c502a\"},null]}�218�5:::{\"name\":\"advisoryIntegrationStatus\",\"args\":[{\"message\":\"Buildasaur : Copying 2 of 3 files\",\"_id\":\"07a63fae4ff2d5a37eee830be556d143\",\"percentage\":0.8607142639160156,\"botId\":\"07a63fae4ff2d5a37eee830be50c502a\"},null]}�228�5:::{\"name\":\"advisoryIntegrationStatus\",\"args\":[{\"message\":\"BuildaUtils : Compiling Swift source files\",\"_id\":\"07a63fae4ff2d5a37eee830be556d143\",\"percentage\":0.05511363506317139,\"botId\":\"07a63fae4ff2d5a37eee830be50c502a\"},null]}"
let packets: [SocketIOPacket] = SocketIOHelper.parsePackets(message)
XCTAssertEqual(packets.count, 4)
expect(packets.count) == 4
for packet in packets {
XCTAssertNotNil(packet.jsonPayload)
expect(packet.jsonPayload).toNot(beNil())
let msg = LiveUpdateMessage(json: packet.jsonPayload!)
XCTAssertEqual(msg.type, LiveUpdateMessage.MessageType.AdvisoryIntegrationStatus)
expect(msg.type) == LiveUpdateMessage.MessageType.AdvisoryIntegrationStatus
}
}
}