rspec-terraform 0.1.0.pre.39 → 0.1.0.pre.42

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: d9e77a423f915bda9a4d02a980a21a1755a6dde139dc3d1890414eacfa72c1c8
4
- data.tar.gz: 6e2ff10778fd5641f717fb2cf9e23d59e39312179a76cffa40d49ece0ae7a001
3
+ metadata.gz: cbb48dde98e84c35ba49c8416a4363ee64388ad4912e0758392d5f8a9228ef21
4
+ data.tar.gz: 4eb898798fb7090a3211bada0de62d0087becf44b51ff8cb8736eb9171d55c6c
5
5
  SHA512:
6
- metadata.gz: a74ba985ec614bcdf6bcf1c9d031d663341f5f41a40feb513d03313d41cbbd97104c784c806ca5a64b38dffeaf5eea822722a0db2e3f1f78bd402ab18a19093a
7
- data.tar.gz: e7c2d9563eb65a3931a4d51d775d1c07e9449a748b15cd1a06e1404a3c9d74d4f65634674d2a88ce736982a75642a3bfb2d6bcadeaef39db9f2182dacc3b3a51
6
+ metadata.gz: 57f20880cfd73436cede9c132204ec6dc5c6f329850eba87c56be738554f2c1c6b5f925307d9284b2ab3b2aec19349b244519b1f0cb18d01d3914f097fc4d103
7
+ data.tar.gz: d4dc0cb70c7977d85a3bdbf98aa47dcd078e9babeb75b77b91f89677d1f4bdc3c3ecae9a11408db387fc580e607ce60d270a5285ec6ba6dba4ec427747489b8a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-terraform (0.1.0.pre.39)
4
+ rspec-terraform (0.1.0.pre.42)
5
5
  confidante (>= 0.27)
6
6
  rspec (>= 3.0)
7
7
  ruby-terraform (= 1.7.0.pre.16)
@@ -205,4 +205,4 @@ DEPENDENCIES
205
205
  terminal-notifier-guard
206
206
 
207
207
  BUNDLED WITH
208
- 2.3.21
208
+ 2.3.22
@@ -7,15 +7,26 @@ require_relative '../configuration/var_captor'
7
7
  module RSpec
8
8
  module Terraform
9
9
  module Helpers
10
+ # rubocop:disable Metrics/ClassLength
10
11
  class Apply
11
12
  attr_reader(
12
- :configuration_provider, :binary, :execution_mode
13
+ :configuration_provider,
14
+ :binary,
15
+ :logger,
16
+ :stdin,
17
+ :stdout,
18
+ :stderr,
19
+ :execution_mode
13
20
  )
14
21
 
15
22
  def initialize(opts = {})
16
23
  @configuration_provider =
17
24
  opts[:configuration_provider] || Configuration.identity_provider
18
25
  @binary = opts[:binary] || 'terraform'
26
+ @logger = opts[:logger]
27
+ @stdin = opts[:stdin]
28
+ @stdout = opts[:stdout]
29
+ @stderr = opts[:stderr]
19
30
  @execution_mode = opts[:execution_mode] || :in_place
20
31
  end
21
32
 
@@ -97,11 +108,11 @@ module RSpec
97
108
  end
98
109
 
99
110
  def init_command
100
- RubyTerraform::Commands::Init.new(binary: binary)
111
+ RubyTerraform::Commands::Init.new(command_options)
101
112
  end
102
113
 
103
114
  def apply_command
104
- RubyTerraform::Commands::Apply.new(binary: binary)
115
+ RubyTerraform::Commands::Apply.new(command_options)
105
116
  end
106
117
 
107
118
  def init_parameters(parameters)
@@ -134,7 +145,18 @@ module RSpec
134
145
  apply_parameters
135
146
  end
136
147
  # rubocop:enable Metrics/MethodLength
