ruby-sfn-local 0.1.12 → 0.1.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 05122d4c47a198bda25cdb97029a921f3e84a081f2bab2283124c8ee4eefb102
4
- data.tar.gz: 212f8edb5259942315dd586ed34c453618adc245164db27b307123b66d9f8ba5
3
+ metadata.gz: ebdc76d783d70c6ffd4a53ad77d2ccad609f51454b6d8888cc03b71c9d2a3f8a
4
+ data.tar.gz: 8d4bd280dab1cc12fb4bd2fb25995c6afb4096ed7862d65df6a7d7c10c57483c
5
5
  SHA512:
6
- metadata.gz: 31b1037fbad8a590aa1df037ab4f57709666e462c8ef9cc05242de74d891461bde6eee0381eaac26b449ef3b7c5864d6df3b6fa7e55ba3403f0e2e9e6cfba77b
7
- data.tar.gz: 128ab49678e6a0d6622811f7610d135ea89d054a2700f915efe40a8e6c37f2259afc84ea08f64c6ca30f72783f33f7b7b83d9fe27cf7168419d45f12037bf653
6
+ metadata.gz: fff1c781578513f06501c8e01c25d72ea30ede3515170e17c4d86fa4f6d0fe6da27a6e0b26d87882c8152c4a343d3a65052b0ab30d183168799bc02d42cb2e41
7
+ data.tar.gz: 2df1e930018156d74acdfadc64d9c9f4bfa63a3c27190067562e556856cc982b1e8df4c8a7f1a554679912115527411043d56c5a733019ead05cd16c89313806
@@ -19,6 +19,7 @@ module Sfn
19
19
 
20
20
  def self.parse(execution_arn)
21
21
  profile = {}
22
+ root_state_name = {}
22
23
  output = nil
23
24
  error = nil
24
25
  state_name = nil
@@ -26,19 +27,19 @@ module Sfn
26
27
  { 'execution-arn': execution_arn.to_s, query: "'events[?#{EVENTS.join(' || ')}]'" })
27
28
  JSON.parse(events_json).each do |event|
28
29
  parsed_event = new(event)
29
-
30
30
  output ||= parsed_event.output
31
31
  error ||= parsed_event.error(events_json)
32
- last_state_name = state_name
33
32
  state_name = parsed_event.state_name
34
33
 
35
34
  unless state_name.nil?
36
35
  profile[state_name] ||= { 'input' => [], 'output' => [], 'parameters' => [] }
37
36
  profile[state_name]['input'] << parsed_event.profile['input'] unless parsed_event.profile['input'].nil?
38
37
  profile[state_name]['output'] << parsed_event.profile['output'] unless parsed_event.profile['output'].nil?
38
+ root_state_name[parsed_event.event['id']] = state_name
39
39
  end
40
- if !last_state_name.nil? && !parsed_event.profile['parameters'].nil?
41
- profile[last_state_name]['parameters'] << parsed_event.profile['parameters']
40
+
41
+ if !root_state_name[parsed_event.event['previousEventId']].nil? && !parsed_event.profile['parameters'].nil?
42
+ profile[root_state_name[parsed_event.event['previousEventId']]]['parameters'] << parsed_event.profile['parameters']
42
43
  end
43
44
  end
44
45
  [output, profile]
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sfn
4
+ module MockMacros
5
+ module OptimisedStepFunction
6
+ def self.response(data)
7
+ data = [data] if data.is_a?(Hash)
8
+ data.map! do |val|
9
+ if val.key?(:error)
10
+ { Throw: { Error: val[:error], Cause: val[:cause] } }
11
+ else
12
+ val[:output] ||= val[:payload]
13
+ val[:output] ||= val[:response]
14
+ { Return: { Output: val[:output], Status: 'SUCCEDED' } }
15
+ end
16
+ end
17
+ out = {}
18
+ data.each_with_index do |val, idx|
19
+ out[idx.to_s] = val
20
+ end
21
+ out
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'sfn/mock_macros/lambda'
4
+ require 'sfn/mock_macros/optimised_step_function'
4
5
  require 'sfn/mock_macros/step_function'
5
6
  require 'sfn/mock_macros/api_gateway'
6
7
  require 'sfn/mock_macros/sns'
@@ -9,6 +10,7 @@ require 'sfn/mock_macros/sqs'
9
10
  module Sfn
10
11
  module MockMacros
11
12
  include Lambda
13
+ include OptimisedStepFunction
12
14
  include StepFunction
13
15
  include ApiGateway
14
16
  include Sns
@@ -30,10 +32,14 @@ module Sfn
30
32
  Sqs.response(data)
31
33
  end
32
34
 
33
- def self.step_function_response(data)
35
+ def self.step_function_response(data, optimised = false)
34
36
  StepFunction.response(data)
35
37
  end
36
38
 
39
+ def self.optimised_step_function_response(data)
40
+ OptimisedStepFunction.response(data)
41
+ end
42
+
37
43
  def self.gateway_payload(data)
38
44
  warn '[DEPRECATION] `gateway_payload` is deprecated. Please use `gateway_response` instead.'
39
45
  ApiGateway.response(data)
@@ -29,7 +29,7 @@ module Sfn
29
29
 
30
30
  def initialize(name, arn = nil)
31
31
  self.path = "#{Sfn.configuration.definition_path}/#{name}.json"
32
- self.name = name.split("/").last
32
+ self.name = name.split('/').last
33
33
  self.arn = arn || self.class.find_by_name(self.name)&.arn || create_state_machine
34
34
  self.executions = {}
35
35
  end
@@ -41,7 +41,7 @@ module Sfn
41
41
  end
42
42
 
43
43
  def run(mock_data = {}, input = {}, test_name = nil)
44
- test_name ||= OpenSSL::Digest::SHA512.digest(mock_data.merge({input: input}).to_json)
44
+ test_name ||= OpenSSL::Digest::SHA512.digest(mock_data.merge({ input: input }).to_json)
45
45
  executions[test_name] ||= Execution.call(self, test_name, mock_data, input)
46
46
  executions[test_name]
47
47
  end
@@ -63,8 +63,8 @@ module Sfn
63
63
 
64
64
  def load_definition
65
65
  local_definition_path = Tempfile.new(['name', '.json']).path
66
-
67
- definition = File.read(self.path)
66
+
67
+ definition = File.read(path)
68
68
  local_definition = definition.gsub(/"MaxConcurrency": [0-9]+/, '"MaxConcurrency": 1')
69
69
 
70
70
  File.open(local_definition_path, 'w') { |file| file.puts local_definition }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-sfn-local
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gianni Mazza
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-23 00:00:00.000000000 Z
11
+ date: 2022-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-release
@@ -68,6 +68,7 @@ files:
68
68
  - lib/sfn/mock_macros.rb
69
69
  - lib/sfn/mock_macros/api_gateway.rb
70
70
  - lib/sfn/mock_macros/lambda.rb
71
+ - lib/sfn/mock_macros/optimised_step_function.rb
71
72
  - lib/sfn/mock_macros/sns.rb
72
73
  - lib/sfn/mock_macros/sqs.rb
73
74
  - lib/sfn/mock_macros/step_function.rb