rspec-terraform 0.1.0.pre.37 → 0.1.0.pre.40

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: f5d0cfbad94632db8e93fd7d1747f84d6c1b41f2210e97108a0809685ebe248f
4
- data.tar.gz: 1fda168e5e4bf24e8d9c6a89bc602974b3a865e94a22cf2bef7421c96e980d43
3
+ metadata.gz: 12e11f477f99fd41080131cf322d8d6dedf40645e04bb41b66de3b5cee3128b5
4
+ data.tar.gz: 47ccbe633464a8a414b9ea950a27c664bae5bef3e60155463b9a979f398900ac
5
5
  SHA512:
6
- metadata.gz: e35006b4b7834783ae18eeded06ef9bd29d52322718ab51c9cb7c09403d28e83e69cc7835bb63a75a565dac10094eb89b4602aaf77e2a1b925953fe17daf504d
7
- data.tar.gz: 1fff5187933552ed362c84114470adadb9cab8799420df6b3ce6a945d9cda5d1d614fec5dec6a672675a6e98a2de83fbeb2f75caf6861f2434b0da324dd732f4
6
+ metadata.gz: 19aa8f5adeedf3bc1a71129205363f7eca9a843d47462345c34ee8a36358ee35e9d4ad2ea9bf1ac63bb8846c789181c88039428cc1514bfbd1f500ce3ca7b145
7
+ data.tar.gz: 3c338a356d1ad4ff0264f1bcef7e756ea743c0f3582865bb62cfaadcc6bb539b4467a7c239836cb0c5f285362d313d9f1ab22aca62203d55816cdc8855c69287
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-terraform (0.1.0.pre.37)
4
+ rspec-terraform (0.1.0.pre.40)
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)
@@ -205,4 +205,4 @@ DEPENDENCIES
205
205
  terminal-notifier-guard
206
206
 
207
207
  BUNDLED WITH
208
- 2.3.21
208
+ 2.3.22
@@ -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,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpec
4
+ module Terraform
5
+ module Logging
6
+ class << self
7
+ def resolve_streams(opts = {})
8
+ opts = resolve_opts(opts)
9
+ streams = opts[:streams]
10
+ level = opts[:level]
11
+ devices = devices(opts)
12
+
13
+ resolve_opts(opts)
14
+
15
+ {
16
+ logger: resolve_logger(opts[:logger], streams, devices, level),
17
+ stdout: resolve_stdout(opts[:stdout], streams, devices),
18
+ stderr: resolve_stderr(opts[:stderr], streams, devices)
19
+ }
20
+ end
21
+
22
+ private
23
+
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)
39
+ return logger if logger
40
+
41
+ log_devices = []
42
+ log_devices << devices[:file] if streams.include?(:file)
43
+ log_devices << devices[:stdout] if streams.include?(:standard)
44
+
45
+ Logger.new(multi_io(log_devices), level: level)
46
+ end
47
+
48
+ def resolve_stdout(stdout, streams, devices)
49
+ return stdout if stdout
50
+
51
+ log_devices = []
52
+ log_devices << devices[:file] if streams.include?(:file)
53
+ log_devices << devices[:stdout] if streams.include?(:standard)
54
+
55
+ multi_io(log_devices)
56
+ end
57
+
58
+ def resolve_stderr(stderr, streams, devices)
59
+ return stderr if stderr
60
+
61
+ log_devices = []
62
+ log_devices << devices[:file] if streams.include?(:file)
63
+ log_devices << devices[:stderr] if streams.include?(:standard)
64
+
65
+ multi_io(log_devices)
66
+ end
67
+
68
+ def devices(opts)
69
+ {
70
+ file: log_device(opts[:file_path] || File::NULL),
71
+ stdout: log_device(opts[:stdout] || $stdout),
72
+ stderr: log_device($stderr)
73
+ }
74
+ end
75
+
76
+ def log_device(io)
77
+ Logger::LogDevice.new(io)
78
+ end
79
+
80
+ def multi_io(ios)
81
+ RubyTerraform::MultiIO.new(*ios)
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module Terraform
5
- VERSION = '0.1.0.pre.37'
5
+ VERSION = '0.1.0.pre.40'
6
6
  end
7
7
  end
@@ -2,33 +2,62 @@
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'
8
9
  require_relative 'terraform/matchers'
9
10
  require_relative 'terraform/helpers'
11
+ require_relative 'terraform/logging'
10
12
 
11
13
  # TODO
12
14
  # ====
13
15
  #
14
- # * Logging
15
16
  # * Test session
16
17
  # * Before support in matchers
17
18
  # * Reference support in matchers
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
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_level, default: Logger::INFO)
31
+ config.add_setting(:terraform_log_streams, default: [:standard])
32
+
33
+ config.add_setting(:terraform_logger, default: nil)
34
+ config.add_setting(:terraform_stdin, default: nil)
35
+ config.add_setting(:terraform_stdout, default: nil)
36
+ config.add_setting(:terraform_stderr, default: nil)
37
+
26
38
  config.add_setting(:terraform_execution_mode, default: :in_place)
39
+
27
40
  config.add_setting(
28
41
  :terraform_configuration_provider,
29
42
  default: RSpec::Terraform::Configuration.identity_provider
30
43
  )
44
+
45
+ config.before(:suite) do
46
+ resolved_streams = RSpec::Terraform::Logging.resolve_streams(
47
+ file_path: RSpec.configuration.terraform_log_file_path,
48
+ level: RSpec.configuration.terraform_log_level,
49
+ streams: RSpec.configuration.terraform_log_streams,
50
+ logger: RSpec.configuration.terraform_logger,
51
+ stdout: RSpec.configuration.terraform_stdout,
52
+ stderr: RSpec.configuration.terraform_stderr
53
+ )
54
+
55
+ RSpec.configuration.terraform_logger = resolved_streams[:logger]
56
+ RSpec.configuration.terraform_stdout = resolved_streams[:stdout]
57
+ RSpec.configuration.terraform_stderr = resolved_streams[:stderr]
58
+ end
31
59
  end
60
+ # rubocop:enable Metrics/BlockLength
32
61
 
33
62
  RSpec::Core::AnonymousExampleGroup
34
63
  .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.37
4
+ version: 0.1.0.pre.40
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-30 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
@@ -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