rspec-terraform 0.1.0.pre.44 → 0.1.0.pre.45

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: 84471e75598a3fc301a717d206fd91ba40583271430805b183cbaf58610a8331
4
- data.tar.gz: 6178c6b399ff218dffbb21c4f036c64233e3ac84e96ba86660254af7d6f2d4d0
3
+ metadata.gz: f5e1e41e777f174198e1de6459ef21f280d11227fd2a0b97e0d6604458b48e34
4
+ data.tar.gz: 071164c5440ab7b9a094c0125c7d562acb40d235485baac554dfd6e14bbc55fb
5
5
  SHA512:
6
- metadata.gz: f3b96974345ca144b4314eb2c90237bb238223e706c214fe94b97f4e5462edf969f6b4da8b3cd83a4a81daed33771f18a0e9f415c361ec6f9cb3ebfe97be7b74
7
- data.tar.gz: 19651b182453d3de16dfca2b5b4fe205df0d2af4bbfdc80dc1aa4d71298cd359a0ce70655720e100dc21f4f1f19b4784f51bdd56b3adfd63c05c3177a825f21d
6
+ metadata.gz: d8f45a75288ba61061d435320509688ac960e4be4b1842b62d4a4c87cc6e5a75af656f6b6fad60b39fbe24f12060cc8d9d1bec4038616efb2d7dea02649caba9
7
+ data.tar.gz: d2e42b5ca9bbfbcb59842e656e9d2816fb838c8bed600aaeaeb008f6601dd64755fa8ac33c27b79cc38c84efc2c8f99b612b25498c98f0292c0fb115433e9e4d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-terraform (0.1.0.pre.44)
4
+ rspec-terraform (0.1.0.pre.45)
5
5
  confidante (>= 0.27)
6
6
  rspec (>= 3.0)
7
7
  ruby-terraform (= 1.7.0.pre.17)
@@ -145,8 +145,8 @@ GEM
145
145
  parser (>= 3.1.1.0)
146
146
  rubocop-rake (0.6.0)
147
147
  rubocop (~> 1.0)
148
- rubocop-rspec (2.12.1)
149
- rubocop (~> 1.31)
148
+ rubocop-rspec (2.13.1)
149
+ rubocop (~> 1.33)
150
150
  ruby-progressbar (1.11.0)
151
151
  ruby-terraform (1.7.0.pre.17)
152
152
  immutable-struct (~> 2.4)
@@ -2,34 +2,13 @@
2
2
 
3
3
  require 'ruby_terraform'
4
4
 
5
+ require_relative './base'
5
6
  require_relative '../configuration/var_captor'
6
7
 
7
8
  module RSpec
8
9
  module Terraform
9
10
  module Helpers
10
- # rubocop:disable Metrics/ClassLength
11
- class Apply
12
- attr_reader(
13
- :configuration_provider,
14
- :binary,
15
- :logger,
16
- :stdin,
17
- :stdout,
18
- :stderr,
19
- :execution_mode
20
- )
21
-
22
- def initialize(opts = {})
23
- @configuration_provider =
24
- opts[:configuration_provider] || Configuration.identity_provider
25
- @binary = opts[:binary] || 'terraform'
26
- @logger = opts[:logger]
27
- @stdin = opts[:stdin]
28
- @stdout = opts[:stdout]
29
- @stderr = opts[:stderr]
30
- @execution_mode = opts[:execution_mode] || :in_place
31
- end
32
-
11
+ class Apply < Base
33
12
  def execute(overrides = {}, &block)
34
13
  parameters = with_configuration_provider_parameters(overrides)
35
14
  parameters = with_resolved_vars(parameters, &block)
@@ -53,23 +32,11 @@ module RSpec
53
32
  block.call if should_execute
54
33
  end
55
34
 
56
- def with_configuration_provider_parameters(parameters)
57
- configuration_provider.resolve(parameters)
58
- end
59
-
60
- def with_resolved_vars(parameters, &block)
61
- return parameters unless block_given?
62
-
63
- var_captor = Configuration::VarCaptor.new(parameters[:vars] || {})
64
- block.call(var_captor)
65
- parameters.merge(vars: var_captor.to_h)
66
- end
67
-
68
- def with_mandatory_parameters(parameters)
69
- parameters.merge(
35
+ def mandatory_parameters
36
+ {
70
37
  input: false,
71
38
  auto_approve: true
72
- )
39
+ }
73
40
  end