148
+
149
+ def command_options
150
+ {
151
+ binary: binary,
152
+ logger: logger,
153
+ stdin: stdin,
154
+ stdout: stdout,
155
+ stderr: stderr
156
+ }
157
+ end
137
158
  end
159
+ # rubocop:enable Metrics/ClassLength
138
160
  end
139
161
  end
140
162
  end
@@ -7,15 +7,26 @@ require_relative '../configuration/var_captor'
7
7
  module RSpec
8
8
  module Terraform
9
9
  module Helpers
10
+ # rubocop:disable Metrics/ClassLength
10
11
  class Destroy
11
12
  attr_reader(
12
- :configuration_provider, :binary, :execution_mode
13
+ :configuration_provider,
14
+ :binary,
15
+ :logger,
16
+ :stdin,
17
+ :stdout,
18
+ :stderr,
19
+ :execution_mode
13
20
  )
14
21
 
15
22
  def initialize(opts = {})
16
23
  @configuration_provider =
17
24
  opts[:configuration_provider] || Configuration.identity_provider
18
25
  @binary = opts[:binary] || 'terraform'
26
+ @logger = opts[:logger]
27
+ @stdin = opts[:stdin]
28
+ @stdout = opts[:stdout]
29
+ @stderr = opts[:stderr]
19
30
  @execution_mode = opts[:execution_mode] || :in_place
20
31
  end
21
32
 
@@ -89,19 +100,18 @@ module RSpec
89
100
  end
90
101
 
91
102
  def init_command
92
- RubyTerraform::Commands::Init.new(binary: binary)
103
+ RubyTerraform::Commands::Init.new(command_options)
93
104
  end
94
105
 
95
106
  def destroy_command
96
- RubyTerraform::Commands::Destroy.new(binary: binary)
107
+ RubyTerraform::Commands::Destroy.new(command_options)
97
108
  end
98
109
 
99
110
  def init_parameters(parameters)
100
- init_parameters =
101
- parameters.merge(
102
- chdir: parameters[:configuration_directory],
103
- input: false
104
- )
111
+ init_parameters = parameters.merge(
112
+ chdir: parameters[:configuration_directory],
113
+ input: false
114
+ )
105
115
  if execution_mode == :isolated
106
116
  init_parameters =
107
117
  init_parameters.merge(from_module: parameters[:source_directory])
@@ -127,7 +137,18 @@ module RSpec
127
137
  destroy_parameters
128
138
  end
129
139
  # rubocop:enable Metrics/MethodLength
140
+
141
+ def command_options
142
+ {
143
+ binary: binary,
144
+ logger: logger,
145
+ stdin: stdin,
146
+ stdout: stdout,
147
+ stderr: stderr
148
+ }
149
+ end
130
150
  end
151
+ # rubocop:enable Metrics/ClassLength
131
152
  end
132
153
  end
133
154
  end
@@ -5,15 +5,26 @@ require 'ruby_terraform'
5
5
  module RSpec
6
6
  module Terraform
7
7
  module Helpers
8
+ # rubocop:disable Metrics/ClassLength
8
9
  class Output
9
10
  attr_reader(
10
- :configuration_provider, :binary, :execution_mode
11
+ :configuration_provider,
12
+ :binary,
13
+ :logger,
14
+ :stdin,
15
+ :stdout,
16
+ :stderr,
17
+ :execution_mode
11
18
  )
12
19
 
13
20
  def initialize(opts = {})
14
21
  @configuration_provider =
15
22
  opts[:configuration_provider] || Configuration.identity_provider
16
23
  @binary = opts[:binary] || 'terraform'
24
+ @logger = opts[:logger]
25
+ @stdin = opts[:stdin]
26
+ @stdout = opts[:stdout]
27
+ @stderr = opts[:stderr]
17
28
  @execution_mode = opts[:execution_mode] || :in_place
18
29
  end
19
30
 
@@ -90,11 +101,11 @@ module RSpec
90
101
  end
91
102
 
92
103
  def init_command
