Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command awspec generate lambda #127

Merged
merged 3 commits into from
Mar 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/awspec/command/generate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def s3_bucket(bucket_name = nil)
end

types_for_generate_all = %w(
iam_policy cloudwatch_alarm directconnect ebs
iam_policy cloudwatch_alarm directconnect ebs lambda
)

types_for_generate_all.each do |type|
Expand Down
1 change: 1 addition & 0 deletions lib/awspec/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
require 'awspec/generator/spec/ebs'
require 'awspec/generator/spec/s3_bucket'
require 'awspec/generator/spec/nat_gateway'
require 'awspec/generator/spec/lambda'

# Doc
require 'awspec/generator/doc/type'
Expand Down
29 changes: 29 additions & 0 deletions lib/awspec/generator/spec/lambda.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module Awspec::Generator
module Spec
class Lambda
include Awspec::Helper::Finder
def generate_all
lambda_functions = select_all_lambda_functions
raise 'Not Found lambda' if lambda_functions.empty?
ERB.new(lambda_spec_template, nil, '-').result(binding).chomp
end

def lambda_spec_template
template = <<-'EOF'
<% lambda_functions.each do |function| %>
describe lambda('<%= function.function_name %>') do
it { should exist }
its(:description) { should eq '<%= function.description %>' }
its(:runtime) { should eq '<%= function.runtime %>' }
its(:handler) { should eq '<%= function.handler %>' }
its(:code_size) { should eq <%= function.code_size %> }
its(:timeout) { should eq <%= function.timeout %> }
its(:memory_size) { should eq <%= function.memory_size %> }
end
<% end %>
EOF
template
end
end
end
end
6 changes: 6 additions & 0 deletions lib/awspec/helper/finder/lambda.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ def select_event_source_by_function_arn(function_arn)
})
res.event_source_mappings
end

def select_all_lambda_functions
res = lambda_client.list_functions.map do |responce|
responce.functions
end.flatten
end
end
end
end
7 changes: 5 additions & 2 deletions lib/awspec/stub/lambda.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
{
function_name: 'my-lambda-function-name',
function_arn: 'arn:aws:lambda:us-east-1:123456789012:function:my-lambda-function-name',
runtime: 'nodejs',
description: 'My Lambda Function',
runtime: 'pyhton2.7',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opps!! Thank you!

handler: 'lambda_function.lambda_handler',
timeout: 5,
memory_size: 256
memory_size: 256,
code_size: 1234
}
]
},
Expand Down
23 changes: 23 additions & 0 deletions spec/generator/spec/lambda_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'spec_helper'

describe Awspec::Generator::Spec::Lambda do
before do
Awspec::Stub.load 'lambda'
end
let(:lambda) { Awspec::Generator::Spec::Lambda.new }
it 'generates spec' do
spec = <<-'EOF'

describe lambda('my-lambda-function-name') do
it { should exist }
its(:description) { should eq 'My Lambda Function' }
its(:runtime) { should eq 'pyhton2.7' }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo

its(:handler) { should eq 'lambda_function.lambda_handler' }
its(:code_size) { should eq 1234 }
its(:timeout) { should eq 5 }
its(:memory_size) { should eq 256 }
end
EOF
expect(lambda.generate_all.to_s).to eq spec
end
end
6 changes: 4 additions & 2 deletions spec/type/lambda_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

describe lambda('my-lambda-function-name') do
it { should exist }
its(:function_name) { should eq 'my-lambda-function-name' }
its(:runtime) { should eq 'nodejs' }
its(:description) { should eq 'My Lambda Function' }
its(:runtime) { should eq 'pyhton2.7' }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And again. If it's intentional, add a comment or use something that is less similar to a real word.

its(:handler) { should eq 'lambda_function.lambda_handler' }
its(:code_size) { should eq 1234 }
its(:timeout) { should eq 5 }
its(:memory_size) { should eq 256 }
end
Expand Down