envato / cloudformation_rspec

Test your CloudFormation templates
MIT License
10 stars 0 forks source link

Error when testing template with Serverless Functions (Transforms) #10

Closed HieronymusLex closed 5 years ago

HieronymusLex commented 5 years ago

I'm having an issue when testing a template which includes a serverless function. When i execute the test, I get the following error:

Failure/Error: expect(stack).to contain_in_change_set("AWS::S3::Bucket", "Bucket")

     NoMethodError:
       undefined method `status_reason' for #<CloudFormationRSpec::ChangeSet:0x00007fdb0b10e850>

Reproducible using a the following template:

Transform: 'AWS::Serverless-2016-10-31'

Resources:
  Function:
    Type: 'AWS::Serverless::Function'
    Properties:
      Handler: index.handler
      Runtime: nodejs8.10
      CodeUri: ./code
  Bucket:
    Type: "AWS::S3::Bucket"

and the following test:

require 'cloudformation_rspec'

describe 'template' do
  let(:template_body) { File.read('template.yaml') }

  let(:stack) {{
    template_body: template_body
  }}

  it 'creates bucket' do
    expect(stack).to contain_in_change_set("AWS::S3::Bucket", "Bucket")
  end
end
HieronymusLex commented 5 years ago

looks like it's coming from: https://github.com/envato/cloudformation_rspec/blob/master/lib/cloudformation_rspec/matchers/change_set.rb#L37

I believe from_cloudformation_template returns the CloudFormationRSpec::ChangeSet object rather than the change set result that is expected in L37 of CloudFormationRSpec::Matchers::ChangeSet: https://github.com/envato/cloudformation_rspec/blob/master/lib/cloudformation_rspec/change_set.rb#L26

patrobinson commented 5 years ago

Yeah you're correct, we should have a status_reason attribute on the CloudFormationRSpec::ChangeSet class