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

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: dde90bef4a301ed3039f8dd05483f9a1719e0a242f6b322df14075301e1bbbf1
4
- data.tar.gz: 7d2608383fc8cf88398b3ba89cec45879c9c4631869026febcf22604f6665fcf
3
+ metadata.gz: d9e77a423f915bda9a4d02a980a21a1755a6dde139dc3d1890414eacfa72c1c8
4
+ data.tar.gz: 6e2ff10778fd5641f717fb2cf9e23d59e39312179a76cffa40d49ece0ae7a001
5
5
  SHA512:
6
- metadata.gz: b598fdbc496757b7ae6280a5ed07d27f37ebd6077f26b640cf49ddf2ecb711376ed3da081b98b96e2e374dab98d7c57e179d31798c6931633a525022737dbe64
7
- data.tar.gz: 85ceeb2799d89e0d73a2949fe3aeaf19a1c22b0810133371bd628aa54d09eb1b9ebd49a8c843f51c9ad24b04baac7062e35c49c13727747825ee2dfb626b8a19
6
+ metadata.gz: a74ba985ec614bcdf6bcf1c9d031d663341f5f41a40feb513d03313d41cbbd97104c784c806ca5a64b38dffeaf5eea822722a0db2e3f1f78bd402ab18a19093a
7
+ data.tar.gz: e7c2d9563eb65a3931a4d51d775d1c07e9449a748b15cd1a06e1404a3c9d74d4f65634674d2a88ce736982a75642a3bfb2d6bcadeaef39db9f2182dacc3b3a51
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-terraform (0.1.0.pre.36)
4
+ rspec-terraform (0.1.0.pre.39)
5
5
  confidante (>= 0.27)
6
6
  rspec (>= 3.0)
7
7
  ruby-terraform (= 1.7.0.pre.16)
@@ -30,7 +30,7 @@ GEM
30
30
  partialruby (~> 0.3)
31
31
  sexp_processor (~> 4.0)
32
32
  excon (0.92.4)
33
- faker (2.22.0)
33
+ faker (2.23.0)
34
34
  i18n (>= 1.8.11, < 2)
35
35
  faraday (2.5.2)
36
36
  faraday-net_http (>= 2.0, < 3.1)
@@ -131,7 +131,7 @@ GEM
131
131
  diff-lcs (>= 1.2.0, < 2.0)
132
132
  rspec-support (~> 3.11.0)
133
133
  rspec-support (3.11.0)
134
- rubocop (1.35.1)
134
+ rubocop (1.36.0)
135
135
  json (~> 2.3)
136
136
  parallel (~> 1.10)
137
137
  parser (>= 3.1.2.1)
@@ -32,10 +32,8 @@ module RSpec
32
32
  init(parameters)
33
33
  plan_file = plan(parameters)
34
34
  plan_contents = show(parameters, plan_file)
35
-
36
- RubyTerraform::Models::Plan.new(
37
- JSON.parse(plan_contents, symbolize_names: true)
38
- )
35
+ remove(parameters, plan_file)
36
+ parse(plan_contents)
39
37
  end
40
38
 
41
39
  private
@@ -105,6 +103,18 @@ module RSpec
105
103
  stdout.string
106
104
  end
107
105
 
106
+ def parse(plan_contents)
107
+ RubyTerraform::Models::Plan.new(
108
+ JSON.parse(plan_contents, symbolize_names: true)
109
+ )
110
+ end
111
+
112
+ def remove(parameters, plan_file)
113
+ FileUtils.rm_f(
114
+ File.join(parameters[:configuration_directory], plan_file)
115
+ )
116
+ end
117
+
108
118
  def init_command
109
119
  RubyTerraform::Commands::Init.new(binary: binary)
110
120
  end
@@ -135,7 +145,8 @@ module RSpec
135
145
  plan_parameters =
136
146
  parameters.merge(
137
147
  chdir: parameters[:configuration_directory],
138
- out: parameters[:plan_file_name] || SecureRandom.hex(10),
148
+ out: parameters[:plan_file_name] ||
149
+ "#{SecureRandom.hex[0, 10]}.tfplan",
139
150
  input: false
140
151
  )
