license-acceptance 0.2.13 → 0.2.15
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 +1 -1
- data/config/product_info.toml +2 -0
- data/lib/license_acceptance/acceptor.rb +37 -2
- data/lib/license_acceptance/product.rb +7 -3
- data/lib/license_acceptance/product_reader.rb +12 -1
- data/lib/license_acceptance/strategy/base.rb +0 -4
- data/lib/license_acceptance/version.rb +1 -1
- data/spec/license_acceptance/acceptor_spec.rb +24 -20
- data/spec/license_acceptance/product_reader_spec.rb +21 -5
- data/spec/license_acceptance/product_spec.rb +3 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ff1d1fbab957952084fe44a975d3c4ddf8bbccfebda7e3a7c54caafd3f5bd28
|
4
|
+
data.tar.gz: 6a7274ee80f7da6465ab928c2e85e02a2da180028e449a2cc04ba7bc956bd655
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 343c73d26b864e316cd742065d2b83527ee6d64ba5ff7bd97a00fa9c05c00c6fdf4ee61c9ddd3cfdd40225c6bdb7bf06fdcb601e425c529c1341e3b586523999
|
7
|
+
data.tar.gz: 3205485af5f026d1d888dec565c229e1c843acc9558693a217b74df70f217cf43124a9c438197a2b6e37874086c3b25dbdac7cf68d2e0724baeab110c1a019a5
|
data/Gemfile.lock
CHANGED
data/config/product_info.toml
CHANGED
@@ -10,6 +10,11 @@ require "license_acceptance/strategy/prompt"
|
|
10
10
|
require "license_acceptance/strategy/provided_value"
|
11
11
|
|
12
12
|
module LicenseAcceptance
|
13
|
+
|
14
|
+
ACCEPT = "accept"
|
15
|
+
ACCEPT_SILENT = "accept-silent"
|
16
|
+
ACCEPT_NO_PERSIST = "accept-no-persist"
|
17
|
+
|
13
18
|
class Acceptor
|
14
19
|
extend Forwardable
|
15
20
|
include Logger
|
@@ -20,11 +25,13 @@ module LicenseAcceptance
|
|
20
25
|
@config = Config.new(opts)
|
21
26
|
Logger.initialize(config.logger)
|
22
27
|
@product_reader = ProductReader.new
|
28
|
+
product_reader.read
|
23
29
|
@env_strategy = Strategy::Environment.new(ENV)
|
24
30
|
@file_strategy = Strategy::File.new(config)
|
25
31
|
@arg_strategy = Strategy::Argument.new(ARGV)
|
26
32
|
@prompt_strategy = Strategy::Prompt.new(config)
|
27
33
|
@provided_strategy = Strategy::ProvidedValue.new(opts.fetch(:provided, nil))
|
34
|
+
@acceptance_value = nil
|
28
35
|
end
|
29
36
|
|
30
37
|
def_delegator :@config, :output
|
@@ -42,10 +49,10 @@ module LicenseAcceptance
|
|
42
49
|
def check_and_persist(product_name, version)
|
43
50
|
if accepted_no_persist?
|
44
51
|
logger.debug("Chef License accepted with no persistence")
|
52
|
+
@acceptance_value = ACCEPT_NO_PERSIST
|
45
53
|
return true
|
46
54
|
end
|
47
55
|
|
48
|
-
product_reader.read
|
49
56
|
product_relationship = product_reader.lookup(product_name, version)
|
50
57
|
|
51
58
|
missing_licenses = file_strategy.accepted?(product_relationship)
|
@@ -53,6 +60,7 @@ module LicenseAcceptance
|
|
53
60
|
# They have already accepted all licenses and stored their acceptance in the persistent files
|
54
61
|
if missing_licenses.empty?
|
55
62
|
logger.debug("All licenses present")
|
63
|
+
@acceptance_value = ACCEPT
|
56
64
|
return true
|
57
65
|
end
|
58
66
|
|
@@ -65,11 +73,15 @@ module LicenseAcceptance
|
|
65
73
|
output_persist_failed(errs)
|
66
74
|
end
|
67
75
|
end
|
76
|
+
@acceptance_value = accepted_silent? ? ACCEPT_SILENT : ACCEPT
|
68
77
|
return true
|
69
78
|
elsif config.output.isatty && prompt_strategy.request(missing_licenses) do
|
79
|
+
# We have to infer the acceptance value if they use the prompt to accept
|
70
80
|
if config.persist
|
81
|
+
@acceptance_value = ACCEPT
|
71
82
|
file_strategy.persist(product_relationship, missing_licenses)
|
72
83
|
else
|
84
|
+
@acceptance_value = ACCEPT_NO_PERSIST
|
73
85
|
[]
|
74
86
|
end
|
75
87
|
end
|
@@ -87,6 +99,29 @@ module LicenseAcceptance
|
|
87
99
|
new(opts).check_and_persist(product_name, version)
|
88
100
|
end
|
89
101
|
|
102
|
+
# Check whether the specified product requires license acceptance for the given version.
|
103
|
+
def license_required?(mixlib_name, version)
|
104
|
+
product = product_reader.lookup_by_mixlib(mixlib_name)
|
105
|
+
return false if product.nil?
|
106
|
+
return true if version == :latest
|
107
|
+
Gem::Version.new(version) >= Gem::Version.new(product.license_required_version)
|
108
|
+
end
|
109
|
+
|
110
|
+
# Some callers only know about mixlib names so we need a way for them to get the product
|
111
|
+
# name as this library knows it.
|
112
|
+
def name_from_mixlib(mixlib_name)
|
113
|
+
product = product_reader.lookup_by_mixlib(mixlib_name)
|
114
|
+
return nil if product.nil?
|
115
|
+
product.name
|
116
|
+
end
|
117
|
+
|
118
|
+
# Return the value that was matched ("accept", "accept-no-persist", etc.). Used by callers so they do not
|
119
|
+
# have to know the precedence order between provided/environment/argument. Can just get back the value
|
120
|
+
# that was used. Value is only guaranteed to be set after calling check_and_persist.
|
121
|
+
def acceptance_value
|
122
|
+
@acceptance_value
|
123
|
+
end
|
124
|
+
|
90
125
|
def accepted?
|
91
126
|
provided_strategy.accepted? || env_strategy.accepted? || arg_strategy.accepted?
|
92
127
|
end
|
@@ -125,7 +160,7 @@ module LicenseAcceptance
|
|
125
160
|
|
126
161
|
class LicenseNotAcceptedError < RuntimeError
|
127
162
|
def initialize(missing_licenses)
|
128
|
-
msg = "Missing licenses for the following:\n* " + missing_licenses.join("\n* ")
|
163
|
+
msg = "Missing licenses for the following:\n* " + missing_licenses.map(&:name).join("\n* ")
|
129
164
|
super(msg)
|
130
165
|
end
|
131
166
|
end
|
@@ -1,19 +1,23 @@
|
|
1
1
|
module LicenseAcceptance
|
2
2
|
class Product
|
3
3
|
|
4
|
-
attr_reader :name, :pretty_name, :filename
|
4
|
+
attr_reader :name, :pretty_name, :filename, :mixlib_name, :license_required_version
|
5
5
|
|
6
|
-
def initialize(name, pretty_name, filename)
|
6
|
+
def initialize(name, pretty_name, filename, mixlib_name, license_required_version)
|
7
7
|
@name = name
|
8
8
|
@pretty_name = pretty_name
|
9
9
|
@filename = filename
|
10
|
+
@mixlib_name = mixlib_name
|
11
|
+
@license_required_version = license_required_version
|
10
12
|
end
|
11
13
|
|
12
14
|
def ==(other)
|
13
15
|
return false if other.class != Product
|
14
16
|
if other.name == name &&
|
15
17
|
other.pretty_name == pretty_name &&
|
16
|
-
other.filename == filename
|
18
|
+
other.filename == filename &&
|
19
|
+
other.mixlib_name == mixlib_name
|
20
|
+
other.license_required_version == license_required_version
|
17
21
|
return true
|
18
22
|
end
|
19
23
|
return false
|
@@ -19,7 +19,11 @@ module LicenseAcceptance
|
|
19
19
|
raise InvalidProductInfo.new(location) if toml.empty? || toml["products"].nil? || toml["relationships"].nil?
|
20
20
|
|
21
21
|
for product in toml["products"]
|
22
|
-
products[product["name"]] = Product.new(
|
22
|
+
products[product["name"]] = Product.new(
|
23
|
+
product["name"], product["pretty_name"],
|
24
|
+
product["filename"], product["mixlib_name"],
|
25
|
+
product["license_required_version"]
|
26
|
+
)
|
23
27
|
end
|
24
28
|
|
25
29
|
for parent_name, children in toml["relationships"]
|
@@ -62,6 +66,13 @@ module LicenseAcceptance
|
|
62
66
|
ProductRelationship.new(parent_product, children, parent_version)
|
63
67
|
end
|
64
68
|
|
69
|
+
def lookup_by_mixlib(mixlib_name)
|
70
|
+
found_product = products.values.find(nil) do |p|
|
71
|
+
p.mixlib_name == mixlib_name
|
72
|
+
end
|
73
|
+
found_product
|
74
|
+
end
|
75
|
+
|
65
76
|
end
|
66
77
|
|
67
78
|
class UnknownProduct < RuntimeError
|
@@ -13,18 +13,17 @@ RSpec.describe LicenseAcceptance::Acceptor do
|
|
13
13
|
end
|
14
14
|
let(:opts) { { output: output } }
|
15
15
|
let(:acc) { LicenseAcceptance::Acceptor.new(opts) }
|
16
|
-
let(:product) { "chef_client" }
|
16
|
+
let(:product) { instance_double(LicenseAcceptance::Product, name: "chef_client") }
|
17
17
|
let(:version) { "version" }
|
18
18
|
let(:relationship) { instance_double(LicenseAcceptance::ProductRelationship) }
|
19
|
-
let(:
|
20
|
-
let(:missing) { [p1] }
|
19
|
+
let(:missing) { [product] }
|
21
20
|
|
22
21
|
describe "#check_and_persist!" do
|
23
22
|
let(:err) { LicenseAcceptance::LicenseNotAcceptedError.new([product]) }
|
24
23
|
it "outputs an error message to stdout and exits when license acceptance is declined" do
|
25
24
|
expect(acc).to receive(:check_and_persist).and_raise(err)
|
26
|
-
expect { acc.check_and_persist!(product, version) }.to raise_error(SystemExit)
|
27
|
-
expect(output.string).to match(/#{product}/)
|
25
|
+
expect { acc.check_and_persist!(product.name, version) }.to raise_error(SystemExit)
|
26
|
+
expect(output.string).to match(/#{product.name}/)
|
28
27
|
end
|
29
28
|
end
|
30
29
|
|
@@ -53,12 +52,15 @@ RSpec.describe LicenseAcceptance::Acceptor do
|
|
53
52
|
allow(provided_acc).to receive(:silent?).and_return(false)
|
54
53
|
allow(env_acc).to receive(:silent?).and_return(false)
|
55
54
|
allow(arg_acc).to receive(:silent?).and_return(false)
|
55
|
+
|
56
|
+
expect(reader).to receive(:read)
|
56
57
|
end
|
57
58
|
|
58
59
|
describe "when accept-no-persist is provided from the caller" do
|
59
60
|
it "returns true" do
|
60
61
|
expect(provided_acc).to receive(:no_persist?).and_return(true)
|
61
62
|
expect(acc.check_and_persist(product, version)).to eq(true)
|
63
|
+
expect(acc.acceptance_value).to eq(LicenseAcceptance::ACCEPT_NO_PERSIST)
|
62
64
|
end
|
63
65
|
end
|
64
66
|
|
@@ -66,6 +68,7 @@ RSpec.describe LicenseAcceptance::Acceptor do
|
|
66
68
|
it "returns true" do
|
67
69
|
expect(env_acc).to receive(:no_persist?).and_return(true)
|
68
70
|
expect(acc.check_and_persist(product, version)).to eq(true)
|
71
|
+
expect(acc.acceptance_value).to eq(LicenseAcceptance::ACCEPT_NO_PERSIST)
|
69
72
|
end
|
70
73
|
end
|
71
74
|
|
@@ -73,39 +76,40 @@ RSpec.describe LicenseAcceptance::Acceptor do
|
|
73
76
|
it "returns true" do
|
74
77
|
expect(arg_acc).to receive(:no_persist?).and_return(true)
|
75
78
|
expect(acc.check_and_persist(product, version)).to eq(true)
|
79
|
+
expect(acc.acceptance_value).to eq(LicenseAcceptance::ACCEPT_NO_PERSIST)
|
76
80
|
end
|
77
81
|
end
|
78
82
|
|
79
83
|
describe "when there are no missing licenses" do
|
80
84
|
it "returns true" do
|
81
|
-
expect(reader).to receive(:read)
|
82
85
|
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
83
86
|
expect(file_acc).to receive(:accepted?).with(relationship).and_return([])
|
84
87
|
expect(acc.check_and_persist(product, version)).to eq(true)
|
88
|
+
expect(acc.acceptance_value).to eq(LicenseAcceptance::ACCEPT)
|
85
89
|
end
|
86
90
|
end
|
87
91
|
|
88
92
|
describe "when the user accepts as an environment variable" do
|
89
93
|
it "returns true" do
|
90
|
-
expect(reader).to receive(:read)
|
91
94
|
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
92
95
|
expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
|
93
96
|
expect(env_acc).to receive(:accepted?).and_return(true)
|
94
97
|
expect(file_acc).to receive(:persist).with(relationship, missing).and_return([])
|
95
98
|
expect(acc.check_and_persist(product, version)).to eq(true)
|
96
99
|
expect(output.string).to match(/1 product license accepted./)
|
100
|
+
expect(acc.acceptance_value).to eq(LicenseAcceptance::ACCEPT)
|
97
101
|
end
|
98
102
|
|
99
103
|
describe "when persist is set to false" do
|
100
104
|
let(:opts) { { output: output, persist: false } }
|
101
105
|
|
102
106
|
it "returns true" do
|
103
|
-
expect(reader).to receive(:read)
|
104
107
|
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
105
108
|
expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
|
106
109
|
expect(env_acc).to receive(:accepted?).and_return(true)
|
107
110
|
expect(acc.check_and_persist(product, version)).to eq(true)
|
108
111
|
expect(output.string).to_not match(/accepted./)
|
112
|
+
expect(acc.acceptance_value).to eq(LicenseAcceptance::ACCEPT)
|
109
113
|
end
|
110
114
|
end
|
111
115
|
|
@@ -113,51 +117,51 @@ RSpec.describe LicenseAcceptance::Acceptor do
|
|
113
117
|
let(:opts) { { output: output } }
|
114
118
|
|
115
119
|
it "returns true and silently persists the file" do
|
116
|
-
expect(reader).to receive(:read)
|
117
120
|
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
118
121
|
expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
|
119
|
-
expect(env_acc).to receive(:silent?).
|
122
|
+
expect(env_acc).to receive(:silent?).times.exactly(3).and_return(true)
|
120
123
|
expect(file_acc).to receive(:persist).with(relationship, missing).and_return([])
|
121
124
|
expect(acc.check_and_persist(product, version)).to eq(true)
|
122
125
|
expect(output.string).to be_empty
|
126
|
+
expect(acc.acceptance_value).to eq(LicenseAcceptance::ACCEPT_SILENT)
|
123
127
|
end
|
124
128
|
end
|
125
129
|
|
126
130
|
describe "when file persistance fails" do
|
127
131
|
it "returns true" do
|
128
|
-
expect(reader).to receive(:read)
|
129
132
|
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
130
133
|
expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
|
131
134
|
expect(env_acc).to receive(:accepted?).and_return(true)
|
132
135
|
expect(file_acc).to receive(:persist).with(relationship, missing).and_return([StandardError.new("foo")])
|
133
136
|
expect(acc.check_and_persist(product, version)).to eq(true)
|
134
137
|
expect(output.string).to match(/Could not persist acceptance:/)
|
138
|
+
expect(acc.acceptance_value).to eq(LicenseAcceptance::ACCEPT)
|
135
139
|
end
|
136
140
|
end
|
137
141
|
end
|
138
142
|
|
139
143
|
describe "when the user accepts as an arg" do
|
140
144
|
it "returns true" do
|
141
|
-
expect(reader).to receive(:read)
|
142
145
|
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
143
146
|
expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
|
144
147
|
expect(arg_acc).to receive(:accepted?).and_return(true)
|
145
148
|
expect(file_acc).to receive(:persist).with(relationship, missing).and_return([])
|
146
149
|
expect(acc.check_and_persist(product, version)).to eq(true)
|
147
150
|
expect(output.string).to match(/1 product license accepted./)
|
151
|
+
expect(acc.acceptance_value).to eq(LicenseAcceptance::ACCEPT)
|
148
152
|
end
|
149
153
|
|
150
154
|
describe "when the silent option is used" do
|
151
155
|
let(:opts) { { output: output } }
|
152
156
|
|
153
157
|
it "returns true and silently persists the file" do
|
154
|
-
expect(reader).to receive(:read)
|
155
158
|
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
156
159
|
expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
|
157
|
-
expect(arg_acc).to receive(:silent?).
|
160
|
+
expect(arg_acc).to receive(:silent?).times.exactly(3).and_return(true)
|
158
161
|
expect(file_acc).to receive(:persist).with(relationship, missing).and_return([])
|
159
162
|
expect(acc.check_and_persist(product, version)).to eq(true)
|
160
163
|
expect(output.string).to be_empty
|
164
|
+
expect(acc.acceptance_value).to eq(LicenseAcceptance::ACCEPT_SILENT)
|
161
165
|
end
|
162
166
|
end
|
163
167
|
|
@@ -166,24 +170,24 @@ RSpec.describe LicenseAcceptance::Acceptor do
|
|
166
170
|
let(:opts) { { output: output, persist: false } }
|
167
171
|
|
168
172
|
it "returns true" do
|
169
|
-
expect(reader).to receive(:read)
|
170
173
|
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
171
174
|
expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
|
172
175
|
expect(arg_acc).to receive(:accepted?).and_return(true)
|
173
176
|
expect(acc.check_and_persist(product, version)).to eq(true)
|
174
177
|
expect(output.string).to_not match(/accepted./)
|
178
|
+
expect(acc.acceptance_value).to eq(LicenseAcceptance::ACCEPT)
|
175
179
|
end
|
176
180
|
end
|
177
181
|
|
178
182
|
describe "when file persistance fails" do
|
179
183
|
it "returns true" do
|
180
|
-
expect(reader).to receive(:read)
|
181
184
|
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
182
185
|
expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
|
183
186
|
expect(arg_acc).to receive(:accepted?).and_return(true)
|
184
187
|
expect(file_acc).to receive(:persist).with(relationship, missing).and_return([StandardError.new("bar")])
|
185
188
|
expect(acc.check_and_persist(product, version)).to eq(true)
|
186
189
|
expect(output.string).to match(/Could not persist acceptance:/)
|
190
|
+
expect(acc.acceptance_value).to eq(LicenseAcceptance::ACCEPT)
|
187
191
|
end
|
188
192
|
end
|
189
193
|
end
|
@@ -191,44 +195,44 @@ RSpec.describe LicenseAcceptance::Acceptor do
|
|
191
195
|
describe "when the prompt is not a tty" do
|
192
196
|
let(:opts) { { output: File.open(File::NULL, "w") } }
|
193
197
|
it "raises a LicenseNotAcceptedError error" do
|
194
|
-
expect(reader).to receive(:read)
|
195
198
|
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
196
199
|
expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
|
197
200
|
expect(prompt_acc).to_not receive(:request)
|
198
201
|
expect { acc.check_and_persist(product, version) }.to raise_error(LicenseAcceptance::LicenseNotAcceptedError)
|
202
|
+
expect(acc.acceptance_value).to eq(nil)
|
199
203
|
end
|
200
204
|
end
|
201
205
|
|
202
206
|
describe "when the user accepts with the prompt" do
|
203
207
|
it "returns true" do
|
204
|
-
expect(reader).to receive(:read)
|
205
208
|
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
206
209
|
expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
|
207
210
|
expect(prompt_acc).to receive(:request).with(missing).and_yield.and_return(true)
|
208
211
|
expect(file_acc).to receive(:persist).with(relationship, missing)
|
209
212
|
expect(acc.check_and_persist(product, version)).to eq(true)
|
213
|
+
expect(acc.acceptance_value).to eq(LicenseAcceptance::ACCEPT)
|
210
214
|
end
|
211
215
|
|
212
216
|
describe "when persist is set to false" do
|
213
217
|
let(:opts) { { output: output, persist: false } }
|
214
218
|
|
215
219
|
it "returns true" do
|
216
|
-
expect(reader).to receive(:read)
|
217
220
|
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
218
221
|
expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
|
219
222
|
expect(prompt_acc).to receive(:request).with(missing).and_yield.and_return(true)
|
220
223
|
expect(acc.check_and_persist(product, version)).to eq(true)
|
224
|
+
expect(acc.acceptance_value).to eq(LicenseAcceptance::ACCEPT_NO_PERSIST)
|
221
225
|
end
|
222
226
|
end
|
223
227
|
end
|
224
228
|
|
225
229
|
describe "when the user declines with the prompt" do
|
226
230
|
it "raises a LicenseNotAcceptedError error" do
|
227
|
-
expect(reader).to receive(:read)
|
228
231
|
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
229
232
|
expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
|
230
233
|
expect(prompt_acc).to receive(:request).with(missing).and_return(false)
|
231
234
|
expect { acc.check_and_persist(product, version) }.to raise_error(LicenseAcceptance::LicenseNotAcceptedError)
|
235
|
+
expect(acc.acceptance_value).to eq(nil)
|
232
236
|
end
|
233
237
|
end
|
234
238
|
|
@@ -7,11 +7,11 @@ RSpec.describe LicenseAcceptance::ProductReader do
|
|
7
7
|
let(:version) { "0.1.0" }
|
8
8
|
let(:location) { "location" }
|
9
9
|
|
10
|
-
let(:p1) { {"name" => "p1", "pretty_name" => "P1", "filename" => "f1"} }
|
11
|
-
let(:p2) { {"name" => "p2", "pretty_name" => "P2", "filename" => "f2"} }
|
10
|
+
let(:p1) { {"name" => "p1", "pretty_name" => "P1", "filename" => "f1", "mixlib_name" => "p1m", "license_required_version" => "p1v"} }
|
11
|
+
let(:p2) { {"name" => "p2", "pretty_name" => "P2", "filename" => "f2", "mixlib_name" => "p2m", "license_required_version" => "p2v"} }
|
12
12
|
# defined the `==` operator on Product for ease of comparison
|
13
|
-
let(:product1) { LicenseAcceptance::Product.new(p1["name"], p1["pretty_name"], p1["filename"]) }
|
14
|
-
let(:product2) { LicenseAcceptance::Product.new(p2["name"], p2["pretty_name"], p2["filename"]) }
|
13
|
+
let(:product1) { LicenseAcceptance::Product.new(p1["name"], p1["pretty_name"], p1["filename"], p1["mixlib_name"], p1["license_required_version"]) }
|
14
|
+
let(:product2) { LicenseAcceptance::Product.new(p2["name"], p2["pretty_name"], p2["filename"], p2["mixlib_name"], p2["license_required_version"]) }
|
15
15
|
let(:r1) { {p1 => p2} }
|
16
16
|
let(:toml) { {"products" => [p1, p2], "relationships" => {"p1" => ["p2"]}} }
|
17
17
|
|
@@ -114,7 +114,7 @@ RSpec.describe LicenseAcceptance::ProductReader do
|
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
117
|
-
let(:nonya) { LicenseAcceptance::Product.new("nonya", "NonYa", "nofile") }
|
117
|
+
let(:nonya) { LicenseAcceptance::Product.new("nonya", "NonYa", "nofile", "no_mixlib", "no_version") }
|
118
118
|
describe "when called on a product with no relationship" do
|
119
119
|
before do
|
120
120
|
reader.products = { "nonya" => nonya }
|
@@ -136,4 +136,20 @@ RSpec.describe LicenseAcceptance::ProductReader do
|
|
136
136
|
end
|
137
137
|
end
|
138
138
|
|
139
|
+
describe "::lookup_by_mixlib" do
|
140
|
+
before do
|
141
|
+
expect(reader).to receive(:get_location).and_return(location)
|
142
|
+
expect(Tomlrb).to receive(:load_file).with(location, symbolize_keys: false).and_return(toml)
|
143
|
+
reader.read
|
144
|
+
end
|
145
|
+
|
146
|
+
it "returns a Product successfully" do
|
147
|
+
expect(reader.lookup_by_mixlib("p1m")).to eq(product1)
|
148
|
+
end
|
149
|
+
|
150
|
+
it "returns nil for an unknown product" do
|
151
|
+
expect(reader.lookup_by_mixlib("foo")).to eq(nil)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
139
155
|
end
|
@@ -2,12 +2,14 @@ require "spec_helper"
|
|
2
2
|
require "license_acceptance/product"
|
3
3
|
|
4
4
|
RSpec.describe LicenseAcceptance::Product do
|
5
|
-
let(:instance) { LicenseAcceptance::Product.new("name", "Pretty Name", "filename") }
|
5
|
+
let(:instance) { LicenseAcceptance::Product.new("name", "Pretty Name", "filename", "mixlib_name", "version") }
|
6
6
|
|
7
7
|
it "can lookup the product attributes" do
|
8
8
|
expect(instance.name).to eq("name")
|
9
9
|
expect(instance.pretty_name).to eq("Pretty Name")
|
10
10
|
expect(instance.filename).to eq("filename")
|
11
|
+
expect(instance.mixlib_name).to eq("mixlib_name")
|
12
|
+
expect(instance.license_required_version).to eq("version")
|
11
13
|
end
|
12
14
|
|
13
15
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: license-acceptance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tyler-ball
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-04-
|
11
|
+
date: 2019-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pastel
|