Use discovered 'rootUrl' as base URI for services
[arvados.git] / spec / google / api_client / discovery_spec.rb
index d1c23759ff523698bfad7f901ed8c55368e1f05d..d9acf3374eab2ee28f9b45eada0d4f7de5a80ed6 100644 (file)
@@ -23,6 +23,8 @@ require 'compat/multi_json'
 require 'signet/oauth_1/client'
 require 'google/api_client'
 
+fixtures_path = File.expand_path('../../../fixtures', __FILE__)
+
 RSpec.describe Google::APIClient do
   include ConnectionHelpers
   CLIENT = Google::APIClient.new(:application_name => 'API Client Tests') unless defined?(CLIENT)
@@ -70,6 +72,15 @@ RSpec.describe Google::APIClient do
     expect(CLIENT.preferred_version('bogus')).to eq(nil)
   end
 
+  describe 'with zoo API' do
+    it 'should return API instance registered from file' do
+      zoo_json = File.join(fixtures_path, 'files', 'zoo.json')
+      contents = File.open(zoo_json, 'rb') { |io| io.read }
+      api = CLIENT.register_discovery_document('zoo', 'v1', contents)
+      expect(api).to be_kind_of(Google::APIClient::API)
+    end
+  end
+  
   describe 'with the prediction API' do
     before do
       CLIENT.authorization = nil
@@ -462,6 +473,10 @@ RSpec.describe Google::APIClient do
         ).to_env(CLIENT.connection)
       end).to raise_error(ArgumentError)
     end
+
+    it 'should correctly determine the service root_uri' do
+      expect(@plus.root_uri.to_s).to eq('https://www.googleapis.com/')
+    end
   end
 
   describe 'with the adsense API' do
@@ -648,4 +663,30 @@ RSpec.describe Google::APIClient do
       expect(@drive.files.insert.media_upload.max_size).not_to eq(nil)
     end
   end
+
+  describe 'with the Pub/Sub API' do
+    before do
+      CLIENT.authorization = nil
+      @pubsub = CLIENT.discovered_api('pubsub', 'v1beta2')
+    end
+
+    it 'should generate requests against the correct URIs' do
+      conn = stub_connection do |stub|
+        stub.get('/v1beta2/projects/12345/topics') do |env|
+          expect(env[:url].host).to eq('pubsub.googleapis.com')
+          [200, {}, '{}']
+        end
+      end
+      request = CLIENT.execute(
+        :api_method => @pubsub.projects.topics.list,
+        :parameters => {'project' => 'projects/12345'},
+        :connection => conn
+      )
+      conn.verify
+    end
+
+    it 'should correctly determine the service root_uri' do
+      expect(@pubsub.root_uri.to_s).to eq('https://pubsub.googleapis.com/')
+    end
+  end
 end