93
- RubyTerraform::Commands::Init.new(binary: binary)
104
+ RubyTerraform::Commands::Init.new(command_options)
94
105
  end
95
106
 
96
107
  def output_command(opts = {})
97
- RubyTerraform::Commands::Output.new(opts.merge(binary: binary))
108
+ RubyTerraform::Commands::Output.new(command_options.merge(opts))
98
109
  end
99
110
 
100
111
  def init_parameters(parameters)
@@ -123,7 +134,18 @@ module RSpec
123
134
 
124
135
  output_parameters
125
136
  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
126
147
  end
127
148
  end
149
+ # rubocop:enable Metrics/ClassLength
128
150
  end
129
151
  end
@@ -12,13 +12,23 @@ module RSpec
12
12
  # rubocop:disable Metrics/ClassLength
13
13
  class Plan
14
14
  attr_reader(
15
- :configuration_provider, :binary, :execution_mode
15
+ :configuration_provider,
16
+ :binary,
17
+ :logger,
18
+ :stdin,
19
+ :stdout,
20
+ :stderr,
21
+ :execution_mode
16
22
  )
17
23
 
18
24
  def initialize(opts = {})
19
25
  @configuration_provider =
20
26
  opts[:configuration_provider] || Configuration.identity_provider
21
27
  @binary = opts[:binary] || 'terraform'
28
+ @logger = opts[:logger]
29
+ @stdin = opts[:stdin]
30
+ @stdout = opts[:stdout]
31
+ @stderr = opts[:stderr]
22
32
  @execution_mode = opts[:execution_mode] || :in_place
23
33
  end
24
34
 
@@ -116,15 +126,15 @@ module RSpec
116
126
  end
117
127
 
118
128
  def init_command
119
- RubyTerraform::Commands::Init.new(binary: binary)
129
+ RubyTerraform::Commands::Init.new(command_options)
120
130
  end
121
131
 
122
132
  def plan_command
123
- RubyTerraform::Commands::Plan.new(binary: binary)
133
+ RubyTerraform::Commands::Plan.new(command_options)
124
134
  end
125
135
 
126
136
  def show_command(opts = {})
127
- RubyTerraform::Commands::Show.new(opts.merge(binary: binary))
137
+ RubyTerraform::Commands::Show.new(command_options.merge(opts))
128
138
  end
129
139
 
130
140
  def init_parameters(parameters)
@@ -167,6 +177,16 @@ module RSpec
167
177
  json: true
168
178
  )
169
179
  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
170
190
  end
171
191
  # rubocop:enable Metrics/ClassLength
172
192
  end
@@ -46,6 +46,10 @@ module RSpec
46
46
 
47
47
  {
48
48
  binary: config.terraform_binary,
49
+ logger: config.terraform_logger,
50
+ stdin: config.terraform_stdin,
51
+ stdout: config.terraform_stdout,
52
+ stderr: config.terraform_stderr,
49
53
  execution_mode: config.terraform_execution_mode,
50
54
  configuration_provider: config.terraform_configuration_provider
51
55
  }
@@ -5,11 +5,15 @@ module RSpec
5
5
  module Logging
6
6
  class << self
7
7
  def resolve_streams(opts = {})
8
- streams = opts[:streams] || []
8
+ opts = resolve_opts(opts)
9
+ streams = opts[:streams]
10
+ level = opts[:level]
9
11
  devices = devices(opts)
10
12
 
13
+ resolve_opts(opts)
14
+
11
15
  {
12
- logger: resolve_logger(opts[:logger], streams, devices),
16
+ logger: resolve_logger(opts[:logger], streams, devices, level),
13
17
  stdout: resolve_stdout(opts[:stdout], streams, devices),
14
18
  stderr: resolve_stderr(opts[:stderr], streams, devices)
15
19
  }
@@ -17,14 +21,28 @@ module RSpec
17
21
 
18
22
  private
19
23
 
