Sha256: 1fe886790d4a5d7a70f7c2fd73070e8c44b467292683676fbe6713c4b9f11caf

Contents?: true

Size: 1.68 KB

Versions: 3

Compression:

Stored size: 1.68 KB

Contents

require "rubygems"
require "bundler/setup"
require "minitest/autorun"
require "minitest/pride"

begin
  require 'pry'
rescue LoadError
  # NBD.
end

require "cfn-flow"

Aws.config[:stub_responses] = true
ENV['AWS_REGION'] = 'us-east-1'
ENV['AWS_ACCESS_KEY_ID'] = 'test-key'
ENV['AWS_SECRET_ACCESS_KEY'] = 'test-secret'
ENV['CFN_FLOW_DEV_NAME'] = 'cfn-flow-specs'
ENV['CFN_FLOW_CONFIG_PATH'] = 'spec/data/cfn-flow.yml'
ENV['CFN_FLOW_EVENT_POLL_INTERVAL'] = '0'

class Minitest::Spec
  before do
    # Reset env between tests:
    @orig_env = ENV.to_hash

    # Disable exit on failure so CLI tests don't bomb out
    CfnFlow.exit_on_failure = false
  end

  after do
    # Reset env
    ENV.clear
    ENV.update(@orig_env)

    # Reset stubs
    CfnFlow.clear!
    Aws.config.delete(:cloudformation)
  end

  def memo_now
    @now = Time.now
  end

  def stub_stack_data(attrs = {})
    {
      stack_name: "mystack",
      stack_status: 'CREATE_COMPLETE',
      creation_time: memo_now,
      tags: [
        {key: 'CfnFlowService', value: CfnFlow.service},
        {key: 'CfnFlowEnvironment', value: 'production'}
      ],
      outputs: [ output_key: 'mykey', output_value: 'myvalue', description: 'My Output' ]
    }.merge(attrs)
  end

  def stub_event_data(attrs = {})
    {
      stack_id: 'mystack',
      stack_name: 'mystack',
      event_id: SecureRandom.hex,
      resource_status: 'CREATE_COMPLETE',
      logical_resource_id: 'stubbed-resource-id',
      resource_type: 'stubbed-resource-type',
      timestamp: Time.now
    }.merge(attrs)
  end

  def stub_event(attrs = {})
    data = stub_event_data(attrs)
    id = data.delete(:event_id)
    Aws::CloudFormation::Event.new(id: id, data: data)
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cfn-flow-0.11.1 spec/helper.rb
cfn-flow-0.11.0 spec/helper.rb
cfn-flow-0.10.0 spec/helper.rb