license-acceptance 0.2.10 → 0.2.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/lib/license_acceptance/acceptor.rb +24 -22
- data/lib/license_acceptance/strategy/argument.rb +44 -0
- data/lib/license_acceptance/strategy/base.rb +11 -0
- data/lib/license_acceptance/strategy/environment.rb +38 -0
- data/lib/license_acceptance/strategy/file.rb +102 -0
- data/lib/license_acceptance/strategy/prompt.rb +111 -0
- data/lib/license_acceptance/strategy/provided_value.rb +28 -0
- data/lib/license_acceptance/version.rb +1 -1
- data/spec/license_acceptance/acceptor_spec.rb +37 -73
- data/spec/license_acceptance/strategy/argument_spec.rb +82 -0
- data/spec/license_acceptance/strategy/environment_spec.rb +76 -0
- data/spec/license_acceptance/{file_acceptance_spec.rb → strategy/file_spec.rb} +3 -3
- data/spec/license_acceptance/{prompt_acceptance_spec.rb → strategy/prompt_spec.rb} +4 -4
- data/spec/license_acceptance/strategy/provided_value_spec.rb +55 -0
- metadata +14 -11
- data/lib/license_acceptance/arg_acceptance.rb +0 -32
- data/lib/license_acceptance/env_acceptance.rb +0 -26
- data/lib/license_acceptance/file_acceptance.rb +0 -97
- data/lib/license_acceptance/prompt_acceptance.rb +0 -106
- data/spec/license_acceptance/arg_acceptance_spec.rb +0 -57
- data/spec/license_acceptance/env_acceptance_spec.rb +0 -65
@@ -0,0 +1,28 @@
|
|
1
|
+
require "license_acceptance/strategy/base"
|
2
|
+
|
3
|
+
module LicenseAcceptance
|
4
|
+
module Strategy
|
5
|
+
|
6
|
+
# Used for library consumers to parse their own form of acceptance (knife config, omnibus config, etc.) and pass it in
|
7
|
+
class ProvidedValue < Base
|
8
|
+
attr_reader :value
|
9
|
+
|
10
|
+
def initialize(value)
|
11
|
+
@value = value
|
12
|
+
end
|
13
|
+
|
14
|
+
def accepted?
|
15
|
+
value == ACCEPT
|
16
|
+
end
|
17
|
+
|
18
|
+
def silent?
|
19
|
+
value == ACCEPT_SILENT
|
20
|
+
end
|
21
|
+
|
22
|
+
def no_persist?
|
23
|
+
value == ACCEPT_NO_PERSIST
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -30,29 +30,47 @@ RSpec.describe LicenseAcceptance::Acceptor do
|
|
30
30
|
|
31
31
|
describe "#check_and_persist" do
|
32
32
|
let(:reader) { instance_double(LicenseAcceptance::ProductReader) }
|
33
|
-
let(:file_acc) { instance_double(LicenseAcceptance::
|
34
|
-
let(:arg_acc) { instance_double(LicenseAcceptance::
|
35
|
-
let(:prompt_acc) { instance_double(LicenseAcceptance::
|
36
|
-
let(:env_acc) { instance_double(LicenseAcceptance::
|
33
|
+
let(:file_acc) { instance_double(LicenseAcceptance::Strategy::File) }
|
34
|
+
let(:arg_acc) { instance_double(LicenseAcceptance::Strategy::Argument) }
|
35
|
+
let(:prompt_acc) { instance_double(LicenseAcceptance::Strategy::Prompt) }
|
36
|
+
let(:env_acc) { instance_double(LicenseAcceptance::Strategy::Environment) }
|
37
|
+
let(:provided_acc) { instance_double(LicenseAcceptance::Strategy::ProvidedValue) }
|
37
38
|
|
38
39
|
before do
|
39
40
|
expect(LicenseAcceptance::ProductReader).to receive(:new).and_return(reader)
|
40
|
-
expect(LicenseAcceptance::
|
41
|
-
expect(LicenseAcceptance::
|
42
|
-
expect(LicenseAcceptance::
|
43
|
-
expect(LicenseAcceptance::
|
41
|
+
expect(LicenseAcceptance::Strategy::File).to receive(:new).and_return(file_acc)
|
42
|
+
expect(LicenseAcceptance::Strategy::Argument).to receive(:new).and_return(arg_acc)
|
43
|
+
expect(LicenseAcceptance::Strategy::Prompt).to receive(:new).and_return(prompt_acc)
|
44
|
+
expect(LicenseAcceptance::Strategy::Environment).to receive(:new).and_return(env_acc)
|
45
|
+
expect(LicenseAcceptance::Strategy::ProvidedValue).to receive(:new).and_return(provided_acc)
|
46
|
+
|
47
|
+
allow(provided_acc).to receive(:no_persist?).and_return(false)
|
48
|
+
allow(env_acc).to receive(:no_persist?).and_return(false)
|
49
|
+
allow(arg_acc).to receive(:no_persist?).and_return(false)
|
50
|
+
allow(provided_acc).to receive(:accepted?).and_return(false)
|
51
|
+
allow(env_acc).to receive(:accepted?).and_return(false)
|
52
|
+
allow(arg_acc).to receive(:accepted?).and_return(false)
|
53
|
+
allow(provided_acc).to receive(:silent?).and_return(false)
|
54
|
+
allow(env_acc).to receive(:silent?).and_return(false)
|
55
|
+
allow(arg_acc).to receive(:silent?).and_return(false)
|
44
56
|
end
|
45
57
|
|
46
|
-
describe "when
|
58
|
+
describe "when accept-no-persist is provided from the caller" do
|
59
|
+
it "returns true" do
|
60
|
+
expect(provided_acc).to receive(:no_persist?).and_return(true)
|
61
|
+
expect(acc.check_and_persist(product, version)).to eq(true)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "when accept-no-persist environment variable is set" do
|
47
66
|
it "returns true" do
|
48
67
|
expect(env_acc).to receive(:no_persist?).and_return(true)
|
49
68
|
expect(acc.check_and_persist(product, version)).to eq(true)
|
50
69
|
end
|
51
70
|
end
|
52
71
|
|
53
|
-
describe "when
|
72
|
+
describe "when accept-no-persist command line argument is set" do
|
54
73
|
it "returns true" do
|
55
|
-
expect(env_acc).to receive(:no_persist?).and_return(false)
|
56
74
|
expect(arg_acc).to receive(:no_persist?).and_return(true)
|
57
75
|
expect(acc.check_and_persist(product, version)).to eq(true)
|
58
76
|
end
|
@@ -60,8 +78,6 @@ RSpec.describe LicenseAcceptance::Acceptor do
|
|
60
78
|
|
61
79
|
describe "when there are no missing licenses" do
|
62
80
|
it "returns true" do
|
63
|
-
expect(env_acc).to receive(:no_persist?).and_return(false)
|
64
|
-
expect(arg_acc).to receive(:no_persist?).and_return(false)
|
65
81
|
expect(reader).to receive(:read)
|
66
82
|
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
67
83
|
expect(file_acc).to receive(:accepted?).with(relationship).and_return([])
|
@@ -71,14 +87,10 @@ RSpec.describe LicenseAcceptance::Acceptor do
|
|
71
87
|
|
72
88
|
describe "when the user accepts as an environment variable" do
|
73
89
|
it "returns true" do
|
74
|
-
expect(env_acc).to receive(:no_persist?).and_return(false)
|
75
|
-
expect(arg_acc).to receive(:no_persist?).and_return(false)
|
76
90
|
expect(reader).to receive(:read)
|
77
91
|
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
78
92
|
expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
|
79
|
-
expect(env_acc).to receive(:accepted?).
|
80
|
-
expect(env_acc).to receive(:silent?).with(ENV).and_return(false)
|
81
|
-
expect(arg_acc).to receive(:silent?).with(ARGV).and_return(false)
|
93
|
+
expect(env_acc).to receive(:accepted?).and_return(true)
|
82
94
|
expect(file_acc).to receive(:persist).with(relationship, missing).and_return([])
|
83
95
|
expect(acc.check_and_persist(product, version)).to eq(true)
|
84
96
|
expect(output.string).to match(/1 product license accepted./)
|
@@ -88,12 +100,10 @@ RSpec.describe LicenseAcceptance::Acceptor do
|
|
88
100
|
let(:opts) { { output: output, persist: false } }
|
89
101
|
|
90
102
|
it "returns true" do
|
91
|
-
expect(env_acc).to receive(:no_persist?).and_return(false)
|
92
|
-
expect(arg_acc).to receive(:no_persist?).and_return(false)
|
93
103
|
expect(reader).to receive(:read)
|
94
104
|
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
95
105
|
expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
|
96
|
-
expect(env_acc).to receive(:accepted?).
|
106
|
+
expect(env_acc).to receive(:accepted?).and_return(true)
|
97
107
|
expect(acc.check_and_persist(product, version)).to eq(true)
|
98
108
|
expect(output.string).to_not match(/accepted./)
|
99
109
|
end
|
@@ -103,14 +113,10 @@ RSpec.describe LicenseAcceptance::Acceptor do
|
|
103
113
|
let(:opts) { { output: output } }
|
104
114
|
|
105
115
|
it "returns true and silently persists the file" do
|
106
|
-
expect(env_acc).to receive(:no_persist?).and_return(false)
|
107
|
-
expect(arg_acc).to receive(:no_persist?).and_return(false)
|
108
116
|
expect(reader).to receive(:read)
|
109
117
|
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
110
118
|
expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
|
111
|
-
expect(env_acc).to receive(:
|
112
|
-
expect(arg_acc).to receive(:accepted?).with(ARGV).and_return(false)
|
113
|
-
expect(env_acc).to receive(:silent?).with(ENV).twice.and_return(true)
|
119
|
+
expect(env_acc).to receive(:silent?).twice.and_return(true)
|
114
120
|
expect(file_acc).to receive(:persist).with(relationship, missing).and_return([])
|
115
121
|
expect(acc.check_and_persist(product, version)).to eq(true)
|
116
122
|
expect(output.string).to be_empty
|
@@ -119,12 +125,10 @@ RSpec.describe LicenseAcceptance::Acceptor do
|
|
119
125
|
|
120
126
|
describe "when file persistance fails" do
|
121
127
|
it "returns true" do
|
122
|
-
expect(env_acc).to receive(:no_persist?).and_return(false)
|
123
|
-
expect(arg_acc).to receive(:no_persist?).and_return(false)
|
124
128
|
expect(reader).to receive(:read)
|
125
129
|
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
126
130
|
expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
|
127
|
-
expect(env_acc).to receive(:accepted?).
|
131
|
+
expect(env_acc).to receive(:accepted?).and_return(true)
|
128
132
|
expect(file_acc).to receive(:persist).with(relationship, missing).and_return([StandardError.new("foo")])
|
129
133
|
expect(acc.check_and_persist(product, version)).to eq(true)
|
130
134
|
expect(output.string).to match(/Could not persist acceptance:/)
|
@@ -134,15 +138,10 @@ RSpec.describe LicenseAcceptance::Acceptor do
|
|
134
138
|
|
135
139
|
describe "when the user accepts as an arg" do
|
136
140
|
it "returns true" do
|
137
|
-
expect(env_acc).to receive(:no_persist?).and_return(false)
|
138
|
-
expect(arg_acc).to receive(:no_persist?).and_return(false)
|
139
141
|
expect(reader).to receive(:read)
|
140
142
|
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
141
143
|
expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
|
142
|
-
expect(
|
143
|
-
expect(arg_acc).to receive(:accepted?).with(ARGV).and_return(true)
|
144
|
-
expect(env_acc).to receive(:silent?).with(ENV).and_return(false)
|
145
|
-
expect(arg_acc).to receive(:silent?).with(ARGV).and_return(false)
|
144
|
+
expect(arg_acc).to receive(:accepted?).and_return(true)
|
146
145
|
expect(file_acc).to receive(:persist).with(relationship, missing).and_return([])
|
147
146
|
expect(acc.check_and_persist(product, version)).to eq(true)
|
148
147
|
expect(output.string).to match(/1 product license accepted./)
|
@@ -152,15 +151,10 @@ RSpec.describe LicenseAcceptance::Acceptor do
|
|
152
151
|
let(:opts) { { output: output } }
|
153
152
|
|
154
153
|
it "returns true and silently persists the file" do
|
155
|
-
expect(env_acc).to receive(:no_persist?).and_return(false)
|
156
|
-
expect(arg_acc).to receive(:no_persist?).and_return(false)
|
157
154
|
expect(reader).to receive(:read)
|
158
155
|
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
159
156
|
expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
|
160
|
-
expect(
|
161
|
-
expect(arg_acc).to receive(:accepted?).with(ARGV).and_return(false)
|
162
|
-
expect(env_acc).to receive(:silent?).with(ENV).twice.and_return(false)
|
163
|
-
expect(arg_acc).to receive(:silent?).with(ARGV).twice.and_return(true)
|
157
|
+
expect(arg_acc).to receive(:silent?).twice.and_return(true)
|
164
158
|
expect(file_acc).to receive(:persist).with(relationship, missing).and_return([])
|
165
159
|
expect(acc.check_and_persist(product, version)).to eq(true)
|
166
160
|
expect(output.string).to be_empty
|
@@ -172,13 +166,10 @@ RSpec.describe LicenseAcceptance::Acceptor do
|
|
172
166
|
let(:opts) { { output: output, persist: false } }
|
173
167
|
|
174
168
|
it "returns true" do
|
175
|
-
expect(env_acc).to receive(:no_persist?).and_return(false)
|
176
|
-
expect(arg_acc).to receive(:no_persist?).and_return(false)
|
177
169
|
expect(reader).to receive(:read)
|
178
170
|
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
179
171
|
expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
|
180
|
-
expect(
|
181
|
-
expect(arg_acc).to receive(:accepted?).with(ARGV).and_return(true)
|
172
|
+
expect(arg_acc).to receive(:accepted?).and_return(true)
|
182
173
|
expect(acc.check_and_persist(product, version)).to eq(true)
|
183
174
|
expect(output.string).to_not match(/accepted./)
|
184
175
|
end
|
@@ -186,13 +177,10 @@ RSpec.describe LicenseAcceptance::Acceptor do
|
|
186
177
|
|
187
178
|
describe "when file persistance fails" do
|
188
179
|
it "returns true" do
|
189
|
-
expect(env_acc).to receive(:no_persist?).and_return(false)
|
190
|
-
expect(arg_acc).to receive(:no_persist?).and_return(false)
|
191
180
|
expect(reader).to receive(:read)
|
192
181
|
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
193
182
|
expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
|
194
|
-
expect(
|
195
|
-
expect(arg_acc).to receive(:accepted?).with(ARGV).and_return(true)
|
183
|
+
expect(arg_acc).to receive(:accepted?).and_return(true)
|
196
184
|
expect(file_acc).to receive(:persist).with(relationship, missing).and_return([StandardError.new("bar")])
|
197
185
|
expect(acc.check_and_persist(product, version)).to eq(true)
|
198
186
|
expect(output.string).to match(/Could not persist acceptance:/)
|
@@ -203,15 +191,9 @@ RSpec.describe LicenseAcceptance::Acceptor do
|
|
203
191
|
describe "when the prompt is not a tty" do
|
204
192
|
let(:opts) { { output: File.open(File::NULL, "w") } }
|
205
193
|
it "raises a LicenseNotAcceptedError error" do
|
206
|
-
expect(env_acc).to receive(:no_persist?).and_return(false)
|
207
|
-
expect(arg_acc).to receive(:no_persist?).and_return(false)
|
208
194
|
expect(reader).to receive(:read)
|
209
195
|
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
210
196
|
expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
|
211
|
-
expect(env_acc).to receive(:accepted?).and_return(false)
|
212
|
-
expect(arg_acc).to receive(:accepted?).and_return(false)
|
213
|
-
expect(env_acc).to receive(:silent?).and_return(false)
|
214
|
-
expect(arg_acc).to receive(:silent?).and_return(false)
|
215
197
|
expect(prompt_acc).to_not receive(:request)
|
216
198
|
expect { acc.check_and_persist(product, version) }.to raise_error(LicenseAcceptance::LicenseNotAcceptedError)
|
217
199
|
end
|
@@ -219,15 +201,9 @@ RSpec.describe LicenseAcceptance::Acceptor do
|
|
219
201
|
|
220
202
|
describe "when the user accepts with the prompt" do
|
221
203
|
it "returns true" do
|
222
|
-
expect(env_acc).to receive(:no_persist?).and_return(false)
|
223
|
-
expect(arg_acc).to receive(:no_persist?).and_return(false)
|
224
204
|
expect(reader).to receive(:read)
|
225
205
|
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
226
206
|
expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
|
227
|
-
expect(env_acc).to receive(:accepted?).and_return(false)
|
228
|
-
expect(arg_acc).to receive(:accepted?).and_return(false)
|
229
|
-
expect(env_acc).to receive(:silent?).and_return(false)
|
230
|
-
expect(arg_acc).to receive(:silent?).and_return(false)
|
231
207
|
expect(prompt_acc).to receive(:request).with(missing).and_yield.and_return(true)
|
232
208
|
expect(file_acc).to receive(:persist).with(relationship, missing)
|
233
209
|
expect(acc.check_and_persist(product, version)).to eq(true)
|
@@ -237,15 +213,9 @@ RSpec.describe LicenseAcceptance::Acceptor do
|
|
237
213
|
let(:opts) { { output: output, persist: false } }
|
238
214
|
|
239
215
|
it "returns true" do
|
240
|
-
expect(env_acc).to receive(:no_persist?).and_return(false)
|
241
|
-
expect(arg_acc).to receive(:no_persist?).and_return(false)
|
242
216
|
expect(reader).to receive(:read)
|
243
217
|
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
244
218
|
expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
|
245
|
-
expect(env_acc).to receive(:accepted?).and_return(false)
|
246
|
-
expect(arg_acc).to receive(:accepted?).and_return(false)
|
247
|
-
expect(env_acc).to receive(:silent?).and_return(false)
|
248
|
-
expect(arg_acc).to receive(:silent?).and_return(false)
|
249
219
|
expect(prompt_acc).to receive(:request).with(missing).and_yield.and_return(true)
|
250
220
|
expect(acc.check_and_persist(product, version)).to eq(true)
|
251
221
|
end
|
@@ -254,15 +224,9 @@ RSpec.describe LicenseAcceptance::Acceptor do
|
|
254
224
|
|
255
225
|
describe "when the user declines with the prompt" do
|
256
226
|
it "raises a LicenseNotAcceptedError error" do
|
257
|
-
expect(env_acc).to receive(:no_persist?).and_return(false)
|
258
|
-
expect(arg_acc).to receive(:no_persist?).and_return(false)
|
259
227
|
expect(reader).to receive(:read)
|
260
228
|
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
261
229
|
expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
|
262
|
-
expect(env_acc).to receive(:accepted?).and_return(false)
|
263
|
-
expect(arg_acc).to receive(:accepted?).and_return(false)
|
264
|
-
expect(env_acc).to receive(:silent?).and_return(false)
|
265
|
-
expect(arg_acc).to receive(:silent?).and_return(false)
|
266
230
|
expect(prompt_acc).to receive(:request).with(missing).and_return(false)
|
267
231
|
expect { acc.check_and_persist(product, version) }.to raise_error(LicenseAcceptance::LicenseNotAcceptedError)
|
268
232
|
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "license_acceptance/strategy/argument"
|
3
|
+
|
4
|
+
RSpec.describe LicenseAcceptance::Strategy::Argument do
|
5
|
+
let(:acc) { LicenseAcceptance::Strategy::Argument.new(argv) }
|
6
|
+
|
7
|
+
describe "#accepted?" do
|
8
|
+
describe "when value is space seperated" do
|
9
|
+
let(:argv) { ["--chef-license", "accept"] }
|
10
|
+
it "returns true if the args contain the required flag with spaces" do
|
11
|
+
expect(acc.accepted?).to eq(true)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "when the value is equal seperated" do
|
16
|
+
let(:argv) { ["--chef-license=accept"] }
|
17
|
+
it "returns true if the args contain the required flag with equal" do
|
18
|
+
expect(acc.accepted?).to eq(true)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
[ ["--chef-license"], ["--chef-license=foo"], ["--chef-license", "foo"] ].each do |v|
|
23
|
+
describe "when the value is #{v}" do
|
24
|
+
let(:argv) { v }
|
25
|
+
it "returns false if the args do not contain the required value" do
|
26
|
+
expect(acc.accepted?).to eq(false)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#silent?" do
|
33
|
+
describe "when value is space seperated" do
|
34
|
+
let(:argv) { ["--chef-license", "accept-silent"] }
|
35
|
+
it "returns true if the args contain the required flag with spaces" do
|
36
|
+
expect(acc.silent?).to eq(true)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "when the value is equal seperated" do
|
41
|
+
let(:argv) { ["--chef-license=accept-silent"] }
|
42
|
+
it "returns true if the args contain the required flag with equal" do
|
43
|
+
expect(acc.silent?).to eq(true)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
[ ["--chef-license"], ["--chef-license=accept"], ["--chef-license", "accept"] ].each do |v|
|
48
|
+
describe "when the value is #{v}" do
|
49
|
+
let(:argv) { v }
|
50
|
+
it "returns false if the args do not contain the required value" do
|
51
|
+
expect(acc.silent?).to eq(false)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#no_persist?" do
|
58
|
+
describe "when value is space seperated" do
|
59
|
+
let(:argv) { ["--chef-license", "accept-no-persist"] }
|
60
|
+
it "returns true if the args contain the required flag with spaces" do
|
61
|
+
expect(acc.no_persist?).to eq(true)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "when the value is equal seperated" do
|
66
|
+
let(:argv) { ["--chef-license=accept-no-persist"] }
|
67
|
+
it "returns true if the args contain the required flag with equal" do
|
68
|
+
expect(acc.no_persist?).to eq(true)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
[ ["--chef-license"], ["--chef-license=accept"], ["--chef-license", "accept"] ].each do |v|
|
73
|
+
describe "when the value is #{v}" do
|
74
|
+
let(:argv) { v }
|
75
|
+
it "returns false if the args do not contain the required value" do
|
76
|
+
expect(acc.no_persist?).to eq(false)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "license_acceptance/strategy/environment"
|
3
|
+
|
4
|
+
RSpec.describe LicenseAcceptance::Strategy::Environment do
|
5
|
+
let(:acc) { LicenseAcceptance::Strategy::Environment.new(env) }
|
6
|
+
|
7
|
+
describe "#accepted?" do
|
8
|
+
describe "when the environment contains the correct key and value" do
|
9
|
+
let(:env) { {"CHEF_LICENSE" => "accept"} }
|
10
|
+
it "returns true" do
|
11
|
+
expect(acc.accepted?).to eq(true)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "when the env has a key but nil value" do
|
16
|
+
let(:env) { {"CHEF_LICENSE" => nil} }
|
17
|
+
it "returns false" do
|
18
|
+
expect(acc.accepted?).to eq(false)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "when the env has a key but incorrect value" do
|
23
|
+
let(:env) { {"CHEF_LICENSE" => "foo"} }
|
24
|
+
it "returns false" do
|
25
|
+
expect(acc.accepted?).to eq(false)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#silent?" do
|
31
|
+
describe "when the environment contains the correct key and value" do
|
32
|
+
let(:env) { {"CHEF_LICENSE" => "accept-silent"} }
|
33
|
+
it "returns true" do
|
34
|
+
expect(acc.silent?).to eq(true)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "when the env has a key but nil value" do
|
39
|
+
let(:env) { {"CHEF_LICENSE" => nil} }
|
40
|
+
it "returns false" do
|
41
|
+
expect(acc.silent?).to eq(false)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "when the env has a key but incorrect value" do
|
46
|
+
let(:env) { {"CHEF_LICENSE" => "accept"} }
|
47
|
+
it "returns false" do
|
48
|
+
expect(acc.silent?).to eq(false)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#no_persist?" do
|
54
|
+
describe "when the environment contains the correct key and value" do
|
55
|
+
let(:env) { {"CHEF_LICENSE" => "accept-no-persist"} }
|
56
|
+
it "returns true" do
|
57
|
+
expect(acc.no_persist?).to eq(true)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "when the env has a key but nil value" do
|
62
|
+
let(:env) { {"CHEF_LICENSE" => nil} }
|
63
|
+
it "returns false" do
|
64
|
+
expect(acc.no_persist?).to eq(false)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "when the env has a key but incorrect value" do
|
69
|
+
let(:env) { {"CHEF_LICENSE" => "accept-silent"} }
|
70
|
+
it "returns false" do
|
71
|
+
expect(acc.no_persist?).to eq(false)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -1,17 +1,17 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
require "license_acceptance/config"
|
3
|
-
require "license_acceptance/
|
3
|
+
require "license_acceptance/strategy/file"
|
4
4
|
require "license_acceptance/product_relationship"
|
5
5
|
require "license_acceptance/product"
|
6
6
|
|
7
|
-
RSpec.describe LicenseAcceptance::
|
7
|
+
RSpec.describe LicenseAcceptance::Strategy::File do
|
8
8
|
let(:dir1) { "/dir1" }
|
9
9
|
let(:dir2) { "/dir2" }
|
10
10
|
let(:dir3) { "/dir3" }
|
11
11
|
let(:config) do
|
12
12
|
instance_double(LicenseAcceptance::Config, license_locations: [dir1, dir2], persist_location: dir3)
|
13
13
|
end
|
14
|
-
let(:acc) { LicenseAcceptance::
|
14
|
+
let(:acc) { LicenseAcceptance::Strategy::File.new(config) }
|
15
15
|
let(:p1_name) { "chef_client" }
|
16
16
|
let(:p1_filename) { "p1_filename" }
|
17
17
|
let(:p1) { instance_double(LicenseAcceptance::Product, name: p1_name, filename: p1_filename) }
|