141
152
 
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpec
4
+ module Terraform
5
+ module Logging
6
+ class << self
7
+ def resolve_streams(opts = {})
8
+ streams = opts[:streams] || []
9
+ devices = devices(opts)
10
+
11
+ {
12
+ logger: resolve_logger(opts[:logger], streams, devices),
13
+ stdout: resolve_stdout(opts[:stdout], streams, devices),
14
+ stderr: resolve_stderr(opts[:stderr], streams, devices)
15
+ }
16
+ end
17
+
18
+ private
19
+
20
+ def resolve_logger(logger, streams, devices)
21
+ return logger if logger
22
+
23
+ log_devices = []
24
+ log_devices << devices[:file] if streams.include?(:file)
25
+ log_devices << devices[:stdout] if streams.include?(:standard)
26
+
27
+ multi_io(log_devices)
28
+ end
29
+
30
+ def resolve_stdout(stdout, streams, devices)
31
+ return stdout if stdout
32
+
33
+ log_devices = []
34
+ log_devices << devices[:file] if streams.include?(:file)
35
+ log_devices << devices[:stdout] if streams.include?(:standard)
36
+
37
+ multi_io(log_devices)
38
+ end
39
+
40
+ def resolve_stderr(stderr, streams, devices)
41
+ return stderr if stderr
42
+
43
+ log_devices = []
44
+ log_devices << devices[:file] if streams.include?(:file)
45
+ log_devices << devices[:stderr] if streams.include?(:standard)
46
+
47
+ multi_io(log_devices)
48
+ end
49
+
50
+ def devices(opts)
51
+ {
52
+ file: log_device(opts[:file_path] || File::NULL),
53
+ stdout: log_device($stdout),
54
+ stderr: log_device($stderr)
55
+ }
56
+ end
57
+
58
+ def log_device(io)
59
+ Logger::LogDevice.new(io)
60
+ end
61
+
62
+ def multi_io(ios)
63
+ RubyTerraform::MultiIO.new(*ios)
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module Terraform
5
- VERSION = '0.1.0.pre.36'
5
+ VERSION = '0.1.0.pre.39'
6
6
  end
7
7
  end
@@ -7,6 +7,7 @@ require_relative 'terraform/version'
7
7
  require_relative 'terraform/configuration'
8
8
  require_relative 'terraform/matchers'
9
9
  require_relative 'terraform/helpers'
10
+ require_relative 'terraform/logging'
10
11
 
11
12
  # TODO
12
13
  # ====
@@ -18,14 +19,43 @@ require_relative 'terraform/helpers'
18
19
  # * Sensitive support in matchers
19
20
  #
20
21
 
22
+ # rubocop:disable Metrics/BlockLength
21
23
  RSpec.configure do |config|
22
24
  config.include(RSpec::Terraform::Matchers)
23
- config.include(RSpec::Terraform::Helpers)
25
+ config.prepend(RSpec::Terraform::Helpers)
24
26
 
25
27
  config.add_setting(:terraform_binary, default: 'terraform')
28
+
29
+ config.add_setting(:terraform_log_file_path, default: nil)
30
+ config.add_setting(:terraform_log_streams, default: [:standard])
31
+
32
+ config.add_setting(:terraform_logger, default: nil)
33
+ config.add_setting(:terraform_stdin, default: nil)
34
+ config.add_setting(:terraform_stdout, default: nil)
35
+ config.add_setting(:terraform_stderr, default: nil)
36
+
26
37
  config.add_setting(:terraform_execution_mode, default: :in_place)
38
+
27
39
  config.add_setting(
28
40
  :terraform_configuration_provider,
29
41
  default: RSpec::Terraform::Configuration.identity_provider
30
42
  )
43
+
44
+ config.before(:suite) do
45
+ resolved_streams = RSpec::Terraform::Logging.resolve_streams(
46
+ file_path: RSpec.configuration.terraform_log_file_path,
47
+ streams: RSpec.configuration.terraform_log_streams,
48
+ logger: RSpec.configuration.terraform_logger,
49
+ stdout: RSpec.configuration.terraform_stdout,
50
+ stderr: RSpec.configuration.terraform_stderr
51
+ )
52
+
53
+ RSpec.configuration.terraform_logger = resolved_streams[:logger]
54
+ RSpec.configuration.terraform_stdout = resolved_streams[:stdout]
55
+ RSpec.configuration.terraform_stderr = resolved_streams[:stderr]
56
+ end
31
57
  end
58
+ # rubocop:enable Metrics/BlockLength
59
+
60
+ RSpec::Core::AnonymousExampleGroup
61
+ .include(RSpec::Terraform::Helpers)
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.36
4
+ version: 0.1.0.pre.39
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-08-29 00:00:00.000000000 Z
11
+ date: 2022-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: confidante
@@ -309,6 +309,7 @@ files:
309
309
  - lib/rspec/terraform/helpers/output.rb
310
310
  - lib/rspec/terraform/helpers/plan.rb
311
311
  - lib/rspec/terraform/helpers/var.rb
312
+ - lib/rspec/terraform/logging.rb
312
313
  - lib/rspec/terraform/matchers.rb
313
314
  - lib/rspec/terraform/matchers/include_output_change.rb
314
315
  - lib/rspec/terraform/matchers/include_resource_change.rb