license-acceptance 1.0.11 → 2.0.0
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 +23 -1
- data/config/product_info.toml +1 -1
- data/lib/license_acceptance/acceptor.rb +28 -25
- data/lib/license_acceptance/cli_flags/mixlib_cli.rb +2 -2
- data/lib/license_acceptance/cli_flags/thor.rb +3 -3
- data/lib/license_acceptance/config.rb +5 -4
- data/lib/license_acceptance/product.rb +8 -6
- data/lib/license_acceptance/product_reader.rb +7 -3
- data/lib/license_acceptance/strategy/argument.rb +4 -3
- data/lib/license_acceptance/strategy/environment.rb +3 -2
- data/lib/license_acceptance/strategy/file.rb +8 -8
- data/lib/license_acceptance/strategy/prompt.rb +23 -23
- data/lib/license_acceptance/version.rb +1 -1
- metadata +6 -132
- data/Gemfile.lock +0 -94
- data/Rakefile +0 -6
- data/spec/license_acceptance/acceptor_spec.rb +0 -301
- data/spec/license_acceptance/cli_flags/mixlib_cli_spec.rb +0 -14
- data/spec/license_acceptance/cli_flags/thor_spec.rb +0 -14
- data/spec/license_acceptance/config_spec.rb +0 -111
- data/spec/license_acceptance/product_reader_spec.rb +0 -155
- data/spec/license_acceptance/product_spec.rb +0 -15
- data/spec/license_acceptance/strategy/argument_spec.rb +0 -82
- data/spec/license_acceptance/strategy/environment_spec.rb +0 -76
- data/spec/license_acceptance/strategy/file_spec.rb +0 -127
- data/spec/license_acceptance/strategy/prompt_spec.rb +0 -100
- data/spec/license_acceptance/strategy/provided_value_spec.rb +0 -55
- data/spec/spec_helper.rb +0 -25
@@ -1,127 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "license_acceptance/config"
|
3
|
-
require "license_acceptance/strategy/file"
|
4
|
-
require "license_acceptance/product_relationship"
|
5
|
-
require "license_acceptance/product"
|
6
|
-
|
7
|
-
RSpec.describe LicenseAcceptance::Strategy::File do
|
8
|
-
let(:dir1) { "/dir1" }
|
9
|
-
let(:dir2) { "/dir2" }
|
10
|
-
let(:dir3) { "/dir3" }
|
11
|
-
let(:config) do
|
12
|
-
instance_double(LicenseAcceptance::Config, license_locations: [dir1, dir2], persist_location: dir3)
|
13
|
-
end
|
14
|
-
let(:acc) { LicenseAcceptance::Strategy::File.new(config) }
|
15
|
-
let(:p1_id) { "foo" }
|
16
|
-
let(:p1_filename) { "p1_filename" }
|
17
|
-
let(:p1_pretty) { "Pretty Name" }
|
18
|
-
let(:p1) { instance_double(LicenseAcceptance::Product, id: p1_id, filename: p1_filename, pretty_name: p1_pretty) }
|
19
|
-
let(:version) { "0.1.0" }
|
20
|
-
let(:product_relationship) { instance_double(LicenseAcceptance::ProductRelationship, parent: p1, children: [], parent_version: version) }
|
21
|
-
let(:mode) { File::WRONLY | File::CREAT | File::EXCL }
|
22
|
-
|
23
|
-
describe "#check" do
|
24
|
-
describe "when there is an existing license file" do
|
25
|
-
it "returns an empty missing product list" do
|
26
|
-
expect(File).to receive(:exist?).with(File.join(dir1, p1_filename)).and_return(true)
|
27
|
-
expect(acc.accepted?(product_relationship)).to eq([])
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "when there is not an existing license file" do
|
32
|
-
it "returns the product in the missing product list" do
|
33
|
-
expect(File).to receive(:exist?).with(File.join(dir1, p1_filename)).and_return(false)
|
34
|
-
expect(File).to receive(:exist?).with(File.join(dir2, p1_filename)).and_return(false)
|
35
|
-
expect(acc.accepted?(product_relationship)).to eq([p1])
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe "#persist" do
|
40
|
-
let(:file) { double("file") }
|
41
|
-
|
42
|
-
it "stores a single license without children" do
|
43
|
-
expect(Dir).to receive(:exist?).with(dir3).and_return(true)
|
44
|
-
expect(File).to receive(:open).with(File.join(dir3, p1_filename), mode).and_yield(file)
|
45
|
-
expect(file).to receive(:<<) do |yaml|
|
46
|
-
yaml = YAML.load(yaml)
|
47
|
-
expect(yaml["id"]).to eq(p1_id)
|
48
|
-
expect(yaml["name"]).to eq(p1_pretty)
|
49
|
-
expect(yaml["accepting_product"]).to eq(p1_id)
|
50
|
-
expect(yaml["accepting_product_version"]).to eq(version)
|
51
|
-
end
|
52
|
-
expect(acc.persist(product_relationship, [p1])).to eq([])
|
53
|
-
end
|
54
|
-
|
55
|
-
describe "when license has children" do
|
56
|
-
let(:p2_id) { "bar" }
|
57
|
-
let(:p2_filename) { "p2_filename" }
|
58
|
-
let(:p2_pretty) { "Other Pretty Name" }
|
59
|
-
let(:p2) { instance_double(LicenseAcceptance::Product, id: p2_id, filename: p2_filename, pretty_name: p2_pretty) }
|
60
|
-
let(:product_relationship) {
|
61
|
-
instance_double(
|
62
|
-
LicenseAcceptance::ProductRelationship,
|
63
|
-
parent: p1,
|
64
|
-
children: [p2],
|
65
|
-
parent_version: version
|
66
|
-
)
|
67
|
-
}
|
68
|
-
|
69
|
-
it "stores a license file for all" do
|
70
|
-
expect(Dir).to receive(:exist?).with(dir3).and_return(true)
|
71
|
-
expect(File).to receive(:open).with(File.join(dir3, p1_filename), mode).and_yield(file)
|
72
|
-
expect(file).to receive(:<<) do |yaml|
|
73
|
-
yaml = YAML.load(yaml)
|
74
|
-
expect(yaml["id"]).to eq(p1_id)
|
75
|
-
expect(yaml["name"]).to eq(p1_pretty)
|
76
|
-
expect(yaml["accepting_product"]).to eq(p1_id)
|
77
|
-
expect(yaml["accepting_product_version"]).to eq(version)
|
78
|
-
end
|
79
|
-
expect(File).to receive(:open).with(File.join(dir3, p2_filename), mode).and_yield(file)
|
80
|
-
expect(file).to receive(:<<) do |yaml|
|
81
|
-
yaml = YAML.load(yaml)
|
82
|
-
expect(yaml["id"]).to eq(p2_id)
|
83
|
-
expect(yaml["name"]).to eq(p2_pretty)
|
84
|
-
expect(yaml["accepting_product"]).to eq(p1_id)
|
85
|
-
expect(yaml["accepting_product_version"]).to eq(version)
|
86
|
-
end
|
87
|
-
expect(acc.persist(product_relationship, [p1, p2])).to eq([])
|
88
|
-
end
|
89
|
-
|
90
|
-
describe "when parent is already persisted" do
|
91
|
-
it "only stores a license file for the child" do
|
92
|
-
expect(Dir).to receive(:exist?).with(dir3).and_return(true)
|
93
|
-
expect(File).to receive(:open).once.with(File.join(dir3, p2_filename), mode).and_yield(file)
|
94
|
-
expect(file).to receive(:<<) do |yaml|
|
95
|
-
yaml = YAML.load(yaml)
|
96
|
-
expect(yaml["id"]).to eq(p2_id)
|
97
|
-
expect(yaml["name"]).to eq(p2_pretty)
|
98
|
-
expect(yaml["accepting_product"]).to eq(p1_id)
|
99
|
-
expect(yaml["accepting_product_version"]).to eq(version)
|
100
|
-
end
|
101
|
-
expect(acc.persist(product_relationship, [p2])).to eq([])
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
describe "when the folder cannot be created" do
|
107
|
-
let(:err) { StandardError.new("foo") }
|
108
|
-
it "returns the error" do
|
109
|
-
expect(Dir).to receive(:exist?).with(dir3).and_return(false)
|
110
|
-
expect(FileUtils).to receive(:mkdir_p).and_raise(err)
|
111
|
-
expect(File).to_not receive(:open)
|
112
|
-
expect(acc.persist(product_relationship, [p1])).to eq([err])
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
describe "when the file cannot be written" do
|
117
|
-
let(:err) { StandardError.new("bar") }
|
118
|
-
it "returns the error" do
|
119
|
-
expect(Dir).to receive(:exist?).with(dir3).and_return(true)
|
120
|
-
expect(File).to receive(:open).with(File.join(dir3, p1_filename), mode).and_raise(err)
|
121
|
-
expect(acc.persist(product_relationship, [p1])).to eq([err])
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
end
|
127
|
-
end
|
@@ -1,100 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "license_acceptance/strategy/prompt"
|
3
|
-
require "license_acceptance/product"
|
4
|
-
require "tty-prompt"
|
5
|
-
|
6
|
-
RSpec.describe LicenseAcceptance::Strategy::Prompt do
|
7
|
-
let(:output) { StringIO.new }
|
8
|
-
let(:config) do
|
9
|
-
instance_double(LicenseAcceptance::Config, output: output)
|
10
|
-
end
|
11
|
-
let(:acc) { LicenseAcceptance::Strategy::Prompt.new(config) }
|
12
|
-
let(:prompt) { instance_double(TTY::Prompt) }
|
13
|
-
let(:p1) { instance_double(LicenseAcceptance::Product, id: "foo", pretty_name: "Pretty Name") }
|
14
|
-
let(:missing_licenses) { [p1] }
|
15
|
-
|
16
|
-
before do
|
17
|
-
expect(TTY::Prompt).to receive(:new).at_least(:once).and_return(prompt)
|
18
|
-
end
|
19
|
-
|
20
|
-
describe "when the user accepts" do
|
21
|
-
it "returns true" do
|
22
|
-
expect(prompt).to receive(:ask).and_return("yes")
|
23
|
-
msg1 = /License that need accepting:\n \* #{p1.pretty_name}/m
|
24
|
-
msg2 = /product license persisted\./
|
25
|
-
b = Proc.new { [] }
|
26
|
-
expect(acc.request(missing_licenses, &b)).to eq(true)
|
27
|
-
expect(output.string).to match(msg1)
|
28
|
-
expect(output.string).to match(msg2)
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "when there are multiple products" do
|
32
|
-
let(:p2) { instance_double(LicenseAcceptance::Product, id: "bar", pretty_name: "Other") }
|
33
|
-
let(:missing_licenses) { [p1, p2] }
|
34
|
-
it "returns true" do
|
35
|
-
expect(prompt).to receive(:ask).and_return("yes")
|
36
|
-
msg1 = /Licenses that need accepting:\n \* #{p1.pretty_name}\n \* #{p2.pretty_name}/m
|
37
|
-
msg2 = /product licenses persisted\./
|
38
|
-
msg3 = /2 product licenses\nmust be accepted/m
|
39
|
-
b = Proc.new { [] }
|
40
|
-
expect(acc.request(missing_licenses, &b)).to eq(true)
|
41
|
-
expect(output.string).to match(msg1)
|
42
|
-
expect(output.string).to match(msg2)
|
43
|
-
expect(output.string).to match(msg3)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "when the callback returns an error" do
|
48
|
-
it "returns true" do
|
49
|
-
expect(prompt).to receive(:ask).and_return("yes")
|
50
|
-
msg1 = /License that need accepting:\n \* #{p1.pretty_name}/m
|
51
|
-
msg2 = /Could not persist acceptance:/
|
52
|
-
b = Proc.new { [StandardError.new("foo")] }
|
53
|
-
expect(acc.request(missing_licenses, &b)).to eq(true)
|
54
|
-
expect(output.string).to match(msg1)
|
55
|
-
expect(output.string).to match(msg2)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe "when the prompt times out" do
|
61
|
-
it "returns false" do
|
62
|
-
expect(Timeout).to receive(:timeout).twice.and_yield
|
63
|
-
expect(prompt).to receive(:ask).twice.and_raise(LicenseAcceptance::Strategy::PromptTimeout)
|
64
|
-
expect(prompt).to receive(:unsubscribe).twice
|
65
|
-
expect(prompt).to receive(:reader).twice
|
66
|
-
msg1 = /Prompt timed out./
|
67
|
-
b = Proc.new { [] }
|
68
|
-
expect(acc.request(missing_licenses, &b)).to eq(false)
|
69
|
-
expect(output.string).to match(msg1)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
describe "when the user declines twice" do
|
74
|
-
it "returns false" do
|
75
|
-
expect(prompt).to receive(:ask).twice.and_return("no")
|
76
|
-
msg1 = /License that need accepting:\n \* #{p1.pretty_name}/m
|
77
|
-
msg2 = /product license persisted\./
|
78
|
-
b = Proc.new { raise "should not be called" }
|
79
|
-
expect(acc.request(missing_licenses, &b)).to eq(false)
|
80
|
-
expect(output.string).to match(msg1)
|
81
|
-
expect(output.string).to_not match(msg2)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
describe "when the user declines once then accepts" do
|
86
|
-
it "returns true" do
|
87
|
-
expect(prompt).to receive(:ask).and_return("no")
|
88
|
-
expect(prompt).to receive(:ask).and_return("yes")
|
89
|
-
msg1 = /License that need accepting:\n \* #{p1.pretty_name}/m
|
90
|
-
msg2 = /product license persisted\./
|
91
|
-
msg3 = /If you do not accept this license you will\nnot be able to use Chef products/m
|
92
|
-
b = Proc.new { [] }
|
93
|
-
expect(acc.request(missing_licenses, &b)).to eq(true)
|
94
|
-
expect(output.string).to match(msg1)
|
95
|
-
expect(output.string).to match(msg2)
|
96
|
-
expect(output.string).to match(msg3)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "license_acceptance/strategy/provided_value"
|
3
|
-
|
4
|
-
RSpec.describe LicenseAcceptance::Strategy::ProvidedValue do
|
5
|
-
let(:acc) { LicenseAcceptance::Strategy::ProvidedValue.new(value) }
|
6
|
-
|
7
|
-
describe "#accepted?" do
|
8
|
-
describe "when the value is correct" do
|
9
|
-
let(:value) { "accept" }
|
10
|
-
it "returns true" do
|
11
|
-
expect(acc.accepted?).to eq(true)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "when the value is incorrect" do
|
16
|
-
let(:value) { nil }
|
17
|
-
it "returns false" do
|
18
|
-
expect(acc.accepted?).to eq(false)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "#silent?" do
|
24
|
-
describe "when the value is correct" do
|
25
|
-
let(:value) { "accept-silent" }
|
26
|
-
it "returns true" do
|
27
|
-
expect(acc.silent?).to eq(true)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "when the value is incorrect" do
|
32
|
-
let(:value) { "accept" }
|
33
|
-
it "returns false" do
|
34
|
-
expect(acc.silent?).to eq(false)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe "#no_persist?" do
|
40
|
-
describe "when the value is correct" do
|
41
|
-
let(:value) { "accept-no-persist" }
|
42
|
-
it "returns true" do
|
43
|
-
expect(acc.no_persist?).to eq(true)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "when the value is incorrect" do
|
48
|
-
let(:value) { "accept-silent" }
|
49
|
-
it "returns false" do
|
50
|
-
expect(acc.no_persist?).to eq(false)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require "bundler/setup"
|
2
|
-
require "license_acceptance/logger"
|
3
|
-
require "logger"
|
4
|
-
|
5
|
-
RSpec.configure do |config|
|
6
|
-
# Enable flags like --only-failures and --next-failure
|
7
|
-
config.example_status_persistence_file_path = ".rspec_status"
|
8
|
-
|
9
|
-
# Disable RSpec exposing methods globally on `Module` and `main`
|
10
|
-
config.disable_monkey_patching!
|
11
|
-
|
12
|
-
config.filter_run :focus => true
|
13
|
-
config.run_all_when_everything_filtered = true
|
14
|
-
config.mock_with :rspec do |mocks|
|
15
|
-
mocks.verify_partial_doubles = true
|
16
|
-
end
|
17
|
-
|
18
|
-
config.expect_with :rspec do |c|
|
19
|
-
c.syntax = :expect
|
20
|
-
end
|
21
|
-
|
22
|
-
config.before(:all) do
|
23
|
-
LicenseAcceptance::Logger.initialize(::Logger.new(IO::NULL))
|
24
|
-
end
|
25
|
-
end
|