File tree Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,8 @@ def matches?(resource)
28
28
actual = resource [ @parameter ]
29
29
expected = @value
30
30
31
+ actual = RSpec ::Puppet ::Sensitive . new ( actual . unwrap ) if actual . is_a? ( Puppet ::Pops ::Types ::PSensitiveType ::Sensitive )
32
+
31
33
# Puppet flattens an array with a single value into just the value and
32
34
# this can cause confusion when testing as people expect when you put
33
35
# an array in, you'll get an array out.
Original file line number Diff line number Diff line change @@ -24,6 +24,11 @@ def inspect
24
24
"Sensitive(#{ @value . inspect } )"
25
25
end
26
26
27
+ # @return the unwrapped value (needed to show diff)
28
+ def to_s
29
+ inspect
30
+ end
31
+
27
32
# Check for equality with another value.
28
33
# If compared to Puppet Sensitive type, it compares the wrapped values.
29
34
Original file line number Diff line number Diff line change 108
108
expect ( subject . matches? ( foo_parameter : nil ) ) . to be ( false )
109
109
end
110
110
end
111
+
112
+ context 'with sensitive("foo") expected' do
113
+ subject do
114
+ described_class . new ( :foo_parameter , RSpec ::Puppet ::Sensitive . new ( 'foo' ) , :should )
115
+ end
116
+
117
+ it 'matches sensitive("foo")' do
118
+ expect ( subject . matches? ( foo_parameter : RSpec ::Puppet ::Sensitive . new ( 'foo' ) ) ) . to be ( true )
119
+ expect ( subject . errors . size ) . to eq ( 0 )
120
+ end
121
+
122
+ it 'does not match sensitive("bar")' do
123
+ expect ( subject . matches? ( foo_parameter : RSpec ::Puppet ::Sensitive . new ( 'bar' ) ) ) . to be ( false )
124
+ expect ( subject . errors . size ) . to eq ( 1 )
125
+ expect ( subject . errors [ 0 ] . message ) . to eq ( 'foo_parameter set to Sensitive("foo") but it is set to Sensitive("bar")' )
126
+ end
127
+
128
+ it 'does not matches "foo"' do
129
+ expect ( subject . matches? ( foo_parameter : 'foo' ) ) . to be ( false )
130
+ expect ( subject . errors . size ) . to eq ( 1 )
131
+ expect ( subject . errors [ 0 ] . message ) . to eq ( 'foo_parameter set to Sensitive("foo") but it is set to "foo"' )
132
+ end
133
+
134
+ it 'does not matches "Sensitive [value redacted]"' do
135
+ expect ( subject . matches? ( foo_parameter : 'Sensitive [value redacted]' ) ) . to be ( false )
136
+ expect ( subject . errors . size ) . to eq ( 1 )
137
+ expect ( subject . errors [ 0 ] . message ) . to eq ( 'foo_parameter set to Sensitive("foo") but it is set to "Sensitive [value redacted]"' )
138
+ end
139
+ end
111
140
end
112
141
end
You can’t perform that action at this time.
0 commit comments