ruby-sfn-local 0.1.13 → 0.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 75dd7b0209a27d5fedaac3a899ab43ce8c9cc814ae8736e9ebfab57e11a81397
4
- data.tar.gz: a4caabe1ecab7fbae2b9a71d3ddd760f95c709813d67c67972248cd15d7628b8
3
+ metadata.gz: 4a8d8a6fc30d2a2965dfda5c56c1aad5af809b7599f829828c829cf9930efbaf
4
+ data.tar.gz: ac740780539e3c0f93a7f3613f5b332f727d063bbbc63476b50c19c536489418
5
5
  SHA512:
6
- metadata.gz: 46d027dcc3ba4688427c36f35ffd40c725a6edef9727320aea01c7c6c100f8dc2933dbe01437104d71546b037ea7830458dccb3e14b1be7cb443c47628077298
7
- data.tar.gz: 77cc4a235b5e881fac19faff75c9a36c2d57ef08b95a7c941d214bb823166db9149f9e53241a51436ec94c0d8e85965564dbe9caa0b40c3f2caae0fbe2a8fe02
6
+ metadata.gz: f0f125829bc0d612a8dfd84f06434434ff684e61cdc51328af8c2ffe0df809cfbf00141d5d436b6a091ecb1413a3b1c58da097eae2b0fbd0fddab7c7e2be7b78
7
+ data.tar.gz: 1b1de6bb7d076d4930594eb5d153c1e243067d5c48f17376a5e500b3d9988679009caa24d34174f3dd3d9c6104b14fa66ddd93ce016b6dda9dcac835c6b3ff46
data/lib/sfn/execution.rb CHANGED
@@ -4,8 +4,8 @@ module Sfn
4
4
  class Execution
5
5
  attr_accessor :uuid, :state_machine, :test_case, :arn, :output, :profile
6
6
 
7
- def self.call(state_machine, test_case, mock_data, input)
8
- new(state_machine, test_case).exec(mock_data, input)
7
+ def self.call(state_machine, test_case, mock_data, input, dry_run = false)
8
+ new(state_machine, test_case).exec(mock_data, input, dry_run)
9
9
  end
10
10
 
11
11
  def initialize(state_machine, test_case)
@@ -14,14 +14,15 @@ module Sfn
14
14
  self.test_case = test_case.camelize
15
15
  end
16
16
 
17
- def exec(mock_data, input)
17
+ def exec(mock_data, input, dry_run = false)
18
18
  MockData.write_context(state_machine.name, test_case, mock_data)
19
19
  self.arn = AwsCli.run('stepfunctions', 'start-execution',
20
20
  { name: uuid,
21
21
  'state-machine': "#{state_machine.arn}##{test_case}",
22
- input: "'#{input.to_json}'" },
22
+ input: "'#{input.to_json}'"
23
+ },
23
24
  'executionArn')
24
- self.output, self.profile = ExecutionLog.parse(arn)
25
+ self.output, self.profile = ExecutionLog.parse(arn, dry_run)
25
26
  self
26
27
  end
27
28
  end
@@ -17,7 +17,7 @@ module Sfn
17
17
  EVENTS = %w[stateEnteredEventDetails stateExitedEventDetails executionSucceededEventDetails
18
18
  executionFailedEventDetails taskScheduledEventDetails].freeze
19
19
 
20
- def self.parse(execution_arn)
20
+ def self.parse(execution_arn, dry_run = false)
21
21
  profile = {}
22
22
  root_state_name = {}
23
23
  output = nil
@@ -28,7 +28,7 @@ module Sfn
28
28
  JSON.parse(events_json).each do |event|
29
29
  parsed_event = new(event)
30
30
  output ||= parsed_event.output
31
- error ||= parsed_event.error(events_json)
31
+ error ||= parsed_event.error(events_json, dry_run)
32
32
  state_name = parsed_event.state_name
33
33
 
34
34
  unless state_name.nil?
@@ -57,12 +57,14 @@ module Sfn
57
57
  try_parse(event.dig('executionSucceededEventDetails', 'output'))
58
58
  end
59
59
 
60
- def error(events_json = '{}')
60
+ def error(events_json = '{}', dry_run = false)
61
61
  return if event['executionFailedEventDetails'].nil?
62
62
 
63
63
  raise ExecutionError.new(event['executionFailedEventDetails']['cause'],
64
- event['executionFailedEventDetails']['error'],
65
- events_json)
64
+ event['executionFailedEventDetails']['error'],
65
+ events_json) unless dry_run
66
+
67
+ event['executionFailedEventDetails']
66
68
  end
67
69
 
68
70
  def 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)
@@ -40,9 +40,13 @@ module Sfn
40
40
  Collection.instance.delete_by_arn(arn)
41
41
  end
42
42
 
43
- def run(mock_data = {}, input = {}, test_name = nil)
43
+ def dry_run(mock_data = {}, input = {}, test_name = nil)
44
+ execution = run(mock_data, input, test_name, true)
45
+ end
46
+
47
+ def run(mock_data = {}, input = {}, test_name = nil, dry_run = false)
44
48
  test_name ||= OpenSSL::Digest::SHA512.digest(mock_data.merge({ input: input }).to_json)
45
- executions[test_name] ||= Execution.call(self, test_name, mock_data, input)
49
+ executions[test_name] ||= Execution.call(self, test_name, mock_data, input, dry_run)
46
50
  executions[test_name]
47
51
  end
48
52
 
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.13
4
+ version: 0.1.17
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-07-02 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