|
270 | 270 | end
|
271 | 271 |
|
272 | 272 | describe "#run_cmd" do
|
| 273 | + it 'should return a string' do |
| 274 | + p = double('process') |
| 275 | + c = double('channel') |
| 276 | + p.stub(:channel).and_return(c) |
| 277 | + subject.stub_chain('session.sys.process.execute').and_return(p) |
| 278 | + expect(c).to receive(:read).and_return('hello') |
| 279 | + expect(c).to receive(:read).and_return(nil) |
| 280 | + expect(c).to receive(:close) |
| 281 | + expect(p).to receive(:close) |
| 282 | + subject.run_cmd(nil).should eq 'hello' |
| 283 | + end |
| 284 | + end |
| 285 | + |
| 286 | + describe "#run_sql" do |
| 287 | + let(:sqlclient) do |
| 288 | + 'blah' |
| 289 | + end |
| 290 | + |
| 291 | + before(:each) do |
| 292 | + subject.sql_client = sqlclient |
| 293 | + end |
273 | 294 |
|
| 295 | + let(:query) do |
| 296 | + 'SELECT * FROM TABLE;' |
| 297 | + end |
| 298 | + |
| 299 | + let(:instance) do |
| 300 | + 'commandInstance' |
| 301 | + end |
| 302 | + |
| 303 | + let(:server) do |
| 304 | + 'mssql1231' |
| 305 | + end |
| 306 | + |
| 307 | + context 'when only a query is supplied' do |
| 308 | + it 'should pass the @sql_client, and query to run_cmd' do |
| 309 | + expect(subject).to receive(:run_cmd) do |*args| |
| 310 | + args.first.include?(sqlclient).should be_truthy |
| 311 | + args.first.include?("-Q \"#{query}\" ").should be_truthy |
| 312 | + args.first.include?("-S . ").should be_truthy |
| 313 | + end |
| 314 | + subject.run_sql(query) |
| 315 | + end |
| 316 | + end |
| 317 | + |
| 318 | + context 'when a query and instance is supplied' do |
| 319 | + it 'should pass the @sql_client, query, and instance to run_cmd' do |
| 320 | + expect(subject).to receive(:run_cmd) do |*args| |
| 321 | + args.first.include?(sqlclient).should be_truthy |
| 322 | + args.first.include?("-Q \"#{query}\" ").should be_truthy |
| 323 | + args.first.include?("-S .\\#{instance} ").should be_truthy |
| 324 | + end |
| 325 | + subject.run_sql(query, instance) |
| 326 | + end |
| 327 | + |
| 328 | + it 'should shouldnt supply an instance if the target is mssqlserver (7/2000)' do |
| 329 | + expect(subject).to receive(:run_cmd) do |*args| |
| 330 | + args.first.include?(sqlclient).should be_truthy |
| 331 | + args.first.include?("-Q \"#{query}\" ").should be_truthy |
| 332 | + args.first.include?("-S . ").should be_truthy |
| 333 | + end |
| 334 | + subject.run_sql(query, 'mssqlsErver') |
| 335 | + end |
| 336 | + end |
| 337 | + |
| 338 | + context 'when a query, instance, and server is supplied' do |
| 339 | + it 'should pass the @sql_client, query, instance, and server to run_cmd' do |
| 340 | + expect(subject).to receive(:run_cmd) do |*args| |
| 341 | + args.first.include?(sqlclient).should be_truthy |
| 342 | + args.first.include?("-Q \"#{query}\" ").should be_truthy |
| 343 | + args.first.include?("-S #{server}\\#{instance} ").should be_truthy |
| 344 | + end |
| 345 | + subject.run_sql(query, instance, server) |
| 346 | + end |
| 347 | + end |
274 | 348 | end
|
275 | 349 |
|
276 | 350 | let(:osql) do
|
|
0 commit comments