rspec-terraform 0.1.0.pre.9 → 0.1.0.pre.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +7 -7
- data/lib/rspec/terraform/matchers/include_resource_change.rb +81 -20
- data/lib/rspec/terraform/version.rb +1 -1
- data/rspec-terraform.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f38869b0e2c2de7b280ff09e070c6fa66fecd2ede8dba1e182300306110a20f
|
4
|
+
data.tar.gz: 384a2ec52c9fbf9162ba773a866fec91463c055a0b59bb4fea922fb421d53e9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dabc8823fc35214035ea62093bfcc7623ab8d6921b381cb3c74a3f6691d23a35ae4bbb58f65c3d900245a355fd6e69ac3a139f097efb3b81dc8a409c648e0e35
|
7
|
+
data.tar.gz: 97f7670c091ea2051bf812f126fdc32df5f8b10f9e234a3dc95a23b59842b9b0f30af9ffd4164bfaffd57b90e9c6f5b185468648a0da53bb1d3a562eafa7d9c9
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rspec-terraform (0.1.0.pre.
|
4
|
+
rspec-terraform (0.1.0.pre.12)
|
5
5
|
rspec (>= 3.0)
|
6
|
-
ruby-terraform (= 1.7.0.pre.
|
6
|
+
ruby-terraform (= 1.7.0.pre.8)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
@@ -20,7 +20,7 @@ GEM
|
|
20
20
|
concurrent-ruby (1.1.10)
|
21
21
|
diff-lcs (1.5.0)
|
22
22
|
docile (1.4.0)
|
23
|
-
excon (0.92.
|
23
|
+
excon (0.92.4)
|
24
24
|
faker (2.21.0)
|
25
25
|
i18n (>= 1.8.11, < 2)
|
26
26
|
faraday (2.3.0)
|
@@ -83,14 +83,14 @@ GEM
|
|
83
83
|
diff-lcs (>= 1.2.0, < 2.0)
|
84
84
|
rspec-support (~> 3.11.0)
|
85
85
|
rspec-support (3.11.0)
|
86
|
-
rubocop (1.
|
86
|
+
rubocop (1.32.0)
|
87
87
|
json (~> 2.3)
|
88
88
|
parallel (~> 1.10)
|
89
89
|
parser (>= 3.1.0.0)
|
90
90
|
rainbow (>= 2.2.2, < 4.0)
|
91
91
|
regexp_parser (>= 1.8, < 3.0)
|
92
92
|
rexml (>= 3.2.5, < 4.0)
|
93
|
-
rubocop-ast (>= 1.
|
93
|
+
rubocop-ast (>= 1.19.1, < 2.0)
|
94
94
|
ruby-progressbar (~> 1.7)
|
95
95
|
unicode-display_width (>= 1.4.0, < 3.0)
|
96
96
|
rubocop-ast (1.19.1)
|
@@ -100,7 +100,7 @@ GEM
|
|
100
100
|
rubocop-rspec (2.12.1)
|
101
101
|
rubocop (~> 1.31)
|
102
102
|
ruby-progressbar (1.11.0)
|
103
|
-
ruby-terraform (1.7.0.pre.
|
103
|
+
ruby-terraform (1.7.0.pre.8)
|
104
104
|
immutable-struct (~> 2.4)
|
105
105
|
lino (~> 3.0)
|
106
106
|
ruby2_keywords (0.0.5)
|
@@ -116,7 +116,7 @@ GEM
|
|
116
116
|
simplecov-html (0.12.3)
|
117
117
|
simplecov_json_formatter (0.1.4)
|
118
118
|
sshkey (2.0.0)
|
119
|
-
tzinfo (2.0.
|
119
|
+
tzinfo (2.0.5)
|
120
120
|
concurrent-ruby (~> 1.0)
|
121
121
|
unicode-display_width (2.2.0)
|
122
122
|
|
@@ -5,6 +5,9 @@ require 'rspec/matchers'
|
|
5
5
|
require 'rspec/matchers/built_in/eq'
|
6
6
|
require 'rspec/matchers/built_in/count_expectation'
|
7
7
|
|
8
|
+
require 'ruby_terraform/models/path'
|
9
|
+
require 'ruby_terraform/models/path_set'
|
10
|
+
|
8
11
|
module RSpec
|
9
12
|
module Terraform
|
10
13
|
module Matchers
|
@@ -12,7 +15,7 @@ module RSpec
|
|
12
15
|
class IncludeResourceChange
|
13
16
|
include RSpec::Matchers::BuiltIn::CountExpectation
|
14
17
|
|
15
|
-
attr_reader :definition, :plan
|
18
|
+
attr_reader :definition, :attributes, :plan
|
16
19
|
|
17
20
|
def initialize(definition = {})
|
18
21
|
@definition = definition
|
@@ -34,15 +37,15 @@ module RSpec
|
|
34
37
|
def with_attribute_value(*args)
|
35
38
|
stage, path, value = args.count == 3 ? args : [:after, *args]
|
36
39
|
path = [path] if path.is_a?(Symbol)
|
40
|
+
path = RubyTerraform::Models::Path.new(path)
|
41
|
+
value = maybe_box_value(value)
|
37
42
|
@attributes << { stage: stage, path: path, value: value }
|
38
43
|
self
|
39
44
|
end
|
40
45
|
|
41
46
|
def failure_message
|
42
47
|
"\nexpected: #{positive_expected_line}" \
|
43
|
-
"\n got: #{positive_got_line}"
|
44
|
-
"\n available resource changes are:" \
|
45
|
-
"\n#{resource_change_lines}"
|
48
|
+
"\n got: #{positive_got_line}"
|
46
49
|
end
|
47
50
|
|
48
51
|
def failure_message_when_negated
|
@@ -68,37 +71,62 @@ module RSpec
|
|
68
71
|
end
|
69
72
|
end
|
70
73
|
|
74
|
+
def maybe_box_value(value)
|
75
|
+
if value.respond_to?(:matches?)
|
76
|
+
value
|
77
|
+
else
|
78
|
+
RubyTerraform::Models::Objects.box(value)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
71
82
|
def attribute_matcher(attribute)
|
72
83
|
expected = attribute[:value]
|
73
84
|
return expected if expected.respond_to?(:matches?)
|
74
85
|
|
75
|
-
RSpec::Matchers::BuiltIn::Eq.new(
|
76
|
-
RubyTerraform::Models::Objects.box(expected)
|
77
|
-
)
|
86
|
+
RSpec::Matchers::BuiltIn::Eq.new(expected)
|
78
87
|
end
|
79
88
|
|
80
89
|
def attribute_value(object, attribute)
|
81
90
|
expected = attribute[:value]
|
82
|
-
actual =
|
91
|
+
actual = attribute[:path].read(object)
|
83
92
|
return actual&.unbox if expected.respond_to?(:matches?)
|
84
93
|
|
85
94
|
actual
|
86
95
|
end
|
87
96
|
|
88
97
|
def positive_expected_line
|
98
|
+
maybe_with_expected_attributes(
|
99
|
+
maybe_with_definition(
|
100
|
+
positive_plan_line
|
101
|
+
)
|
102
|
+
)
|
103
|
+
end
|
104
|
+
|
105
|
+
def positive_plan_line
|
89
106
|
cardinality = cardinality_fragment
|
90
107
|
plurality = expected_count.nil? || expected_count == 1 ? '' : 's'
|
91
|
-
expected_line =
|
92
|
-
"a plan including #{cardinality} resource change#{plurality}"
|
93
108
|
|
109
|
+
"a plan including #{cardinality} resource change#{plurality}"
|
110
|
+
end
|
111
|
+
|
112
|
+
def maybe_with_definition(expected_line)
|
94
113
|
unless @definition.empty?
|
95
114
|
expected_line =
|
96
115
|
"#{expected_line} matching definition:\n#{definition_lines}"
|
97
116
|
end
|
117
|
+
expected_line
|
118
|
+
end
|
98
119
|
|
120
|
+
def maybe_with_expected_attributes(expected_line)
|
121
|
+
unless @attributes.empty?
|
122
|
+
expected_line =
|
123
|
+
"#{expected_line}\n with attribute values after " \
|
124
|
+
"the resource change is applied of:\n#{expected_attribute_lines}"
|
125
|
+
end
|
99
126
|
expected_line
|
100
127
|
end
|
101
128
|
|
129
|
+
# rubocop:disable Metrics/MethodLength
|
102
130
|
def positive_got_line
|
103
131
|
if plan.resource_changes.empty?
|
104
132
|
'a plan including no resource changes.'
|
@@ -106,9 +134,21 @@ module RSpec
|
|
106
134
|
count = attribute_matches(plan).count
|
107
135
|
amount = count.zero? ? 'no' : cardinality_amount(count)
|
108
136
|
plurality = count == 1 ? '' : 's'
|
109
|
-
|
137
|
+
got_line =
|
138
|
+
"a plan including #{amount} matching " \
|
139
|
+
"resource change#{plurality}."
|
140
|
+
|
141
|
+
unless attributes.empty?
|
142
|
+
got_line =
|
143
|
+
"#{got_line}\n relevant resource changes are:" \
|
144
|
+
"\n#{relevant_resource_change_lines}"
|
145
|
+
end
|
146
|
+
|
147
|
+
"#{got_line}\n available resource changes are:" \
|
148
|
+
"\n#{available_resource_change_lines}"
|
110
149
|
end
|
111
150
|
end
|
151
|
+
# rubocop:enable Metrics/MethodLength
|
112
152
|
|
113
153
|
def cardinality_fragment
|
114
154
|
qualifier = cardinality_qualifier
|
@@ -136,21 +176,42 @@ module RSpec
|
|
136
176
|
end
|
137
177
|
|
138
178
|
def definition_lines
|
179
|
+
indent = ' '
|
139
180
|
definition
|
140
|
-
.collect { |k, v| "
|
181
|
+
.collect { |k, v| "#{indent}#{k} = #{v.inspect}" }
|
141
182
|
.join("\n")
|
142
183
|
end
|
143
184
|
|
144
|
-
def
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
185
|
+
def expected_attribute_lines
|
186
|
+
paths = attributes.collect { |attribute| attribute[:path] }
|
187
|
+
path_set = RubyTerraform::Models::PathSet.new(paths)
|
188
|
+
values = attributes.collect { |attribute| attribute[:value] }
|
189
|
+
object = RubyTerraform::Models::Objects.object(path_set, values)
|
190
|
+
object.render(level: 6, bare: true)
|
191
|
+
end
|
192
|
+
|
193
|
+
def relevant_resource_change_lines
|
194
|
+
relevant_lines = definition_matches(plan).collect do |rc|
|
195
|
+
address = rc.address
|
196
|
+
actions = rc.change.actions.join(', ')
|
197
|
+
attributes = rc.change.after_object
|
198
|
+
attribute_lines = attributes.render(level: 8, bare: true)
|
199
|
+
|
200
|
+
" - #{address} (#{actions})\n#{attribute_lines}"
|
201
|
+
end
|
202
|
+
relevant_lines.join("\n")
|
203
|
+
end
|
204
|
+
|
205
|
+
def available_resource_change_lines
|
206
|
+
available_lines = plan.resource_changes.collect do |rc|
|
207
|
+
address = rc.address
|
208
|
+
actions = rc.change.actions.join(', ')
|
209
|
+
" - #{address} (#{actions})"
|
210
|
+
end
|
211
|
+
available_lines.join("\n")
|
152
212
|
end
|
153
213
|
end
|
214
|
+
|
154
215
|
# rubocop:enable Metrics/ClassLength
|
155
216
|
end
|
156
217
|
end
|
data/rspec-terraform.gemspec
CHANGED
@@ -38,7 +38,7 @@ Gem::Specification.new do |spec|
|
|
38
38
|
spec.required_ruby_version = '>= 2.7'
|
39
39
|
|
40
40
|
spec.add_dependency 'rspec', '>= 3.0'
|
41
|
-
spec.add_dependency 'ruby-terraform', '1.7.0.pre.
|
41
|
+
spec.add_dependency 'ruby-terraform', '1.7.0.pre.8'
|
42
42
|
|
43
43
|
spec.add_development_dependency 'bundler'
|
44
44
|
spec.add_development_dependency 'faker'
|
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.
|
4
|
+
version: 0.1.0.pre.12
|
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-07-
|
11
|
+
date: 2022-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.7.0.pre.
|
33
|
+
version: 1.7.0.pre.8
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.7.0.pre.
|
40
|
+
version: 1.7.0.pre.8
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|