Permalink
Browse files

fix specs

  • Loading branch information...
tongueroo committed Jan 6, 2019
1 parent cbbfd6b commit cc88c163d8a6e11810fffd8f424edc08cc723310
Showing with 161 additions and 238 deletions.
  1. +1 −0 .gitignore
  2. +1 −0 docs/_docs/shared-resources-depends-on.md
  3. +1 −1 lib/jets/commands/dynamodb/migrator.rb
  4. +3 −1 lib/jets/processors/main_processor.rb
  5. +7 −2 lib/jets/resource/api_gateway/rest_api/logical_id.rb
  6. +0 −2 lib/jets/resource/lambda/layer_version.rb
  7. +1 −1 spec/fixtures/apps/franky/app/controllers/books_controller/node/list.js
  8. +1 −1 spec/fixtures/apps/franky/app/controllers/books_controller/node/node_async.js
  9. +1 −1 spec/fixtures/apps/franky/app/controllers/books_controller/node/node_error_test.js
  10. +2 −2 spec/fixtures/apps/franky/app/controllers/books_controller/python/error_test.py
  11. +2 −2 spec/fixtures/apps/franky/app/controllers/books_controller/python/show.py
  12. 0 spec/fixtures/apps/franky/app/shared/functions/hello.rb
  13. +6 −6 spec/fixtures/apps/franky/config/routes.rb
  14. +0 −19 spec/fixtures/apps/franky/spec/controllers/posts_controller_spec.rb
  15. +0 −32 spec/fixtures/timing/update_stack.log
  16. +7 −14 spec/lib/jets/commands/build_spec.rb
  17. +2 −1 spec/lib/jets/generate_spec.rb
  18. +3 −5 spec/lib/jets/job/base_spec.rb
  19. +4 −5 spec/lib/jets/lambda/dsl_spec.rb
  20. +3 −1 spec/lib/jets/mega/request_spec.rb
  21. +3 −2 spec/lib/jets/middleware/configurator_spec.rb
  22. +2 −1 spec/lib/jets/middleware/default_stack_spec.rb
  23. +11 −2 spec/lib/jets/middleware/stack_spec.rb
  24. +2 −1 spec/lib/jets/middleware_spec.rb
  25. +14 −18 spec/lib/jets/processors/main_processor_spec.rb
  26. +1 −1 spec/lib/jets/resource/api_gateway/method_spec.rb
  27. +4 −11 spec/lib/jets/resource/api_gateway/rest_api/logical_id_spec.rb
  28. +0 −37 spec/lib/jets/resource/api_gateway/rest_api/routes_spec.rb
  29. +1 −1 spec/lib/jets/resource/api_gateway/rest_api_spec.rb
  30. +1 −1 spec/lib/jets/resource/child_stack/api_deployment_spec.rb
  31. +1 −1 spec/lib/jets/resource/child_stack/api_gateway_spec.rb
  32. +3 −3 spec/lib/jets/resource/child_stack/shared_spec.rb
  33. +6 −0 spec/lib/jets/resource/iam/class_role_spec.rb
  34. +8 −1 spec/lib/jets/resource/iam/function_role_spec.rb
  35. +6 −10 spec/lib/jets/resource/iam/policy_document_spec.rb
  36. +13 −0 spec/lib/jets/resource/lambda/gem_layer_spec.rb
  37. +0 −14 spec/lib/jets/resource/lambda/layer_version_spec.rb
  38. +1 −1 spec/lib/jets/resource/permission_spec.rb
  39. +2 −2 spec/lib/jets/resource/route53/record_set_spec.rb
  40. +4 −4 spec/lib/jets/router_spec.rb
  41. +3 −3 spec/lib/jets/rule/base_spec.rb
  42. +4 −3 spec/lib/jets/rule/dsl_spec.rb
  43. +13 −13 spec/lib/jets/stack/builder_spec.rb
  44. +3 −3 spec/lib/jets/stack/function_spec.rb
  45. +1 −2 spec/lib/jets/stack/main_spec.rb
  46. +9 −6 spec/lib/jets/stack_spec.rb
  47. +0 −1 spec/spec_helper.rb