74
41
 
75
42
  def required_parameters(execution_mode)
@@ -79,28 +46,6 @@ module RSpec
79
46
  }[execution_mode] || []
80
47
  end
81
48
 
82
- def raise_missing_parameters(parameters)
83
- parameters = parameters.collect { |parameter| "`:#{parameter}`" }
84
- if parameters.count == 1
85
- raise StandardError,
86
- "Required parameter: #{parameters[0]} missing."
87
- else
88
- parameters = "#{parameters[..-2].join(', ')} and #{parameters[-1]}"
89
- raise StandardError,
90
- "Required parameters: #{parameters} missing."
91
- end
92
- end
93
-
94
- def validate(parameters)
95
- missing_parameters =
96
- required_parameters(execution_mode)
97
- .filter { |parameter| parameters[parameter].nil? }
98
-
99
- return if missing_parameters.empty?
100
-
101
- raise_missing_parameters(missing_parameters)
102
- end
103
-
104
49
  def clean(parameters)
105
50
  return unless execution_mode == :isolated
106
51
 
@@ -154,18 +99,7 @@ module RSpec
154
99
  apply_parameters
155
100
  end
156
101
  # rubocop:enable Metrics/MethodLength
157
-
158
- def command_options
159
- {
160
- binary: binary,
161
- logger: logger,
162
- stdin: stdin,
163
- stdout: stdout,
164
- stderr: stderr
165
- }
166
- end
167
102
  end
168
- # rubocop:enable Metrics/ClassLength
169
103
  end
170
104
  end
171
105
  end
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../configuration/var_captor'
4
+
5
+ module RSpec
6
+ module Terraform
7
+ module Helpers
8
+ class Base
9
+ attr_reader(
10
+ :configuration_provider,
11
+ :binary,
12
+ :logger,
13
+ :stdin,
14
+ :stdout,
15
+ :stderr,
16
+ :execution_mode
17
+ )
18
+
19
+ def initialize(opts = {})
20
+ @configuration_provider =
21
+ opts[:configuration_provider] || Configuration.identity_provider
22
+ @binary = opts[:binary] || 'terraform'
23
+ @logger = opts[:logger]
24
+ @stdin = opts[:stdin]
25
+ @stdout = opts[:stdout]
26
+ @stderr = opts[:stderr]
27
+ @execution_mode = opts[:execution_mode] || :in_place
28
+ end
29
+
30
+ private
31
+
32
+ def with_configuration_provider_parameters(parameters)
33
+ configuration_provider.resolve(parameters)
34
+ end
35
+
36
+ def with_resolved_vars(parameters, &block)
37
+ return parameters unless block_given?
38
+
39
+ var_captor = Configuration::VarCaptor.new(parameters[:vars] || {})
40
+ block.call(var_captor)
41
+ parameters.merge(vars: var_captor.to_h)
42
+ end
43
+
44
+ def with_mandatory_parameters(parameters)
45
+ parameters.merge(mandatory_parameters)
46
+ end
47
+
48
+ def raise_missing_parameters(parameters)
49
+ parameters = parameters.collect { |parameter| "`:#{parameter}`" }
50
+ if parameters.count == 1
51
+ raise StandardError,
52
+ "Required parameter: #{parameters[0]} missing."
53
+ else
54
+ parameters = "#{parameters[..-2].join(', ')} and #{parameters[-1]}"
55
+ raise StandardError,
56
+ "Required parameters: #{parameters} missing."
57
+ end
58
+ end
59
+
60
+ def validate(parameters)
61
+ missing_parameters =
62
+ required_parameters(execution_mode)
63
+ .filter { |parameter| parameters[parameter].nil? }
64
+
65
+ return if missing_parameters.empty?
66
+
67
+ raise_missing_parameters(missing_parameters)
68
+ end
69
+
70
+ def mandatory_parameters
71
+ {}
72
+ end
73
+
74
+ def required_parameters(_)
75
+ []
76
+ end
77
+
78
+ def command_options
79
+ {
80
+ binary: binary,
81
+ logger: logger,
82
+ stdin: stdin,
83
+ stdout: stdout,
84
+ stderr: stderr
85
+ }
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -2,34 +2,12 @@
2
2
 
