@@ -90,6 +90,45 @@ def stub_uninstall(args, installed_features, exit_code = 0)
9090 }
9191 end
9292
93+ shared_examples 'create_failure' do |exit_code , error_matcher |
94+ it {
95+ execute_args = args . merge ( munged_values )
96+ @resource = Puppet ::Type ::Sqlserver_instance . new ( args )
97+ @provider = provider_class . new ( @resource )
98+
99+ stub_powershell_call ( subject )
100+ stub_source_which_call args [ :source ]
101+
102+ cmd_args = [ "#{ execute_args [ :source ] } /setup.exe" ,
103+ "/ACTION=install" ,
104+ '/Q' ,
105+ '/IACCEPTSQLSERVERLICENSETERMS' ,
106+ "/INSTANCENAME=#{ execute_args [ :name ] } " ,
107+ "/FEATURES=#{ execute_args [ :features ] . join ( ',' ) } " , ]
108+ ( execute_args . keys - %w( ensure loglevel features name source sql_sysadmin_accounts sql_security_mode install_switches ) . map ( &:to_sym ) ) . sort . collect do |key |
109+ cmd_args << "/#{ key . to_s . gsub ( /_/ , '' ) . upcase } =\" #{ @resource [ key ] } \" "
110+ end
111+ if execute_args [ :sql_security_mode ]
112+ cmd_args << "/SECURITYMODE=SQL"
113+ end
114+
115+ # wrap each arg in doublequotes
116+ admin_args = execute_args [ :sql_sysadmin_accounts ] . map { |a | "\" #{ a } \" " }
117+ # prepend first arg only with CLI switch
118+ admin_args [ 0 ] = "/SQLSYSADMINACCOUNTS=" + admin_args [ 0 ]
119+ cmd_args += admin_args
120+
121+ additional_install_switches . each do |switch |
122+ cmd_args << switch
123+ end
124+
125+ @provider . stubs ( :warn ) . with ( anything ) . times ( 0 )
126+
127+ result = Puppet ::Util ::Execution ::ProcessOutput . new ( '' , exit_code || 0 )
128+ Puppet ::Util ::Execution . stubs ( :execute ) . with ( cmd_args . compact , failonfail : false ) . returns ( result )
129+ expect { @provider . create } . to raise_error ( error_matcher )
130+ }
131+ end
93132
94133 shared_examples 'destroy' do |exit_code , warning_matcher |
95134 it {
@@ -127,6 +166,18 @@ def stub_uninstall(args, installed_features, exit_code = 0)
127166 end
128167 end
129168
169+ describe 'it should raise error if as_sysadmin_accounts is specified without AS feature' do
170+ it_behaves_like 'create_failure' , 1 , /as_sysadmin_accounts was specified however the AS feature was not included/i do
171+ args = get_basic_args
172+ args [ :features ] = [ 'SQLEngine' ]
173+ args [ :as_sysadmin_accounts ] = 'username'
174+
175+ let ( :args ) { args }
176+ munged = { :features => Array . new ( args [ :features ] ) }
177+ let ( :munged_values ) { munged }
178+ end
179+ end
180+
130181 describe 'it should raise warning on install when 1641 exit code returned' do
131182 it_behaves_like 'create' , 1641 , /reboot initiated/i do
132183 args = get_basic_args
0 commit comments