Reorganized some of the code and removed unnecessary stuff.
[arvados.git] / spec / google / api_client / discovery_spec.rb
1 # Copyright 2010 Google Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 require 'spec_helper'
16
17 require 'signet/oauth_1/client'
18 require 'httpadapter/adapters/net_http'
19
20 require 'google/api_client'
21 require 'google/api_client/version'
22 require 'google/api_client/parsers/json_parser'
23
24 describe Google::APIClient, 'configured for the prediction API' do
25   before do
26     @client = Google::APIClient.new(:service => 'prediction')
27   end
28
29   it 'should have multiple versions available' do
30     @client.discovered_services.size.should > 1
31   end
32
33   it 'should correctly determine the latest version' do
34     @client.latest_service('prediction').version.should_not == 'v1'
35   end
36
37   it 'should correctly determine the latest version' do
38     # Sanity check the algorithm
39     @client.discovered_services.clear
40     @client.discovered_services <<
41       Google::APIClient::Service.new('magic', 'v1', {})
42     @client.discovered_services <<
43       Google::APIClient::Service.new('magic', 'v1.1', {})
44     @client.discovered_services <<
45       Google::APIClient::Service.new('magic', 'v1.10', {})
46     @client.discovered_services <<
47       Google::APIClient::Service.new('magic', 'v10.1', {})
48     @client.discovered_services <<
49       Google::APIClient::Service.new('magic', 'v2.1', {})
50     @client.discovered_services <<
51       Google::APIClient::Service.new('magic', 'v10.0', {})
52     @client.latest_service('magic').version.should == 'v10.1'
53   end
54
55   it 'should correctly determine the latest version' do
56     # Sanity check the algorithm
57     @client.discovered_services.clear
58     @client.discovered_services <<
59       Google::APIClient::Service.new('one', 'v3', {})
60     @client.discovered_services <<
61       Google::APIClient::Service.new('two', 'v1', {})
62     @client.discovered_services <<
63       Google::APIClient::Service.new('two', 'v2', {})
64     @client.latest_service('two').version.should == 'v2'
65   end
66
67   it 'should return nil for bogus service names' do
68     # Sanity check the algorithm
69     @client.latest_service('bogus').should == nil
70   end
71 end