|
| 1 | +# |
| 2 | +# Copyright (c) 2014 SoftLayer Technologies, Inc. All rights reserved. |
| 3 | +# |
| 4 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | +# of this software and associated documentation files (the 'Software'), to deal |
| 6 | +# in the Software without restriction, including without limitation the rights |
| 7 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | +# copies of the Software, and to permit persons to whom the Software is |
| 9 | +# furnished to do so, subject to the following conditions: |
| 10 | +# |
| 11 | +# The above copyright notice and this permission notice shall be included in |
| 12 | +# all copies or substantial portions of the Software. |
| 13 | +# |
| 14 | +# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 20 | +# THE SOFTWARE. |
| 21 | +# |
| 22 | + |
| 23 | +$LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '../lib')) |
| 24 | + |
| 25 | +require 'rubygems' |
| 26 | +require 'softlayer_api' |
| 27 | +require 'rspec' |
| 28 | + |
| 29 | +describe SoftLayer::Datacenter do |
| 30 | + let (:mock_client) do |
| 31 | + mock_client = SoftLayer::Client.new(:username => "fakeuser", :api_key => "DEADBEEFBADF00D") |
| 32 | + allow(mock_client[:Location]).to receive(:call_softlayer_api_with_params) do |method_name, parameters, args| |
| 33 | + fixture_from_json('datacenter_locations.json') |
| 34 | + end |
| 35 | + |
| 36 | + mock_client |
| 37 | + end |
| 38 | + |
| 39 | + it "retrieves a list of datacenters" do |
| 40 | + datacenters = SoftLayer::Datacenter.datacenters(mock_client) |
| 41 | + names = datacenters.collect { |datacenter| datacenter.name } |
| 42 | + expect(names.sort).to eq ["ams01", "dal01", "dal02", "dal04", "dal05", "dal06", "dal07", "hkg02", "hou02", "lon02", "sea01", "sjc01", "sng01", "tor01", "wdc01", "wdc03"] |
| 43 | + end |
| 44 | + |
| 45 | + it "retrieves a particular datacenter by name" do |
| 46 | + dal05 = SoftLayer::Datacenter.datacenter_named("dal05", mock_client) |
| 47 | + expect(dal05.name).to eq "dal05" |
| 48 | + expect(dal05.id).to be 138124 |
| 49 | + end |
| 50 | +end |
0 commit comments