From bb8ee26dced1cfbaa28262680d74e836a6428a5e Mon Sep 17 00:00:00 2001 From: Ferran Rodenas Date: Wed, 25 Feb 2015 16:17:07 -0800 Subject: [PATCH] [google] Add credentials tests --- tests/google/credentials_tests.rb | 73 +++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 tests/google/credentials_tests.rb diff --git a/tests/google/credentials_tests.rb b/tests/google/credentials_tests.rb new file mode 100644 index 000000000..93a53a0f4 --- /dev/null +++ b/tests/google/credentials_tests.rb @@ -0,0 +1,73 @@ +require 'google/api_client' + +Shindo.tests('Google | credentials', ['google']) do + + tests('success') do + pending if Fog.mocking? + + google_key_location = Fog.credentials[:google_key_location] + if google_key_location.nil? + tests('Needs a :google_key_location credentials key').pending + end + google_key_string = File.open(File.expand_path(google_key_location), 'rb') { |io| io.read } + + tests("#using_p12_key_file").succeeds do + Fog::Compute::Google.new(:google_key_location => google_key_location, + :google_key_string => nil, + :google_json_key_location => nil, + :google_json_key_string => nil) + end + + tests("#using_p12_key_string").succeeds do + Fog::Compute::Google.new(:google_key_location => nil, + :google_key_string => google_key_string, + :google_json_key_location => nil, + :google_json_key_string => nil) + end + end + + tests('success') do + pending if Fog.mocking? + + google_json_key_location = Fog.credentials[:google_json_key_location] + if google_json_key_location.nil? + tests('Needs a :google_json_key_location credentials key').pending + end + google_json_key_string = File.open(File.expand_path(google_json_key_location), 'rb') { |io| io.read } + + tests("#using_json_key_file").succeeds do + Fog::Compute::Google.new(:google_key_location => nil, + :google_key_string => nil, + :google_json_key_location => google_json_key_location, + :google_json_key_string => nil) + end + + tests("#using_json_key_string").succeeds do + Fog::Compute::Google.new(:google_key_location => nil, + :google_key_string => nil, + :google_json_key_location => nil, + :google_json_key_string => google_json_key_string) + end + end + + tests('failure') do + tests("#missing_google_project").raises(ArgumentError, 'raises ArgumentError when google_project is missing') do + Fog::Compute::Google.new(:google_project => nil) + end + + tests("#missing_google_client_email").raises(ArgumentError, 'raises ArgumentError when google_client_email is missing') do + pending if Fog.mocking? # Mock doesn't check google_client_email + Fog::Compute::Google.new(:google_client_email => nil, + :google_json_key_location => nil) # JSON key overrides google_client_email + end + + tests("#missing_keys").raises(ArgumentError, 'raises ArgumentError when google keys are missing') do + pending if Fog.mocking? # Mock doesn't check missing keys + Fog::Compute::Google.new(:google_key_location => nil, + :google_key_string => nil, + :google_json_key_location => nil, + :google_json_key_string => nil) + end + end + +end