Skip to content

Commit

Permalink
TO3k7
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardopereira committed Oct 13, 2016
1 parent b943eb2 commit ce0bb41
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions Spec/RestClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,72 @@ class RestClient: QuickSpec {
// RSC15
context("Host Fallback") {

// TO3k7
context("fallbackHostsUseDefault option") {

it("allows the default fallback hosts to be used when @environment@ is not production") {
let options = ARTClientOptions(key: "xxxx:xxxx")
options.environment = "not-production"
options.fallbackHosts = ["fakeA.ably.io", "fakeB.ably.io"]
options.fallbackHostsUseDefault = true

let client = ARTRest(options: options)
expect(client.options.fallbackHostsUseDefault).to(beTrue())
// Not production
expect(client.options.environment).toNot(beNil())
expect(client.options.environment).toNot(equal("production"))

let fallback = ARTFallback(options: client.options)
expect(fallback.hosts).to(haveCount(ARTDefault.fallbackHosts().count))

ARTDefault.fallbackHosts().forEach() {
expect(fallback.hosts).to(contain($0))
}
}

it("allows the default fallback hosts to be used when a custom Realtime or REST host endpoint is being used") {
let options = ARTClientOptions(key: "xxxx:xxxx")
options.restHost = "fake1.ably.io"
options.realtimeHost = "fake2.ably.io"
options.fallbackHosts = ["fakeA.ably.io", "fakeB.ably.io"]
options.fallbackHostsUseDefault = true

let client = ARTRest(options: options)
expect(client.options.fallbackHostsUseDefault).to(beTrue())
// Custom
expect(client.options.restHost).toNot(equal(ARTDefault.restHost()))
expect(client.options.realtimeHost).toNot(equal(ARTDefault.realtimeHost()))

let fallback = ARTFallback(options: client.options)
expect(fallback.hosts).to(haveCount(ARTDefault.fallbackHosts().count))

ARTDefault.fallbackHosts().forEach() {
expect(fallback.hosts).to(contain($0))
}
}

it("should be inactive by default") {
let options = ARTClientOptions(key: "xxxx:xxxx")
expect(options.fallbackHostsUseDefault).to(beFalse())
}

it("should never accept to configure @fallbackHost@ and set @fallbackHostsUseDefault@ to @true@") {
let options = ARTClientOptions(key: "xxxx:xxxx")
expect(options.fallbackHosts).to(beNil())
expect(options.fallbackHostsUseDefault).to(beFalse())

options.fallbackHostsUseDefault = true
options.fallbackHosts = []
expect(options.fallbackHosts).toNot(beNil())
expect(options.fallbackHostsUseDefault).to(beFalse())

options.fallbackHostsUseDefault = true
expect(options.fallbackHosts).to(beNil())
expect(options.fallbackHostsUseDefault).to(beTrue())
}

}

// RSC15b
it("failing HTTP requests with custom endpoint should result in an error immediately") {
let options = ARTClientOptions(key: "xxxx:xxxx")
Expand Down

0 comments on commit ce0bb41

Please sign in to comment.