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