rspec-terraform 0.1.0.pre.38 → 0.1.0.pre.41

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: e3e05eb03fa7646e942de57b9dace527769ff3f82d29a8558e296c633e4781f5
4
- data.tar.gz: a48852eace306d90abed4dceae0b3ae6967fde6206c884817690f78161a11f70
3
+ metadata.gz: 6abf52967c937d8a7761aab1289a1a244ed440bd735311360d3888c3746d8e39
4
+ data.tar.gz: ef8e4d1ed48f86632623785b6fafa69bef6bc38c63d902c3897ea8083c31bc7a
5
5
  SHA512:
6
- metadata.gz: 3e9bfbef08d1a36d6484543bc98e63ca2a1dbea26787c4460798aa0bd03a0155d5d68e077b357467d56c2e9f15ee7913df44c879f397375afa4eb6df1e9fb836
7
- data.tar.gz: 9e1d4703dcd59209d1141da61361a5503021416a11c29d772777d97b8bca316ef73282cefb1db1b8a4f8e990c69b0fb39602946f79d5df51dd134d6650ffed68
6
+ metadata.gz: 2034dd4ce31339bd6e6e834adfba4d0fc7ca894e532e2e0ef1e4e06efd24c3596d5daf2317933c5d4ee50c0da88ee3188840ed141a9a20492f9ba5d66c97ac1f
7
+ data.tar.gz: d41ffaa70e27cedc9f6dcaceb2aeec825be58c9bb41cc8344e9780d7cc1f9db77b8f44dba89da6cb159beabcfa6febac2c0ea93d76bd831f33a163b380bd39eb
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-terraform (0.1.0.pre.38)
4
+ rspec-terraform (0.1.0.pre.41)
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
@@ -0,0 +1,107 @@
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
+ streams = opts[:streams]
70
+ file_path = opts[:file_path]
71
+ stdout = opts[:stdout]
72
+
73
+ {
74
+ file: log_device(resolve_file_path(file_path, streams)),
75
+ stdout: log_device(resolved_stdout(stdout)),
76
+ stderr: log_device(resolved_stderr)
77
+ }
78
+ end
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
+
97
+ def log_device(io)
98
+ Logger::LogDevice.new(io)
99
+ end
100
+
101
+ def multi_io(ios)
102
+ RubyTerraform::MultiIO.new(*ios)
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module Terraform
5
- VERSION = '0.1.0.pre.38'
5
+ VERSION = '0.1.0.pre.41'
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.38
4
+ version: 0.1.0.pre.41
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-31 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