-
-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from k1LoW/add-type-lambda
Add lambda type
- Loading branch information
Showing
9 changed files
with
127 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Awspec::Generator | ||
module Doc | ||
module Type | ||
class Lambda < Base | ||
def initialize | ||
super | ||
@type_name = 'Lambda' | ||
@type = Awspec::Type::Lambda.new('my-lambda-function-name') | ||
@ret = @type.function | ||
@matchers = [] | ||
@ignore_matchers = [] | ||
@describes = [] | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module Awspec::Helper | ||
module Finder | ||
module Lambda | ||
def find_lambda(id) | ||
functions = [] | ||
marker = nil | ||
loop do | ||
res = @lambda_client.list_functions( | ||
marker: marker | ||
) | ||
marker = res.next_marker | ||
break if res.functions.empty? | ||
res.functions.each do |function| | ||
if function.function_name == id || function.function_arn == id | ||
functions.push(function) | ||
end | ||
end | ||
break unless marker | ||
end | ||
return functions[0] if functions.count == 1 | ||
end | ||
|
||
def select_event_source_by_function_arn(function_arn) | ||
res = @lambda_client.list_event_source_mappings({ | ||
function_name: function_arn | ||
}) | ||
res[:event_source_mappings] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Aws.config[:lambda] = { | ||
stub_responses: { | ||
list_functions: { | ||
functions: [ | ||
{ | ||
function_name: 'my-lambda-function-name', | ||
function_arn: 'arn:aws:lambda:us-east-1:123456789012:function:my-lambda-function-name', | ||
runtime: 'nodejs', | ||
timeout: 5, | ||
memory_size: 256 | ||
} | ||
] | ||
}, | ||
list_event_source_mappings: { | ||
# @todo | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module Awspec::Type | ||
class Lambda < Base | ||
attr_reader :function | ||
|
||
def initialize(id) | ||
super | ||
@function = find_lambda(id) | ||
@id = @function[:function_arn] if @function | ||
end | ||
|
||
def method_missing(name) | ||
describe = name.to_sym | ||
if @function.members.include?(describe) | ||
@function[describe] | ||
else | ||
super | ||
end | ||
end | ||
|
||
def timeout | ||
@function[:timeout] | ||
end | ||
|
||
def has_event_source?(event_source_arn) | ||
sources = select_event_source_by_function_arn(@id) | ||
sources.find do |source| | ||
source.event_source_arn == event_source_arn | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require 'spec_helper' | ||
Awspec::Stub.load 'lambda' | ||
|
||
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(:timeout) { should eq 5 } | ||
its(:memory_size) { should eq 256 } | ||
end | ||
|
||
describe lambda('not-exist-function') do | ||
it { should_not exist } | ||
end |