3
3
  require 'ruby_terraform'
4
4
 
5
- require_relative '../configuration/var_captor'
5
+ require_relative './base'
6
6
 
7
7
  module RSpec
8
8
  module Terraform
9
9
  module Helpers
10
- # rubocop:disable Metrics/ClassLength
11
- class Destroy
12
- attr_reader(
13
- :configuration_provider,
14
- :binary,
15
- :logger,
16
- :stdin,
17
- :stdout,
18
- :stderr,
19
- :execution_mode
20
- )
21
-
22
- def initialize(opts = {})
23
- @configuration_provider =
24
- opts[:configuration_provider] || Configuration.identity_provider
25
- @binary = opts[:binary] || 'terraform'
26
- @logger = opts[:logger]
27
- @stdin = opts[:stdin]
28
- @stdout = opts[:stdout]
29
- @stderr = opts[:stderr]
30
- @execution_mode = opts[:execution_mode] || :in_place
31
- end
32
-
10
+ class Destroy < Base
33
11
  def execute(overrides = {}, &block)
34
12
  parameters = with_configuration_provider_parameters(overrides)
35
13
  parameters = with_resolved_vars(parameters, &block)
@@ -52,18 +30,6 @@ module RSpec
52
30
  block.call if should_execute
53
31
  end
54
32
 
55
- def with_configuration_provider_parameters(parameters)
56
- configuration_provider.resolve(parameters)
57
- end
58
-
59
- def with_resolved_vars(parameters, &block)
60
- return parameters unless block_given?
61
-
62
- var_captor = Configuration::VarCaptor.new(parameters[:vars] || {})
63
- block.call(var_captor)
64
- parameters.merge(vars: var_captor.to_h)
65
- end
66
-
67
33
  def required_parameters(execution_mode)
68
34
  {
69
35
  in_place: [:configuration_directory],
@@ -71,28 +37,6 @@ module RSpec
71
37
  }[execution_mode] || []
72
38
  end
73
39
 
74
- def raise_missing_parameters(parameters)
75
- parameters = parameters.collect { |parameter| "`:#{parameter}`" }
76
- if parameters.count == 1
77
- raise StandardError,
78
- "Required parameter: #{parameters[0]} missing."
79
- else
80
- parameters = "#{parameters[..-2].join(', ')} and #{parameters[-1]}"
81
- raise StandardError,
82
- "Required parameters: #{parameters} missing."
83
- end
84
- end
85
-
86
- def validate(parameters)
87
- missing_parameters =
88
- required_parameters(execution_mode)
89
- .filter { |parameter| parameters[parameter].nil? }
90
-
91
- return if missing_parameters.empty?
92
-
93
- raise_missing_parameters(missing_parameters)
94
- end
95
-
96
40
  def clean(parameters)
97
41
  return unless execution_mode == :isolated
98
42
 
@@ -146,18 +90,7 @@ module RSpec
146
90
  destroy_parameters
147
91
  end
148
92
  # rubocop:enable Metrics/MethodLength
149
-
150
- def command_options
151
- {
152
- binary: binary,
153
- logger: logger,
154
- stdin: stdin,
155
- stdout: stdout,
156
- stderr: stderr
157
- }
158
- end
159
93
  end
160
- # rubocop:enable Metrics/ClassLength
161
94
  end
162
95
  end
163
96
  end
@@ -2,38 +2,17 @@
2
2
 
3
3
  require 'ruby_terraform'
4
4
 
5
+ require_relative './base'
6
+
5
7
  module RSpec
6
8
  module Terraform
7
9
  module Helpers
8
- # rubocop:disable Metrics/ClassLength
9
- class Output
10
- attr_reader(
11
- :configuration_provider,
12
- :binary,
13
- :logger,
14
- :stdin,
15
- :stdout,
16
- :stderr,
17
- :execution_mode
18
- )
19
-
20
- def initialize(opts = {})
21
- @configuration_provider =
22
- opts[:configuration_provider] || Configuration.identity_provider
23
- @binary = opts[:binary] || 'terraform'
24
- @logger = opts[:logger]
25
- @stdin = opts[:stdin]
26
- @stdout = opts[:stdout]
27
- @stderr = opts[:stderr]
28
- @execution_mode = opts[:execution_mode] || :in_place
29
- end
30
-
10
+ class Output < Base
31
11
  def execute(overrides = {})
