lib/stubs/aws_stubs.rb in cloud_powers-0.2.7.7 vs lib/stubs/aws_stubs.rb in cloud_powers-0.2.7.8
- old
+ new
@@ -1,11 +1,32 @@
module Smash
module CloudPowers
- # Provides stubbing for development work in CloudPowers or in a project that uses is
+ # Provides stubbing for development work in CloudPowers or in a project that uses is. Here's a little bit
+ # of a deeper picture, so this all makes sense...
+ # The AWS SDK makes HTTP requests to get things done but if you want to do some development on your project,
+ # it might get pretty expensive. In steps "stubbing". In order to get the SDK to not make any real HTTP
+ # requests and at the same time allow the SDK to respond to your code as if it were really making the requests
+ # you have to give the client that makes the request in question some fake data that it can use when it builds
+ # a response to return to your code. So to stub your client, follow these simple steps:
+ #
+ # 1. pick the appropriate client e.g. +sqs+ for Amazon's queue service, +ec2+ for their EC2 instances, etc
+ # 2. use the +Smash::CloudPowers::AwsResources.<your chosen client>+ method to create the client and
+ # automatically set an appropriate instance variable to that value. This method caches the client so
+ # once you've stubbed it, you can make any call against it that you stubbed. That method should be called
+ # before you need to make any HTTP requests using the client.
+ #
+ # and that's it. You have a stubbed client that you can use for development in your own projects that use
+ # the CloudPowers gem or you can screw around with CloudPowers itself, in the console or something like that
+ # by stubbing the client and making Smash::CloudPowers method calls that use the client you stubbed.
module AwsStubs
# Stub metadata for EC2 instance
+ #
+ # Notes
+ # * defaults can't be overriden or don't have good support for
+ # for it yet but you can use this hash as a guide
+ # for your own custom configuration
def self.instance_metadata_stub(opts = {})
{
'ami-id' => 'ami-1234',
'ami-launch-index' => '1',
'ami-manifest-path' => '',
@@ -50,19 +71,20 @@
# Notes
# * defaults can't be overriden or don't have good support for
# for it yet but you can use this hash as a guide
# for your own custom configuration
def self.node_stub(opts = {})
+ time = opts[:launch_time] || Time.new((Time.now.utc.to_i / 86400 * 86400)) # midnight
{
stub_responses: {
create_tags: {},
run_instances: {
instances: [
- { instance_id: 'asd-1234', launch_time: Time.now, state: { name: 'running' } },
- { instance_id: 'qwe-4323', launch_time: Time.now, state: { name: 'running' } },
- { instance_id: 'tee-4322', launch_time: Time.now, state: { name: 'running' } },
- { instance_id: 'bbf-6969', launch_time: Time.now, state: { name: 'running' } },
- { instance_id: 'lkj-0987', launch_time: Time.now, state: { name: 'running' } },
+ { instance_id: 'asd-1234', launch_time: time, state: { name: 'running' } },
+ { instance_id: 'qwe-4323', launch_time: time , state: { name: 'running' } },
+ { instance_id: 'tee-4322', launch_time: time, state: { name: 'running' } },
+ { instance_id: 'bbf-6969', launch_time: time, state: { name: 'running' } },
+ { instance_id: 'lkj-0987', launch_time: time, state: { name: 'running' } },
]},
describe_instances: {
reservations: [
{ instances: [
{ instance_id: 'asd-1234', state: { code: 200, name: 'running' } },