|
412 | 412 | expect(ec_util.get_instance_name('i-2')).to be_nil |
413 | 413 | end |
414 | 414 |
|
| 415 | + describe 'make_spot_instance_request' do |
| 416 | + it 'should make a spot instnace request' do |
| 417 | + ec2_client.stub_responses( |
| 418 | + :describe_spot_instance_requests, |
| 419 | + spot_instance_requests: [{ |
| 420 | + status: { |
| 421 | + code: 'fulfilled' |
| 422 | + } |
| 423 | + }] |
| 424 | + ) |
| 425 | + |
| 426 | + ec2_client.stub_responses( |
| 427 | + :request_spot_instances, |
| 428 | + spot_instance_requests: [{ |
| 429 | + spot_instance_request_id: 'sir-1212121' |
| 430 | + }] |
| 431 | + ) |
| 432 | + |
| 433 | + options = { |
| 434 | + instance_count: 1, |
| 435 | + launch_specification: { |
| 436 | + |
| 437 | + image_id: 'ami-275ffe31', |
| 438 | + instance_type: 'm3.medium' |
| 439 | + }, |
| 440 | + spot_price: '0.016', |
| 441 | + type: 'one-time' |
| 442 | + } |
| 443 | + |
| 444 | + expect { ec_util.make_spot_instance_request(options) }.not_to raise_error |
| 445 | + end |
| 446 | + end |
| 447 | + |
| 448 | + describe 'best_spot_bid_price' do |
| 449 | + it 'should return a list of bid recommendations' do |
| 450 | + ec2_client.stub_responses( |
| 451 | + :describe_spot_price_history, |
| 452 | + JSON.parse(File.read(File.join(File.dirname(__FILE__), '/fixtures/bid_history.json')), symbolize_names: true) |
| 453 | + ) |
| 454 | + |
| 455 | + bid_prices = ec_util.best_spot_bid_price('m3.medium') |
| 456 | + expect(bid_prices).to match_array([ |
| 457 | + ['us-west-1a', 0.08244842404174188], |
| 458 | + ['us-west-1c', 0.07917263606261282] |
| 459 | + ]) |
| 460 | + end |
| 461 | + |
| 462 | + it 'should return a list of bid recommendations (paginate)' do |
| 463 | + ec2_client.stub_responses( |
| 464 | + :describe_spot_price_history, |
| 465 | + [ |
| 466 | + { |
| 467 | + next_token: '1123123', |
| 468 | + spot_price_history: [ |
| 469 | + { |
| 470 | + availability_zone: 'us-west-1a', |
| 471 | + instance_type: 'm3.medium', |
| 472 | + product_description: 'Linux/UNIX (Amazon VPC)', |
| 473 | + spot_price: '0.080000', |
| 474 | + timestamp: Time.parse('2014-01-06T04:32:53.000Z') |
| 475 | + } |
| 476 | + ] |
| 477 | + }, |
| 478 | + { |
| 479 | + next_token: '', |
| 480 | + spot_price_history: [ |
| 481 | + { |
| 482 | + availability_zone: 'us-west-1a', |
| 483 | + instance_type: 'm3.medium', |
| 484 | + product_description: 'Linux/UNIX (Amazon VPC)', |
| 485 | + spot_price: '0.080000', |
| 486 | + timestamp: Time.parse('2014-01-06T04:32:53.000Z') |
| 487 | + } |
| 488 | + ] |
| 489 | + } |
| 490 | + ] |
| 491 | + ) |
| 492 | + |
| 493 | + expect { ec_util.best_spot_bid_price('m3.medium') }.not_to raise_error |
| 494 | + end |
| 495 | + end |
| 496 | + |
415 | 497 | describe '#instances_to_patch_by_tag' do |
416 | 498 | it 'should run without an error with no valid targets' do |
417 | 499 | expect { ec_util.instances_to_patch_by_tag }.not_to raise_error |
|
0 commit comments