20
- def resolve_logger(logger, streams, devices)
24
+ def resolve_opts(opts)
25
+ streams = opts[:streams] || []
26
+ level = opts[:level] || Logger::INFO
27
+
28
+ if streams.include?(:file) && !opts[:file_path]
29
+ raise(
30
+ ArgumentError,
31
+ 'File logging requested but no file path provided'
32
+ )
33
+ end
34
+
35
+ opts.merge(streams: streams, level: level)
36
+ end
37
+
38
+ def resolve_logger(logger, streams, devices, level)
21
39
  return logger if logger
22
40
 
23
41
  log_devices = []
24
42
  log_devices << devices[:file] if streams.include?(:file)
25
43
  log_devices << devices[:stdout] if streams.include?(:standard)
26
44
 
27
- multi_io(log_devices)
45
+ Logger.new(multi_io(log_devices), level: level)
28
46
  end
29
47
 
30
48
  def resolve_stdout(stdout, streams, devices)
@@ -48,13 +66,34 @@ module RSpec
48
66
  end
49
67
 
50
68
  def devices(opts)
69
+ streams = opts[:streams]
70
+ file_path = opts[:file_path]
71
+ stdout = opts[:stdout]
72
+
51
73
  {
52
- file: log_device(opts[:file_path] || File::NULL),
53
- stdout: log_device($stdout),
54
- stderr: log_device($stderr)
74
+ file: log_device(resolve_file_path(file_path, streams)),
75
+ stdout: log_device(resolved_stdout(stdout)),
76
+ stderr: log_device(resolved_stderr)
55
77
  }
56
78
  end
57
79
 
80
+ def resolve_file_path(file_path, streams)
81
+ resolved_file_path = File::NULL
82
+ if streams.include?(:file) && file_path
83
+ FileUtils.mkdir_p(File.dirname(file_path))
84
+ resolved_file_path = file_path
85
+ end
86
+ resolved_file_path
87
+ end
88
+
89
+ def resolved_stdout(stdout)
90
+ stdout || $stdout
91
+ end
92
+
93
+ def resolved_stderr
94
+ $stderr
95
+ end
96
+
58
97
  def log_device(io)
59
98
  Logger::LogDevice.new(io)
60
99
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module Terraform
5
- VERSION = '0.1.0.pre.39'
5
+ VERSION = '0.1.0.pre.42'
6
6
  end
7
7
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'rspec/core'
4
4
  require 'ruby_terraform'
5
+ require 'logger'
5
6
 
6
7
  require_relative 'terraform/version'
7
8
  require_relative 'terraform/configuration'
@@ -12,7 +13,6 @@ require_relative 'terraform/logging'
12
13
  # TODO
13
14
  # ====
14
15
  #
15
- # * Logging
16
16
  # * Test session
17
17
  # * Before support in matchers
18
18
  # * Reference support in matchers
@@ -27,6 +27,7 @@ RSpec.configure do |config|
27
27
  config.add_setting(:terraform_binary, default: 'terraform')
28
28
 
29
29
  config.add_setting(:terraform_log_file_path, default: nil)
30
+ config.add_setting(:terraform_log_level, default: Logger::INFO)
30
31
  config.add_setting(:terraform_log_streams, default: [:standard])
31
32
 
32
33
  config.add_setting(:terraform_logger, default: nil)
@@ -44,6 +45,7 @@ RSpec.configure do |config|
44
45
  config.before(:suite) do
45
46
  resolved_streams = RSpec::Terraform::Logging.resolve_streams(
46
47
  file_path: RSpec.configuration.terraform_log_file_path,
48
+ level: RSpec.configuration.terraform_log_level,
47
49
  streams: RSpec.configuration.terraform_log_streams,
48
50
  logger: RSpec.configuration.terraform_logger,
49
51
  stdout: RSpec.configuration.terraform_stdout,
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.39
4
+ version: 0.1.0.pre.42
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-03 00:00:00.000000000 Z
11
+ date: 2022-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: confidante