]> git.donarmstrong.com Git - dsa-puppet.git/blobdiff - 3rdparty/modules/keystone/spec/unit/provider/keystone_spec.rb
try with modules from master
[dsa-puppet.git] / 3rdparty / modules / keystone / spec / unit / provider / keystone_spec.rb
index de9ceb0d1893a19075d31ae0b4dc637838bcc568..4981f1e5ce2ba6ad2cb7a589c7d6d9d921418581 100644 (file)
@@ -3,10 +3,11 @@ require 'spec_helper'
 require 'puppet/provider/keystone'
 require 'tempfile'
 
-
 klass = Puppet::Provider::Keystone
 
 class Puppet::Provider::Keystone
+  @credentials = Puppet::Provider::Openstack::CredentialsV2_0.new
+
   def self.reset
     @admin_endpoint = nil
     @tenant_hash    = nil
@@ -21,20 +22,15 @@ describe Puppet::Provider::Keystone do
     klass.reset
   end
 
-
   describe 'when retrieving the security token' do
-
     it 'should return nothing if there is no keystone config file' do
-      ini_file = Puppet::Util::IniConfig::File.new
-      t = Tempfile.new('foo')
-      path = t.path
-      t.unlink
-      ini_file.read(path)
+      File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(false)
       expect(klass.get_admin_token).to be_nil
     end
 
     it 'should return nothing if the keystone config file does not have a DEFAULT section' do
       mock = {}
+      File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
       Puppet::Util::IniConfig::File.expects(:new).returns(mock)
       mock.expects(:read).with('/etc/keystone/keystone.conf')
       expect(klass.get_admin_token).to be_nil
@@ -42,6 +38,7 @@ describe Puppet::Provider::Keystone do
 
     it 'should fail if the keystone config file does not contain an admin token' do
       mock = {'DEFAULT' => {'not_a_token' => 'foo'}}
+      File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
       Puppet::Util::IniConfig::File.expects(:new).returns(mock)
       mock.expects(:read).with('/etc/keystone/keystone.conf')
       expect(klass.get_admin_token).to be_nil
@@ -49,65 +46,74 @@ describe Puppet::Provider::Keystone do
 
     it 'should parse the admin token if it is in the config file' do
       mock = {'DEFAULT' => {'admin_token' => 'foo'}}
+      File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
       Puppet::Util::IniConfig::File.expects(:new).returns(mock)
       mock.expects(:read).with('/etc/keystone/keystone.conf')
-      klass.get_admin_token.should == 'foo'
+      expect(klass.get_admin_token).to eq('foo')
     end
 
     it 'should use the specified bind_host in the admin endpoint' do
       mock = {'DEFAULT' => {'admin_bind_host' => '192.168.56.210', 'admin_port' => '35357' }}
+      File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
       Puppet::Util::IniConfig::File.expects(:new).returns(mock)
       mock.expects(:read).with('/etc/keystone/keystone.conf')
-      klass.get_admin_endpoint.should == 'http://192.168.56.210:35357/v2.0/'
+      expect(klass.get_admin_endpoint).to eq('http://192.168.56.210:35357/v2.0/')
     end
 
     it 'should use localhost in the admin endpoint if bind_host is 0.0.0.0' do
       mock = {'DEFAULT' => { 'admin_bind_host' => '0.0.0.0', 'admin_port' => '35357' }}
+      File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
       Puppet::Util::IniConfig::File.expects(:new).returns(mock)
       mock.expects(:read).with('/etc/keystone/keystone.conf')
-      klass.get_admin_endpoint.should == 'http://127.0.0.1:35357/v2.0/'
+      expect(klass.get_admin_endpoint).to eq('http://127.0.0.1:35357/v2.0/')
     end
 
     it 'should use [::1] in the admin endpoint if bind_host is ::0' do
       mock = {'DEFAULT' => { 'admin_bind_host' => '::0', 'admin_port' => '35357' }}
+      File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
       Puppet::Util::IniConfig::File.expects(:new).returns(mock)
       mock.expects(:read).with('/etc/keystone/keystone.conf')
-      klass.get_admin_endpoint.should == 'http://[::1]:35357/v2.0/'
+      expect(klass.get_admin_endpoint).to eq('http://[::1]:35357/v2.0/')
     end
 
     it 'should use localhost in the admin endpoint if bind_host is unspecified' do
       mock = {'DEFAULT' => { 'admin_port' => '35357' }}
+      File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
       Puppet::Util::IniConfig::File.expects(:new).returns(mock)
       mock.expects(:read).with('/etc/keystone/keystone.conf')
-      klass.get_admin_endpoint.should == 'http://127.0.0.1:35357/v2.0/'
+      expect(klass.get_admin_endpoint).to eq('http://127.0.0.1:35357/v2.0/')
     end
 
     it 'should use https if ssl is enabled' do
       mock = {'DEFAULT' => {'admin_bind_host' => '192.168.56.210', 'admin_port' => '35357' }, 'ssl' => {'enable' => 'True'}}
+      File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
       Puppet::Util::IniConfig::File.expects(:new).returns(mock)
       mock.expects(:read).with('/etc/keystone/keystone.conf')
-      klass.get_admin_endpoint.should == 'https://192.168.56.210:35357/v2.0/'
+      expect(klass.get_admin_endpoint).to eq('https://192.168.56.210:35357/v2.0/')
     end
 
     it 'should use http if ssl is disabled' do
       mock = {'DEFAULT' => {'admin_bind_host' => '192.168.56.210', 'admin_port' => '35357' }, 'ssl' => {'enable' => 'False'}}
+      File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
       Puppet::Util::IniConfig::File.expects(:new).returns(mock)
       mock.expects(:read).with('/etc/keystone/keystone.conf')
-      klass.get_admin_endpoint.should == 'http://192.168.56.210:35357/v2.0/'
+      expect(klass.get_admin_endpoint).to eq('http://192.168.56.210:35357/v2.0/')
     end
 
     it 'should use the defined admin_endpoint if available' do
       mock = {'DEFAULT' => {'admin_endpoint' => 'https://keystone.example.com' }, 'ssl' => {'enable' => 'False'}}
+      File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
       Puppet::Util::IniConfig::File.expects(:new).returns(mock)
       mock.expects(:read).with('/etc/keystone/keystone.conf')
-      klass.get_admin_endpoint.should == 'https://keystone.example.com/v2.0/'
+      expect(klass.get_admin_endpoint).to eq('https://keystone.example.com/v2.0/')
     end
 
     it 'should handle an admin_endpoint with a trailing slash' do
       mock = {'DEFAULT' => {'admin_endpoint' => 'https://keystone.example.com/' }, 'ssl' => {'enable' => 'False'}}
+      File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
       Puppet::Util::IniConfig::File.expects(:new).returns(mock)
       mock.expects(:read).with('/etc/keystone/keystone.conf')
-      klass.get_admin_endpoint.should == 'https://keystone.example.com/v2.0/'
+      expect(klass.get_admin_endpoint).to eq('https://keystone.example.com/v2.0/')
     end
 
   end