1010 subject { provider_class }
1111 let ( :additional_install_switches ) { [ ] }
1212
13- def stub_uninstall ( args , installed_features )
13+ def stub_uninstall ( args , installed_features , exit_code = 0 )
1414 cmd_args = [ "#{ args [ :source ] } /setup.exe" ,
1515 "/ACTION=uninstall" ,
1616 '/Q' ,
1717 '/IACCEPTSQLSERVERLICENSETERMS' ,
1818 "/INSTANCENAME=#{ args [ :name ] } " ,
1919 "/FEATURES=#{ installed_features . join ( ',' ) } " , ]
20- Puppet ::Util ::Execution . stubs ( :execute ) . with ( cmd_args . compact ) . returns ( 0 )
20+
21+ result = Puppet ::Util ::Execution ::ProcessOutput . new ( '' , exit_code )
22+ Puppet ::Util ::Execution . stubs ( :execute ) . with ( cmd_args . compact , failonfail : false ) . returns ( result )
2123 end
2224
2325 shared_examples 'run' do |args , munged_values = { } |
@@ -46,7 +48,7 @@ def stub_uninstall(args, installed_features)
4648 @provider . create
4749 }
4850 end
49- shared_examples 'create' do
51+ shared_examples 'create' do | exit_code , warning_matcher |
5052 it {
5153 execute_args = args . merge ( munged_values )
5254 @resource = Puppet ::Type ::Sqlserver_instance . new ( args )
@@ -77,20 +79,27 @@ def stub_uninstall(args, installed_features)
7779 additional_install_switches . each do |switch |
7880 cmd_args << switch
7981 end
80- Puppet ::Util ::Execution . stubs ( :execute ) . with ( cmd_args . compact ) . returns ( 0 )
82+
83+ # If warning_matcher supplied ensure warnings raised match, otherwise no warnings raised
84+ @provider . stubs ( :warn ) . with ( regexp_matches ( warning_matcher ) ) . returns ( nil ) . times ( 1 ) if warning_matcher
85+ @provider . stubs ( :warn ) . with ( anything ) . times ( 0 ) unless warning_matcher
86+
87+ result = Puppet ::Util ::Execution ::ProcessOutput . new ( '' , exit_code || 0 )
88+ Puppet ::Util ::Execution . stubs ( :execute ) . with ( cmd_args . compact , failonfail : false ) . returns ( result )
8189 @provider . create
8290 }
8391 end
8492
8593
86- shared_examples 'destroy' do
94+ shared_examples 'destroy' do | exit_code , warning_matcher |
8795 it {
8896 @resource = Puppet ::Type ::Sqlserver_instance . new ( args )
8997 @provider = provider_class . new ( @resource )
9098
9199 stub_source_which_call args [ :source ]
92100 @provider . expects ( :current_installed_features ) . returns ( installed_features )
93- stub_uninstall args , installed_features
101+ stub_uninstall args , installed_features , exit_code || 0
102+ @provider . stubs ( :warn ) . with ( regexp_matches ( warning_matcher ) ) . returns ( nil ) . times ( 1 ) if warning_matcher
94103 @provider . destroy
95104 }
96105 end
@@ -118,6 +127,30 @@ def stub_uninstall(args, installed_features)
118127 end
119128 end
120129
130+ describe 'it should raise warning on install when 1641 exit code returned' do
131+ it_behaves_like 'create' , 1641 , /reboot initiated/i do
132+ args = get_basic_args
133+ let ( :args ) { args }
134+ munged = { :features => Array . new ( args [ :features ] ) }
135+ munged [ :features ] . delete ( 'SQL' )
136+ munged [ :features ] += %w( DQ FullText Replication SQLEngine )
137+ munged [ :features ] . sort!
138+ let ( :munged_values ) { munged }
139+ end
140+ end
141+
142+ describe 'it should raise warning on install when 3010 exit code returned' do
143+ it_behaves_like 'create' , 3010 , /reboot required/i do
144+ args = get_basic_args
145+ let ( :args ) { args }
146+ munged = { :features => Array . new ( args [ :features ] ) }
147+ munged [ :features ] . delete ( 'SQL' )
148+ munged [ :features ] += %w( DQ FullText Replication SQLEngine )
149+ munged [ :features ] . sort!
150+ let ( :munged_values ) { munged }
151+ end
152+ end
153+
121154 describe 'empty array should' do
122155 it_behaves_like 'destroy on create' do
123156 let ( :installed_features ) { %w( SQLEngine Replication ) }
@@ -140,6 +173,29 @@ def stub_uninstall(args, installed_features)
140173 end
141174
142175 end
176+
177+ describe 'it should raise warning on uninstall when 1641 exit code returned' do
178+ it_behaves_like 'destroy' , 1641 , /reboot initiated/i do
179+ let ( :args ) { {
180+ :name => 'MYSQLSERVER' ,
181+ :source => 'C:\myinstallexecs' ,
182+ :features => [ ]
183+ } }
184+ let ( :installed_features ) { %w( SQLEngine Replication ) }
185+ end
186+ end
187+
188+ describe 'it should raise warning on uninstall when 3010 exit code returned' do
189+ it_behaves_like 'destroy' , 3010 , /reboot required/i do
190+ let ( :args ) { {
191+ :name => 'MYSQLSERVER' ,
192+ :source => 'C:\myinstallexecs' ,
193+ :features => [ ]
194+ } }
195+ let ( :installed_features ) { %w( SQLEngine Replication ) }
196+ end
197+ end
198+
143199 describe 'installed features even if provided features' do
144200 it_behaves_like 'destroy' do
145201 let ( :args ) { {
0 commit comments