32
12
  parameters = with_configuration_provider_parameters(overrides)
33
13
  parameters = with_mandatory_parameters(parameters)
34
14
 
35
- ensure_required_parameters(parameters)
36
-
15
+ validate(parameters)
37
16
  clean(parameters)
38
17
  init(parameters)
39
18
  output_value = output(parameters)
@@ -43,14 +22,14 @@ module RSpec
43
22
 
44
23
  private
45
24
 
46
- def with_configuration_provider_parameters(parameters)
47
- configuration_provider.resolve(parameters)
25
+ def with_mandatory_parameters(parameters)
26
+ parameters.merge(mandatory_parameters)
48
27
  end
49
28
 
50
- def with_mandatory_parameters(parameters)
51
- parameters.merge(
29
+ def mandatory_parameters
30
+ {
52
31
  json: true
53
- )
32
+ }
54
33
  end
55
34
 
56
35
  def required_parameters(execution_mode)
@@ -60,28 +39,6 @@ module RSpec
60
39
  }[execution_mode] || []
61
40
  end
62
41
 
63
- def ensure_required_parameters(parameters)
64
- missing_parameters =
65
- required_parameters(execution_mode)
66
- .filter { |parameter| parameters[parameter].nil? }
67
-
68
- return if missing_parameters.empty?
69
-
70
- raise_missing_parameters(missing_parameters)
71
- end
72
-
73
- def raise_missing_parameters(parameters)
74
- parameters = parameters.collect { |parameter| "`:#{parameter}`" }
75
- if parameters.count == 1
76
- raise StandardError,
77
- "Required parameter: #{parameters[0]} missing."
78
- else
79
- parameters = "#{parameters[..-2].join(', ')} and #{parameters[-1]}"
80
- raise StandardError,
81
- "Required parameters: #{parameters} missing."
82
- end
83
- end
84
-
85
42
  def clean(parameters)
86
43
  return unless execution_mode == :isolated
87
44
 
@@ -134,18 +91,7 @@ module RSpec
134
91
 
135
92
  output_parameters
136
93
  end
137
-
138
- def command_options
139
- {
140
- binary: binary,
141
- logger: logger,
142
- stdin: stdin,
143
- stdout: stdout,
144
- stderr: stderr
145
- }
146
- end
147
94
  end
148
95
  end
149
- # rubocop:enable Metrics/ClassLength
150
96
  end
151
97
  end
@@ -4,40 +4,17 @@ require 'ruby_terraform'
4
4
  require 'securerandom'
5
5
  require 'stringio'
6
6
 
7
- require_relative '../configuration/var_captor'
7
+ require_relative './base'
8
8
 
9
9
  module RSpec
10
10
  module Terraform
11
11
  module Helpers
12
- # rubocop:disable Metrics/ClassLength
13
- class Plan
14
- attr_reader(
15
- :configuration_provider,
16
- :binary,
17
- :logger,
18
- :stdin,
19
- :stdout,
20
- :stderr,
21
- :execution_mode
22
- )
23
-
24
- def initialize(opts = {})
25
- @configuration_provider =
26
- opts[:configuration_provider] || Configuration.identity_provider
27
- @binary = opts[:binary] || 'terraform'
28
- @logger = opts[:logger]
29
- @stdin = opts[:stdin]
30
- @stdout = opts[:stdout]
31
- @stderr = opts[:stderr]
32
- @execution_mode = opts[:execution_mode] || :in_place
33
- end
34
-
12
+ class Plan < Base
35
13
  def execute(overrides = {}, &block)
36
14
  parameters = with_configuration_provider_parameters(overrides)
37
15
  parameters = with_resolved_vars(parameters, &block)
38
16
 
39
- ensure_required_parameters(parameters)
40
-
17
+ validate(parameters)
41
18
  clean(parameters)
42
19
  init(parameters)
43
20
  plan_file = plan(parameters)
