Sha256: 0e072bf8297443dc0a94b7955169404792e01ac841133f1da3ff7fc4f457920b

Contents?: true

Size: 1.79 KB

Versions: 4

Compression:

Stored size: 1.79 KB

Contents

require_relative '../helper'

describe 'CfnFlow::CachedStack' do
  subject { CfnFlow::CachedStack }

  describe '.stack_cache' do
    it 'defaults to a hash' do
      subject.stack_cache.must_equal({})
    end
  end

  describe '.get_output' do
    let(:output_value) { 'myvalue' }

    before do
      Aws.config[:cloudformation]= {
        stub_responses: {
          describe_stacks: { stacks: [ stub_stack_data.merge(outputs: [{ output_key: "myoutput", output_value: output_value } ]) ] }
        }
      }
    end

    it 'returns the output' do
      subject.get_output(stack: 'mystack', output: 'myoutput').must_equal output_value
    end

    it 'has required kwargs' do
      -> { subject.get_output }.must_raise(ArgumentError)
    end
  end

  describe 'an instance' do
    subject { CfnFlow::CachedStack.new('mystack') }
    let(:output_value) { 'myvalue' }

    before do
      Aws.config[:cloudformation]= {
        stub_responses: {
          describe_stacks: { stacks: [ stub_stack_data.merge(outputs: [{ output_key: "myoutput", output_value: output_value } ]) ] }
        }
      }
    end

    it "should return the output value" do
      subject.output('myoutput').must_equal output_value
    end

    describe "with a missing output" do
      it "should raise an error" do
        -> { subject.output("no-such-output") }.must_raise(CfnFlow::CachedStack::MissingOutput)
      end
    end

    describe "with a missing stack" do

      subject { CfnFlow::CachedStack.new('no-such-stack') }
      before do
        Aws.config[:cloudformation]= {
          stub_responses: {
            describe_stacks: 'ValidationError'
          }
        }
      end

      it "should raise an error" do
        -> { subject.output('blah') }.must_raise(Aws::CloudFormation::Errors::ValidationError)
      end
    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cfn-flow-0.11.1 spec/cfn_flow/cached_stack_spec.rb
cfn-flow-0.11.0 spec/cfn_flow/cached_stack_spec.rb
cfn-flow-0.10.0 spec/cfn_flow/cached_stack_spec.rb
cfn-flow-0.9.0 spec/cfn_flow/cached_stack_spec.rb