@@ -19,3 +19,4 @@ spec/fixtures/project/handlers
.codebuild/definitions
demo*
/html
spec/fixtures/apps/franky/dynamodb/migrate
@@ -37,6 +37,7 @@ class Alarm < Jets::Stack
threshold: "100",
comparison_operator: "GreaterThanThreshold",
alarm_actions: [ref(:billing_alert)],
)
end
```

@@ -20,7 +20,7 @@ def migrate
path = "#{Jets.root}#{@path}"
unless File.exist?(path)
puts "Unable to find the migration file: #{path}"
exit 1
exit 1 unless ENV['TEST']
end

require path
@@ -28,10 +28,12 @@ def run
# deducer.code => HelloFunction.process(event, context, "world")
# deducer.path => app/functions/hello.rb
deducer.load_class
result = instance_eval(deducer.code, deducer.path)
# result = PostsController.process(event, context, "create")
result = instance_eval(deducer.code, deducer.path)
result = HashWithIndifferentAccess.new(result) if result.is_a?(Hash)

Jets.increase_call_count

if result.is_a?(Hash) && result["headers"]
result["headers"]["x-jets-call-count"] = Jets.call_count
result["headers"]["x-jets-prewarm-count"] = Jets.prewarm_count
@@ -6,14 +6,19 @@ class LogicalId
def get
return default unless stack_exists?(parent_stack_name) && api_gateway_exists?

change_detection = ChangeDetection.new
if change_detection.changed?

if changed?
new_id
else
current
end
end

def changed?
change_detection = ChangeDetection.new
change_detection.changed?
end

# Takes current logical id and increments the number that is appended to it.
#
# Examples:
@@ -15,11 +15,9 @@ def definition
layer_version_logical_id => {
type: "AWS::Lambda::LayerVersion",
properties: {
# compatible_runtimes: ["ruby2.5"],
content: {
s3_bucket: s3_bucket,
s3_key: code_s3_key,
# s3_object_version: string,
},
description: description,
layer_name: layer_name,
@@ -1,6 +1,6 @@
'use strict';

exports.handle = function(event, context, callback) {
exports.handler = function(event, context, callback) {
var body = {'message': 'hi from node'};
var response = {
statusCode: "200",
@@ -1,6 +1,6 @@
'use strict';

exports.handle = async function(event, context) {
exports.handler = async function(event, context) {
var body = {'message': 'hi from node'};
var response = {
statusCode: "200",
@@ -1,6 +1,6 @@
'use strict';

exports.handle = function(event, context, callback) {
exports.handler = function(event, context, callback) {
INTENTIONAL_NODE_ERROR
var body = {'message': 'hi from node'};
var response = {
@@ -13,7 +13,7 @@ def response(message, status_code):
},
}

def handle(event, context):
def lambda_handler(event, context):
# TODO: figure out why this does not print out to stderr with python 3
# print("BooksController#show", file=sys.stderr)
# print(pprint.pformat(event), file=sys.stderr))
@@ -24,4 +24,4 @@ def handle(event, context):
return response({'message': e.message}, 400)

if __name__ == '__main__':
print(handle({"test": "1"}, {}))
print(lambda_handler({"test": "1"}, {}))
@@ -12,7 +12,7 @@ def response(message, status_code):
},
}

def handle(event, context):
def lambda_handler(event, context):
# TODO: figure out why this does not print out to stderr with python 3
# print("BooksController#show", file=sys.stderr)
# print(pprint.pformat(event), file=sys.stderr))
@@ -23,4 +23,4 @@ def handle(event, context):
return response({'message': e.message}, 400)

if __name__ == '__main__':
print(handle({"test": "1"}, {}))
print(lambda_handler({"test": "1"}, {}))
@@ -25,20 +25,20 @@

any "others/*proxy", to: "others#catchall"
# # jets routes these special paths to the JetsPublicFilesController
# any "public/*proxy", to: "public_files#catchall"
# any "javascripts/*proxy", to: "public_files#catchall"
# any "stylesheets/*proxy", to: "public_files#catchall"
# any "public/*proxy", to: "jets/public_files#catchall"
# any "javascripts/*proxy", to: "jets/public_files#catchall"
# any "stylesheets/*proxy", to: "jets/public_files#catchall"

# Catchall routes at the root level work differently in local development
# than on AWS API Gateway. Locally, the rack middleware routes the static
# files directly never hits Jets. On AWS though, there is no rack middleware
# it's all API Gateway. So for a root level catchall route like
#
# any "*catchall", to: "public_files#show"
# any "*catchall", to: "jets/public_files#show"
#
# It cannot be tested locally - at least, I'm don't how to do that yet.
any "static/*catchall", to: "public_files#show"
any "*catchall", to: "public_files#show"
any "static/*catchall", to: "jets/public_files#show"
any "*catchall", to: "jets/public#show"

# public2/stylesheets/test.css
end

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
@@ -1,4 +1,10 @@
describe Jets::Commands::Build do
before(:each) do
# hack to reset subclasses, Stack classes from other specs pollutes it.
# Dont really want to define a reset_subclasses! method because this is only used for specs.
Jets::Stack.instance_variable_set(:@subclasses, [])
end

context "templates only and fake full" do
let(:build) do
Jets::Commands::Build.new(templates: true, full: true)
@@ -9,20 +15,6 @@
file_exist = File.exist?("/tmp/jets/demo/templates/demo-test-app-posts_controller.yml")
expect(file_exist).to be true
end

# it "builds handlers javascript files" do
# end

# Would be nice to be able to automate testing the shim
# context "node shim" do
# it "posts create should return json" do
# # build.build
# # Dir.chdir(ENV["JETS_ROOT"]) do
# out = execute("cd #{ENV["JETS_ROOT"]} && node handlers/controllers/posts.js")
# puts out
# # end
# end
# end
end

context "methods" do
@@ -48,6 +40,7 @@
router = Jets::Router.drawn_router
files = Jets::Commands::Build.internal_app_files
files.reject! { |p| p.include?("preheat_job") }
files.reject! { |p| p.include?("public_controller") }
expect(files).to eq([])

router.draw do
@@ -3,8 +3,9 @@
it "creates a migration file" do
command = "exe/jets dynamodb:generate create_posts --partition-key id:string"
out = execute(command)
puts "HIII".colorize(:yellow)
# pp out # uncomment to debug
# expect(out).to include("Creating migration")
expect(out).to include("Generating migration")
migration_path = Dir.glob("#{Dynomite.app_root}dynamodb/migrate/*").first
migration_exist = File.exist?(migration_path)
expect(migration_exist).to be true
@@ -10,17 +10,15 @@
expect(tasks).to eq [:dig, :drive, :lift]

dig_task = HardJob.all_public_tasks[:dig]
expect(dig_task).to be_a(Jets::Job::Task)
expect(dig_task.schedule_expression).to eq "rate(10 hours)"
expect(dig_task).to be_a(Jets::Lambda::Task)

drive_task = HardJob.all_public_tasks[:lift]
expect(drive_task).to be_a(Jets::Job::Task)
expect(drive_task.schedule_expression).to eq "cron(0 */12 * * ? *)"
expect(drive_task).to be_a(Jets::Lambda::Task)
end

it "tasks contains flatten Array structure" do
tasks = HardJob.tasks
expect(tasks.first).to be_a(Jets::Job::Task)
expect(tasks.first).to be_a(Jets::Lambda::Task)

task_names = tasks.map(&:name)
expect(task_names).to eq(HardJob.all_public_tasks.keys)
@@ -53,19 +53,18 @@ def index
context "Admin::StoresController" do
let(:controller) { Admin::StoresController.new({}, nil, "new") }

it "tasks should not include tasks from parent class" do
it "tasks should include tasks from parent class" do
tasks = Admin::StoresController.all_public_tasks.keys
# pp tasks
expect(tasks).to eq []
expect(tasks).to eq [:index, :new, :show]
end
end

context "App extension iot" do
it "creates custom resource" do
task = TemperatureJob.tasks.first
# pp task # uncomment to see and debug
has_resource = task.associated_resources.first.key?("room_topic_rule")
expect(has_resource).to be true
logical_id = task.associated_resources.first.logical_id
expect(logical_id).to eq "room_topic_rule"
end
end

@@ -15,14 +15,16 @@
# Uncomment this stubbing to test live request
# Will need a rack server up and running
http = double(:http)
allow(http).to receive(:open_timeout=)
allow(http).to receive(:read_timeout=)
response = double(:response).as_null_object
allow(response).to receive(:code).and_return("200")
allow(response).to receive(:each_header).and_return({})
allow(response).to receive(:body).and_return("test body")
allow(http).to receive(:request).and_return(response)
allow(Net::HTTP).to receive(:new).and_return(http)

resp = request.process
resp = request.proxy
# pp resp # uncomment to see and debug
expect(resp).to eq({:status=>200, :headers=>{}, :body=>"test body"})
end
@@ -21,7 +21,8 @@
event = json_file("spec/fixtures/dumps/api_gateway/posts/index.json")
context = nil
env = Jets::Controller::Rack::Env.new(event, context).convert
mimic = Jets::Controller::Middleware::Local::MimicAwsCall.new(env)
route = Jets::Controller::Middleware::Local::RouteMatcher.new(env).find_route
mimic = Jets::Controller::Middleware::Local::MimicAwsCall.new(route, env)
env.merge!(mimic.vars)
env
end
@@ -32,7 +33,7 @@
config_middleware.use Rack::TempfileReaper

middleware = config_middleware.merge_into(default_stack)
stack = middleware.build(Jets::Controller::Rack::Main)
stack = middleware.build(Jets::Controller::Middleware::Main)
status, headers, body = stack.call(rack_env)
expect(status).to eq "200"
expect(headers).to be_a(Hash)
@@ -8,7 +8,8 @@
end

it "session store" do
expect(default_stack.session_store).to eq Rack::Session::Cookie
session_store = default_stack.send(:session_store)
expect(session_store).to eq Rack::Session::Cookie
end
end
end
@@ -2,10 +2,19 @@
context "stack" do
it "build" do
default_stack = Jets::Middleware::DefaultStack.new(Jets.config, Jets.application).build_stack
endpoint = Jets::Controller::Rack::Main
endpoint = Jets::Controller::Middleware::Main
middleware = default_stack.build(endpoint) # uncomment to see middleware tree
# pp middleware # uncomment to see and debug
expect(middleware).to be_a Jets::Controller::Middleware::Local # top of the tree
expect(middleware).to be_a Rack::Runtime # top of the tree
# $ jets middleware
# use Rack::Runtime
# use Rack::MethodOverride
# use Jets::Controller::Middleware::Local
# use Rack::Session::Cookie
# use Rack::Head
# use Rack::ConditionalGet
# use Rack::ETag
# run Jets::Controller::Middleware::Main
end
end
end
@@ -7,7 +7,8 @@ class MiddlewareTestClass
event = json_file("spec/fixtures/dumps/api_gateway/posts/index.json")
context = nil
env = Jets::Controller::Rack::Env.new(event, context).convert
mimic = Jets::Controller::Middleware::Local::MimicAwsCall.new(env)
route = Jets::Controller::Middleware::Local::RouteMatcher.new(env).find_route
mimic = Jets::Controller::Middleware::Local::MimicAwsCall.new(route, env)
env.merge!(mimic.vars)
env
end
Oops, something went wrong.

0 comments on commit cc88c16

Please sign in to comment.