@@ -48,18 +25,6 @@ module RSpec
48
25
 
49
26
  private
50
27
 
51
- def with_configuration_provider_parameters(parameters)
52
- configuration_provider.resolve(parameters)
53
- end
54
-
55
- def with_resolved_vars(parameters, &block)
56
- return parameters unless block_given?
57
-
58
- var_captor = Configuration::VarCaptor.new(parameters[:vars] || {})
59
- block.call(var_captor)
60
- parameters.merge(vars: var_captor.to_h)
61
- end
62
-
63
28
  def required_parameters(execution_mode)
64
29
  {
65
30
  in_place: [:configuration_directory],
@@ -67,28 +32,6 @@ module RSpec
67
32
  }[execution_mode] || []
68
33
  end
69
34
 
70
- def ensure_required_parameters(parameters)
71
- missing_parameters =
72
- required_parameters(execution_mode)
73
- .filter { |parameter| parameters[parameter].nil? }
74
-
75
- return if missing_parameters.empty?
76
-
77
- raise_missing_parameters(missing_parameters)
78
- end
79
-
80
- def raise_missing_parameters(parameters)
81
- parameters = parameters.collect { |parameter| "`:#{parameter}`" }
82
- if parameters.count == 1
83
- raise StandardError,
84
- "Required parameter: #{parameters[0]} missing."
85
- else
86
- parameters = "#{parameters[..-2].join(', ')} and #{parameters[-1]}"
87
- raise StandardError,
88
- "Required parameters: #{parameters} missing."
89
- end
90
- end
91
-
92
35
  def clean(parameters)
93
36
  return unless execution_mode == :isolated
94
37
 
@@ -177,18 +120,7 @@ module RSpec
177
120
  json: true
178
121
  )
179
122
  end
180
-
181
- def command_options
182
- {
183
- binary: binary,
184
- logger: logger,
185
- stdin: stdin,
186
- stdout: stdout,
187
- stderr: stderr
188
- }
189
- end
190
123
  end
191
- # rubocop:enable Metrics/ClassLength
192
124
  end
193
125
  end
194
126
  end
@@ -1,38 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative './base'
3
4
  require_relative '../configuration/var_captor'
4
5
 
5
6
  module RSpec
6
7
  module Terraform
7
8
  module Helpers
8
- class Var
9
- attr_reader(:configuration_provider)
10
-
11
- def initialize(opts = {})
12
- @configuration_provider =
13
- opts[:configuration_provider] || Configuration.identity_provider
14
- end
15
-
9
+ class Var < Base
16
10
  def execute(overrides = {}, &block)
17
11
  parameters = with_configuration_provider_parameters(overrides)
18
12
  parameters = with_resolved_vars(parameters, &block)
19
13
 
20
14
  parameters[:vars][parameters[:name].to_sym]
21
15
  end
22
-
23
- private
24
-
25
- def with_configuration_provider_parameters(parameters)
26
- configuration_provider.resolve(parameters)
27
- end
28
-
29
- def with_resolved_vars(parameters, &block)
30
- return parameters unless block_given?
31
-
32
- var_captor = Configuration::VarCaptor.new(parameters[:vars] || {})
33
- block.call(var_captor)
34
- parameters.merge(vars: var_captor.to_h)
35
- end
36
16
  end
37
17
  end
38
18
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module Terraform
5
- VERSION = '0.1.0.pre.44'
5
+ VERSION = '0.1.0.pre.45'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-terraform
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre.44
4
+ version: 0.1.0.pre.45
5
5
  platform: ruby
6
6
  authors:
7
7
  - InfraBlocks Maintainers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-11 00:00:00.000000000 Z
11
+ date: 2022-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: confidante
@@ -305,6 +305,7 @@ files:
305
305
  - lib/rspec/terraform/configuration/var_captor.rb
306
306
  - lib/rspec/terraform/helpers.rb
307
307
  - lib/rspec/terraform/helpers/apply.rb
308
+ - lib/rspec/terraform/helpers/base.rb
308
309
  - lib/rspec/terraform/helpers/destroy.rb
309
310
  - lib/rspec/terraform/helpers/output.rb
310
311
  - lib/rspec/terraform/helpers/plan.rb