1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
require 'spec_helper'
describe 'os_database_connection' do
it 'refuses String' do
is_expected.to run.with_params('foo').\
and_raise_error(Puppet::ParseError, /Requires an hash/)
end
it 'refuses Array' do
is_expected.to run.with_params(['foo']).\
and_raise_error(Puppet::ParseError, /Requires an hash/)
end
it 'refuses without at least one argument' do
is_expected.to run.with_params().\
and_raise_error(Puppet::ParseError, /Wrong number of arguments/)
end
it 'refuses too many arguments' do
is_expected.to run.with_params('foo', 'bar').\
and_raise_error(Puppet::ParseError, /Wrong number of arguments/)
end
it 'refuses extra params passed as String' do
is_expected.to run.with_params({
'dialect' => 'sqlite',
'database' => '/var/lib/keystone/keystone.db',
'host' => '127.0.0.1',
'port' => '3306',
'extra' => 'charset=utf-8'
}).and_raise_error(Puppet::ParseError, /extra should be a Hash/)
end
it 'fails if port is provided with missing host' do
is_expected.to run.with_params({
'dialect' => 'sqlite',
'database' => '/var/lib/keystone/keystone.db',
'port' => '3306',
'extra' => { 'charset' => 'utf-8' }
}).and_raise_error(Puppet::ParseError, /host is required with port/)
end
context 'creates the correct connection URI' do
it 'with all parameters' do
is_expected.to run.with_params({
'dialect' => 'mysql',
'host' => '127.0.0.1',
'port' => '3306',
'database' => 'test',
'username' => 'guest',
'password' => 's3cr3t',
'extra' => { 'charset' => 'utf-8', 'read_timeout' => '60' }
}).and_return('mysql://guest:s3cr3t@127.0.0.1:3306/test?charset=utf-8&read_timeout=60')
end
it 'with all parameters and charset set' do
is_expected.to run.with_params({
'dialect' => 'mysql',
'host' => '127.0.0.1',
'port' => '3306',
'database' => 'test',
'username' => 'guest',
'password' => 's3cr3t',
'charset' => 'utf-8',
'extra' => { 'charset' => 'latin1', 'read_timeout' => '60' }
}).and_return('mysql://guest:s3cr3t@127.0.0.1:3306/test?charset=utf-8&read_timeout=60')
end
it 'without port' do
is_expected.to run.with_params({
'dialect' => 'mysql',
'host' => '127.0.0.1',
'database' => 'test',
'username' => 'guest',
'password' => 's3cr3t',
'extra' => { 'charset' => 'utf-8' }
}).and_return('mysql://guest:s3cr3t@127.0.0.1/test?charset=utf-8')
end
it 'without host and port' do
is_expected.to run.with_params({
'dialect' => 'sqlite',
'database' => '/var/lib/keystone/keystone.db',
'extra' => { 'charset' => 'utf-8' }
}).and_return('sqlite:////var/lib/keystone/keystone.db?charset=utf-8')
end
it 'without username and password' do
is_expected.to run.with_params({
'dialect' => 'mysql',
'host' => '127.0.0.1',
'port' => '3306',
'database' => 'test',
'extra' => { 'charset' => 'utf-8' }
}).and_return('mysql://127.0.0.1:3306/test?charset=utf-8')
end
it 'with username set to undef' do
is_expected.to run.with_params({
'dialect' => 'mysql',
'host' => '127.0.0.1',
'port' => '3306',
'database' => 'test',
'username' => :undef,
'extra' => { 'charset' => 'utf-8' }
}).and_return('mysql://127.0.0.1:3306/test?charset=utf-8')
end
it 'with username set to an empty string' do
is_expected.to run.with_params({
'dialect' => 'mysql',
'host' => '127.0.0.1',
'port' => '3306',
'database' => 'test',
'username' => '',
'extra' => { 'charset' => 'utf-8' }
}).and_return('mysql://127.0.0.1:3306/test?charset=utf-8')
end
it 'without password' do
is_expected.to run.with_params({
'dialect' => 'mysql',
'host' => '127.0.0.1',
'port' => '3306',
'database' => 'test',
'username' => 'guest',
'extra' => { 'charset' => 'utf-8' }
}).and_return('mysql://guest@127.0.0.1:3306/test?charset=utf-8')
end
it 'with password set to undef' do
is_expected.to run.with_params({
'dialect' => 'mysql',
'host' => '127.0.0.1',
'port' => '3306',
'database' => 'test',
'username' => 'guest',
'password' => :undef,
'extra' => { 'charset' => 'utf-8' }
}).and_return('mysql://guest@127.0.0.1:3306/test?charset=utf-8')
end
it 'with password set to an empty string' do
is_expected.to run.with_params({
'dialect' => 'mysql',
'host' => '127.0.0.1',
'port' => '3306',
'database' => 'test',
'username' => 'guest',
'password' => '',
'extra' => { 'charset' => 'utf-8' }
}).and_return('mysql://guest@127.0.0.1:3306/test?charset=utf-8')
end
end
end
|