Skip to content

Commit

Permalink
fix specs
Browse files Browse the repository at this point in the history
  • Loading branch information
tongueroo committed Nov 22, 2017
1 parent ed76dcf commit e430b83
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 11 deletions.
2 changes: 2 additions & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
local: dynamodb-local # port 8000
admin: env AWS_ACCESS_KEY_ID=$DYNAMODB_ADMIN_AWS_ACCESS_KEY_ID PORT=8001 dynamodb-admin # port 8001
11 changes: 7 additions & 4 deletions lib/jets/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ def config
@config ||= RecursiveOpenStruct.new
end

# Jets' the default config/application.rb is loaded,
# then the project's config/application.rb is loaded.
def load_configs
require File.expand_path("../default/application.rb", __FILE__)
app_config = "#{Jets.root}config/application.rb"
require app_config if File.exist?(app_config)
set_aliases!
normalize_environment!
normalize_env_vars!
end

# Use the shorter name in stack names, but use the full name when it
Expand Down Expand Up @@ -48,9 +50,10 @@ def set_aliases!
end
end

# It is pretty easy to attempt to environment variables without the correct
# AWS Environment.Variables path struture. We auto-fix it for convenience.
def normalize_environment!
# It is pretty easy to attempt to set environment variables without
# the correct AWS Environment.Variables path struture.
# Auto-fix it for convenience.
def normalize_env_vars!
environment = config.function.environment
if environment and !environment.to_h.key?(:variables)
config.function.environment = {
Expand Down
1 change: 1 addition & 0 deletions lib/jets/default/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
config.extra_autoload_paths = []

# function properties defaults
config.function = RecursiveOpenStruct.new
config.function.timeout = 10
config.function.runtime = "nodejs6.10"
config.function.memory_size = 1536
Expand Down
5 changes: 4 additions & 1 deletion lib/jets/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ def config
Jets.application.config
end

# Calling application triggers load of configs.
# Jets' the default config/application.rb is loaded,
# then the project's config/application.rb is loaded.
@@application = nil
def application
return @@application if @@application
@@application = Jets::Application.new
@@application.load_configs # triggers load of application configs
@@application.load_configs
@@application
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@
properties = resources["StoresControllerIndexLambdaFunction"]["Properties"]

expect(properties["MemorySize"]).to eq 1000
# should not pascalize the keys under Variables section
expect(properties["DeadLetterConfig"]).to eq "arn"
expect(properties["Timeout"]).to eq 20
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
# pp props
# testing properties(...)
expect(props["MemorySize"]).to eq 1000
expect(props["Role"]).to eq "myrole"
expect(props["Role"]).to eq("Ref"=>"IamRole")
expect(props["Timeout"]).to eq 20
end
end
Expand Down
23 changes: 20 additions & 3 deletions spec/lib/jets/lambda/dsl_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
require "spec_helper"

class TestPropertiesController < ApplicationController
properties(
dead_letter_config: "arn", timeout: 20, role: "myrole", memory_size: 1000
)
def index
end
end

describe Jets::Lambda::Dsl do
context "TestPropertiesController" do
let(:controller) { TestPropertiesController.new({}, nil, "index") }

it "tasks" do
index_task = TestPropertiesController.all_tasks[:index]
expect(index_task).to be_a(Jets::Lambda::Task)
expect(index_task.properties).to eq(
dead_letter_config: "arn", timeout: 20, role: "myrole", memory_size: 1000
)
end
end

context "StoresController" do
let(:controller) { StoresController.new({}, nil, "new") }

Expand All @@ -10,9 +30,6 @@

index_task = StoresController.all_tasks[:index]
expect(index_task).to be_a(Jets::Lambda::Task)
expect(index_task.properties).to eq(
dead_letter_config: "arn", timeout: 20, role: "myrole", memory_size: 1000
)
end

it "timeout" do
Expand Down
9 changes: 9 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ def json_file(path)
end
end

# pretty hacky way of stubbing out md5_code_zipfile
Jets::Naming # autoload it
class Jets::Naming
# override this for specs
def self.md5_code_zipfile
"/tmp/jets/demo/code/code-2e0e18f6.zip"
end
end

RSpec.configure do |c|
c.before(:suite) do
Aws.config.update(stub_responses: true)
Expand Down

0 comments on commit e430b83

Please sign in to comment.