linux_admin 0.9.1 → 0.9.2
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 +7 -0
- data/README.md +6 -8
- data/lib/linux_admin/distro.rb +2 -2
- data/lib/linux_admin/etc_issue.rb +1 -1
- data/lib/linux_admin/fstab.rb +0 -1
- data/lib/linux_admin/logical_volume.rb +6 -8
- data/lib/linux_admin/registration_system/rhn.rb +2 -2
- data/lib/linux_admin/registration_system/subscription_manager.rb +1 -1
- data/lib/linux_admin/version.rb +1 -1
- data/lib/linux_admin/volume.rb +3 -3
- data/lib/linux_admin/yum.rb +8 -3
- data/spec/common_spec.rb +2 -4
- data/spec/deb_spec.rb +7 -9
- data/spec/disk_spec.rb +61 -63
- data/spec/distro_spec.rb +2 -4
- data/spec/etc_issue_spec.rb +1 -2
- data/spec/fstab_spec.rb +23 -24
- data/spec/hosts_spec.rb +3 -5
- data/spec/logical_volume_spec.rb +42 -44
- data/spec/mountable_spec.rb +28 -30
- data/spec/partition_spec.rb +5 -7
- data/spec/physical_volume_spec.rb +25 -27
- data/spec/registration_system_spec.rb +8 -10
- data/spec/rhn_spec.rb +17 -19
- data/spec/rpm_spec.rb +17 -19
- data/spec/service_spec.rb +23 -25
- data/spec/spec_helper.rb +68 -14
- data/spec/subscription_manager_spec.rb +21 -23
- data/spec/system_spec.rb +2 -4
- data/spec/volume_group_spec.rb +18 -20
- data/spec/yum_spec.rb +27 -23
- metadata +19 -45
- data/spec/linux_admin_spec.rb +0 -4
data/spec/spec_helper.rb
CHANGED
@@ -1,31 +1,82 @@
|
|
1
1
|
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
2
|
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
-
#
|
4
|
-
# loaded
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
4
|
+
# file to always be loaded, without a need to explicitly require it in any files.
|
5
|
+
#
|
6
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
7
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
8
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
9
|
+
# individual file that may not need all of that loaded. Instead, make a
|
10
|
+
# separate helper file that requires this one and then use it only in the specs
|
11
|
+
# that actually need it.
|
12
|
+
#
|
13
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
14
|
+
# users commonly want.
|
5
15
|
#
|
6
16
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
17
|
RSpec.configure do |config|
|
8
|
-
|
18
|
+
# The settings below are suggested to provide a good initial experience
|
19
|
+
# with RSpec, but feel free to customize to your heart's content.
|
20
|
+
|
21
|
+
# These two settings work together to allow you to limit a spec run
|
22
|
+
# to individual examples or groups you care about by tagging them with
|
23
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
24
|
+
# get run.
|
25
|
+
config.filter_run :focus
|
9
26
|
config.run_all_when_everything_filtered = true
|
10
|
-
|
27
|
+
|
28
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
29
|
+
# file, and it's useful to allow more verbose output when running an
|
30
|
+
# individual spec file.
|
31
|
+
if config.files_to_run.one?
|
32
|
+
# Use the documentation formatter for detailed output,
|
33
|
+
# unless a formatter has already been configured
|
34
|
+
# (e.g. via a command-line flag).
|
35
|
+
config.default_formatter = 'doc'
|
36
|
+
end
|
37
|
+
|
38
|
+
# Print the 10 slowest examples and example groups at the
|
39
|
+
# end of the spec run, to help surface which specs are running
|
40
|
+
# particularly slow.
|
41
|
+
# config.profile_examples = 10
|
11
42
|
|
12
43
|
# Run specs in random order to surface order dependencies. If you find an
|
13
44
|
# order dependency and want to debug it, you can fix the order by providing
|
14
45
|
# the seed, which is printed after each run.
|
15
46
|
# --seed 1234
|
16
|
-
config.order =
|
47
|
+
config.order = :random
|
17
48
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
49
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
50
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
51
|
+
# test failures related to randomization by passing the same `--seed` value
|
52
|
+
# as the one that triggered the failure.
|
53
|
+
Kernel.srand config.seed
|
54
|
+
|
55
|
+
# rspec-expectations config goes here. You can use an alternate
|
56
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
57
|
+
# assertions if you prefer.
|
58
|
+
config.expect_with :rspec do |expectations|
|
59
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
60
|
+
# For more details, see:
|
61
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
62
|
+
expectations.syntax = :expect
|
63
|
+
end
|
64
|
+
|
65
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
66
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
67
|
+
config.mock_with :rspec do |mocks|
|
68
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
69
|
+
# For more details, see:
|
70
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
71
|
+
mocks.syntax = :expect
|
72
|
+
|
73
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
74
|
+
# a real object. This is generally recommended.
|
75
|
+
mocks.verify_partial_doubles = true
|
22
76
|
end
|
23
77
|
|
24
78
|
config.after do
|
25
79
|
clear_caches
|
26
|
-
|
27
|
-
# reset the distro, tested in various placed & used extensively
|
28
|
-
LinuxAdmin::Distros.instance_variable_set(:@local, nil)
|
29
80
|
end
|
30
81
|
end
|
31
82
|
|
@@ -39,13 +90,13 @@ require 'linux_admin'
|
|
39
90
|
|
40
91
|
def etc_issue_contains(contents)
|
41
92
|
LinuxAdmin::EtcIssue.instance.send(:refresh)
|
42
|
-
allow(File).to receive(:
|
93
|
+
allow(File).to receive(:exist?).with('/etc/issue').at_least(:once).and_return(true)
|
43
94
|
allow(File).to receive(:read).with('/etc/issue').at_least(:once).and_return(contents)
|
44
95
|
end
|
45
96
|
|
46
97
|
def stub_distro(distro = LinuxAdmin::Distros.rhel)
|
47
98
|
# simply alias test distro to redhat distro for time being
|
48
|
-
LinuxAdmin::Distros.
|
99
|
+
allow(LinuxAdmin::Distros).to receive_messages(:local => distro)
|
49
100
|
end
|
50
101
|
|
51
102
|
def data_file_path(to)
|
@@ -58,4 +109,7 @@ end
|
|
58
109
|
|
59
110
|
def clear_caches
|
60
111
|
LinuxAdmin::RegistrationSystem.instance_variable_set(:@registration_type, nil)
|
112
|
+
|
113
|
+
# reset the distro, tested in various placed & used extensively
|
114
|
+
LinuxAdmin::Distros.instance_variable_set(:@local, nil)
|
61
115
|
end
|
@@ -1,20 +1,18 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
describe LinuxAdmin::SubscriptionManager do
|
4
2
|
context "#registered?" do
|
5
3
|
it "system with subscription-manager commands" do
|
6
|
-
described_class.
|
7
|
-
expect(described_class.new.registered?).to
|
4
|
+
expect_any_instance_of(described_class).to receive(:run).once.with("subscription-manager identity").and_return(double(:exit_status => 0))
|
5
|
+
expect(described_class.new.registered?).to be_truthy
|
8
6
|
end
|
9
7
|
|
10
8
|
it "system without subscription-manager commands" do
|
11
|
-
described_class.
|
12
|
-
expect(described_class.new.registered?).to
|
9
|
+
expect_any_instance_of(described_class).to receive(:run).once.with("subscription-manager identity").and_return(double(:exit_status => 255))
|
10
|
+
expect(described_class.new.registered?).to be_falsey
|
13
11
|
end
|
14
12
|
end
|
15
13
|
|
16
14
|
it "#refresh" do
|
17
|
-
described_class.
|
15
|
+
expect_any_instance_of(described_class).to receive(:run!).once.with("subscription-manager refresh")
|
18
16
|
described_class.new.refresh
|
19
17
|
end
|
20
18
|
|
@@ -39,15 +37,15 @@ describe LinuxAdmin::SubscriptionManager do
|
|
39
37
|
run_params.store_path(:params, "--serverurl=", "https://server.url")
|
40
38
|
base_options.store_path(:server_url, "https://server.url")
|
41
39
|
|
42
|
-
described_class.
|
43
|
-
LinuxAdmin::Rpm.
|
40
|
+
expect_any_instance_of(described_class).to receive(:run!).once.with("subscription-manager register", run_params)
|
41
|
+
expect(LinuxAdmin::Rpm).to receive(:upgrade).with("http://server.url/pub/katello-ca-consumer-latest.noarch.rpm")
|
44
42
|
|
45
43
|
described_class.new.register(base_options)
|
46
44
|
end
|
47
45
|
|
48
46
|
it "without server_url" do
|
49
|
-
described_class.
|
50
|
-
described_class.
|
47
|
+
expect_any_instance_of(described_class).to receive(:run!).once.with("subscription-manager register", run_params)
|
48
|
+
expect_any_instance_of(described_class).not_to receive(:install_server_certificate)
|
51
49
|
|
52
50
|
described_class.new.register(base_options)
|
53
51
|
end
|
@@ -56,30 +54,30 @@ describe LinuxAdmin::SubscriptionManager do
|
|
56
54
|
|
57
55
|
context "#subscribe" do
|
58
56
|
it "with pools" do
|
59
|
-
described_class.
|
57
|
+
expect_any_instance_of(described_class).to receive(:run!).once.with("subscription-manager attach", {:params=>[["--pool", 123], ["--pool", 456]]})
|
60
58
|
described_class.new.subscribe({:pools => [123, 456]})
|
61
59
|
end
|
62
60
|
|
63
61
|
it "without pools" do
|
64
|
-
described_class.
|
62
|
+
expect_any_instance_of(described_class).to receive(:run!).once.with("subscription-manager attach", {:params=>{"--auto"=>nil}})
|
65
63
|
described_class.new.subscribe({})
|
66
64
|
end
|
67
65
|
end
|
68
66
|
|
69
67
|
context "#subscribed_products" do
|
70
68
|
it "subscribed" do
|
71
|
-
described_class.
|
69
|
+
expect_any_instance_of(described_class).to receive(:run!).once.with("subscription-manager list --installed").and_return(double(:output => sample_output("subscription_manager/output_list_installed_subscribed")))
|
72
70
|
expect(described_class.new.subscribed_products).to eq(["69", "167"])
|
73
71
|
end
|
74
72
|
|
75
73
|
it "not subscribed" do
|
76
|
-
described_class.
|
74
|
+
expect_any_instance_of(described_class).to receive(:run!).once.with("subscription-manager list --installed").and_return(double(:output => sample_output("subscription_manager/output_list_installed_not_subscribed")))
|
77
75
|
expect(described_class.new.subscribed_products).to eq(["167"])
|
78
76
|
end
|
79
77
|
end
|
80
78
|
|
81
79
|
it "#available_subscriptions" do
|
82
|
-
described_class.
|
80
|
+
expect_any_instance_of(described_class).to receive(:run!).once.with("subscription-manager list --all --available").and_return(double(:output => sample_output("subscription_manager/output_list_all_available")))
|
83
81
|
expect(described_class.new.available_subscriptions).to eq({
|
84
82
|
"82c042fca983889b10178893f29b06e3" => {
|
85
83
|
:subscription_name => "Example Subscription",
|
@@ -132,8 +130,8 @@ describe LinuxAdmin::SubscriptionManager do
|
|
132
130
|
it "with valid credentials" do
|
133
131
|
run_options = ["subscription-manager orgs", {:params=>{"--username="=>"SomeUser", "--password="=>"SomePass", "--proxy="=>"1.2.3.4", "--proxyuser="=>"ProxyUser", "--proxypassword="=>"ProxyPass", "--serverurl="=>"192.168.1.1"}}]
|
134
132
|
|
135
|
-
LinuxAdmin::Rpm.
|
136
|
-
described_class.
|
133
|
+
expect(LinuxAdmin::Rpm).to receive(:upgrade).with("http://192.168.1.1/pub/katello-ca-consumer-latest.noarch.rpm")
|
134
|
+
expect_any_instance_of(described_class).to receive(:run!).once.with(*run_options).and_return(double(:output => sample_output("subscription_manager/output_orgs")))
|
137
135
|
|
138
136
|
expect(described_class.new.organizations({:username=>"SomeUser", :password=>"SomePass", :proxy_address=>"1.2.3.4", :proxy_username=>"ProxyUser", :proxy_password=>"ProxyPass", :server_url=>"192.168.1.1"})).to eq({"SomeOrg"=>{:name=>"SomeOrg", :key=>"1234567"}})
|
139
137
|
end
|
@@ -146,19 +144,19 @@ describe LinuxAdmin::SubscriptionManager do
|
|
146
144
|
:exit_status => 255
|
147
145
|
)
|
148
146
|
)
|
149
|
-
AwesomeSpawn.
|
147
|
+
expect(AwesomeSpawn).to receive(:run!).once.with(*run_options).and_raise(error)
|
150
148
|
expect { described_class.new.organizations({:username=>"BadUser", :password=>"BadPass"}) }.to raise_error(LinuxAdmin::CredentialError)
|
151
149
|
end
|
152
150
|
end
|
153
151
|
|
154
152
|
it "#enable_repo" do
|
155
|
-
described_class.
|
153
|
+
expect_any_instance_of(described_class).to receive(:run!).once.with("subscription-manager repos", {:params=>{"--enable="=>"abc"}})
|
156
154
|
|
157
155
|
described_class.new.enable_repo("abc")
|
158
156
|
end
|
159
157
|
|
160
158
|
it "#disable_repo" do
|
161
|
-
described_class.
|
159
|
+
expect_any_instance_of(described_class).to receive(:run!).once.with("subscription-manager repos", {:params=>{"--disable="=>"abc"}})
|
162
160
|
|
163
161
|
described_class.new.disable_repo("abc")
|
164
162
|
end
|
@@ -185,7 +183,7 @@ describe LinuxAdmin::SubscriptionManager do
|
|
185
183
|
}
|
186
184
|
]
|
187
185
|
|
188
|
-
described_class.
|
186
|
+
expect_any_instance_of(described_class).to receive(:run!).once.with("subscription-manager repos").and_return(double(:output => sample_output("subscription_manager/output_repos")))
|
189
187
|
|
190
188
|
expect(described_class.new.all_repos).to eq(expected)
|
191
189
|
end
|
@@ -193,7 +191,7 @@ describe LinuxAdmin::SubscriptionManager do
|
|
193
191
|
it "#enabled_repos" do
|
194
192
|
expected = ["some-repo-source-rpms", "some-repo-rpms"]
|
195
193
|
|
196
|
-
described_class.
|
194
|
+
expect_any_instance_of(described_class).to receive(:run!).once.with("subscription-manager repos").and_return(double(:output => sample_output("subscription_manager/output_repos")))
|
197
195
|
|
198
196
|
expect(described_class.new.enabled_repos).to eq(expected)
|
199
197
|
end
|
data/spec/system_spec.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
describe LinuxAdmin::System do
|
4
2
|
describe "#reboot!" do
|
5
3
|
it "reboots the system" do
|
6
|
-
LinuxAdmin::System.
|
4
|
+
expect(LinuxAdmin::System).to receive(:run!).
|
7
5
|
with(LinuxAdmin::System.cmd(:shutdown),
|
8
6
|
:params => { '-r' => 'now'})
|
9
7
|
LinuxAdmin::System.reboot!
|
@@ -12,7 +10,7 @@ describe LinuxAdmin::System do
|
|
12
10
|
|
13
11
|
describe "#shutdown!" do
|
14
12
|
it "shuts down the system" do
|
15
|
-
LinuxAdmin::System.
|
13
|
+
expect(LinuxAdmin::System).to receive(:run!).
|
16
14
|
with(LinuxAdmin::System.cmd(:shutdown),
|
17
15
|
:params => { '-h' => '0'})
|
18
16
|
LinuxAdmin::System.shutdown!
|
data/spec/volume_group_spec.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
describe LinuxAdmin::VolumeGroup do
|
4
2
|
before(:each) do
|
5
3
|
@groups = <<eos
|
@@ -18,7 +16,7 @@ eos
|
|
18
16
|
it "uses lvextend" do
|
19
17
|
vg = described_class.new :name => 'vg'
|
20
18
|
lv = LinuxAdmin::LogicalVolume.new :name => 'lv', :volume_group => vg
|
21
|
-
vg.
|
19
|
+
expect(vg).to receive(:run!).
|
22
20
|
with(vg.cmd(:lvextend),
|
23
21
|
:params => ['lv', 'vg'])
|
24
22
|
vg.attach_to(lv)
|
@@ -27,8 +25,8 @@ eos
|
|
27
25
|
it "returns self" do
|
28
26
|
vg = described_class.new :name => 'vg'
|
29
27
|
lv = LinuxAdmin::LogicalVolume.new :name => 'lv', :volume_group => vg
|
30
|
-
vg.
|
31
|
-
vg.attach_to(lv).
|
28
|
+
allow(vg).to receive(:run!)
|
29
|
+
expect(vg.attach_to(lv)).to eq(vg)
|
32
30
|
end
|
33
31
|
end
|
34
32
|
|
@@ -36,7 +34,7 @@ eos
|
|
36
34
|
it "uses vgextend" do
|
37
35
|
vg = described_class.new :name => 'vg'
|
38
36
|
pv = LinuxAdmin::PhysicalVolume.new :device_name => '/dev/hda'
|
39
|
-
vg.
|
37
|
+
expect(vg).to receive(:run!).
|
40
38
|
with(vg.cmd(:vgextend),
|
41
39
|
:params => ['vg', '/dev/hda'])
|
42
40
|
vg.extend_with(pv)
|
@@ -45,16 +43,16 @@ eos
|
|
45
43
|
it "assigns volume group to physical volume" do
|
46
44
|
vg = described_class.new :name => 'vg'
|
47
45
|
pv = LinuxAdmin::PhysicalVolume.new :device_name => '/dev/hda'
|
48
|
-
vg.
|
46
|
+
allow(vg).to receive(:run!)
|
49
47
|
vg.extend_with(pv)
|
50
|
-
pv.volume_group.
|
48
|
+
expect(pv.volume_group).to eq(vg)
|
51
49
|
end
|
52
50
|
|
53
51
|
it "returns self" do
|
54
52
|
vg = described_class.new :name => 'vg'
|
55
53
|
pv = LinuxAdmin::PhysicalVolume.new :device_name => '/dev/hda'
|
56
|
-
vg.
|
57
|
-
vg.extend_with(pv).
|
54
|
+
allow(vg).to receive(:run!)
|
55
|
+
expect(vg.extend_with(pv)).to eq(vg)
|
58
56
|
end
|
59
57
|
end
|
60
58
|
|
@@ -65,29 +63,29 @@ eos
|
|
65
63
|
|
66
64
|
it "uses vgcreate" do
|
67
65
|
described_class.instance_variable_set(:@vgs, [])
|
68
|
-
described_class.
|
66
|
+
expect(described_class).to receive(:run!).
|
69
67
|
with(LinuxAdmin.cmd(:vgcreate),
|
70
68
|
:params => ['vg', '/dev/hda'])
|
71
69
|
described_class.create 'vg', @pv
|
72
70
|
end
|
73
71
|
|
74
72
|
it "returns new volume group" do
|
75
|
-
described_class.
|
73
|
+
allow(described_class).to receive_messages(:run! => double(:output => ""))
|
76
74
|
vg = described_class.create 'vg', @pv
|
77
|
-
vg.
|
78
|
-
vg.name.
|
75
|
+
expect(vg).to be_an_instance_of(described_class)
|
76
|
+
expect(vg.name).to eq('vg')
|
79
77
|
end
|
80
78
|
|
81
79
|
it "adds volume group to local registry" do
|
82
|
-
described_class.
|
80
|
+
allow(described_class).to receive_messages(:run! => double(:output => ""))
|
83
81
|
vg = described_class.create 'vg', @pv
|
84
|
-
described_class.scan.
|
82
|
+
expect(described_class.scan).to include(vg)
|
85
83
|
end
|
86
84
|
end
|
87
85
|
|
88
86
|
describe "#scan" do
|
89
87
|
it "uses vgdisplay" do
|
90
|
-
described_class.
|
88
|
+
expect(described_class).to receive(:run!).
|
91
89
|
with(LinuxAdmin.cmd(:vgdisplay),
|
92
90
|
:params => { '-c' => nil}).
|
93
91
|
and_return(double(:output => @groups))
|
@@ -95,11 +93,11 @@ eos
|
|
95
93
|
end
|
96
94
|
|
97
95
|
it "returns local volume groups" do
|
98
|
-
described_class.
|
96
|
+
expect(described_class).to receive(:run!).and_return(double(:output => @groups))
|
99
97
|
vgs = described_class.scan
|
100
98
|
|
101
|
-
vgs[0].
|
102
|
-
vgs[0].name.
|
99
|
+
expect(vgs[0]).to be_an_instance_of(described_class)
|
100
|
+
expect(vgs[0].name).to eq('vg_foobar')
|
103
101
|
end
|
104
102
|
end
|
105
103
|
end
|
data/spec/yum_spec.rb
CHANGED
@@ -1,25 +1,23 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
describe LinuxAdmin::Yum do
|
4
2
|
before(:each) do
|
5
|
-
FileUtils.
|
3
|
+
allow(FileUtils).to receive_messages(:mkdir_p => true)
|
6
4
|
end
|
7
5
|
|
8
6
|
context ".create_repo" do
|
9
7
|
it "default arguments" do
|
10
|
-
described_class.
|
8
|
+
expect(described_class).to receive(:run!).once.with("createrepo", {:params=>{nil=>"some/path", "--database"=>nil, "--unique-md-filenames"=>nil}})
|
11
9
|
described_class.create_repo("some/path")
|
12
10
|
end
|
13
11
|
|
14
12
|
it "bare create" do
|
15
|
-
described_class.
|
13
|
+
expect(described_class).to receive(:run!).once.with("createrepo", {:params=>{nil=>"some/path"}})
|
16
14
|
described_class.create_repo("some/path", :database => false, :unique_file_names => false)
|
17
15
|
end
|
18
16
|
end
|
19
17
|
|
20
18
|
context ".download_packages" do
|
21
19
|
it "with valid input" do
|
22
|
-
described_class.
|
20
|
+
expect(described_class).to receive(:run!).once.with("repotrack", {:params=>{"-p"=>"some/path", nil=>"pkg_a pkg_b"}})
|
23
21
|
described_class.download_packages("some/path", "pkg_a pkg_b")
|
24
22
|
end
|
25
23
|
|
@@ -29,8 +27,8 @@ describe LinuxAdmin::Yum do
|
|
29
27
|
end
|
30
28
|
|
31
29
|
it ".repo_settings" do
|
32
|
-
described_class.
|
33
|
-
expect(described_class.repo_settings).to
|
30
|
+
expect(described_class).to receive(:parse_repo_dir).once.with("/etc/yum.repos.d").and_return(true)
|
31
|
+
expect(described_class.repo_settings).to be_truthy
|
34
32
|
end
|
35
33
|
|
36
34
|
it ".parse_repo_dir" do
|
@@ -68,41 +66,47 @@ describe LinuxAdmin::Yum do
|
|
68
66
|
|
69
67
|
context ".updates_available?" do
|
70
68
|
it "check updates for a specific package" do
|
71
|
-
described_class.
|
72
|
-
expect(described_class.updates_available?("abc")).to
|
69
|
+
expect(described_class).to receive(:run).once.with("yum check-update", {:params=>{nil=>["abc"]}}).and_return(double(:exit_status => 100))
|
70
|
+
expect(described_class.updates_available?("abc")).to be_truthy
|
73
71
|
end
|
74
72
|
|
75
73
|
it "updates are available" do
|
76
|
-
described_class.
|
77
|
-
expect(described_class.updates_available?).to
|
74
|
+
allow(described_class).to receive_messages(:run => double(:exit_status => 100))
|
75
|
+
expect(described_class.updates_available?).to be_truthy
|
78
76
|
end
|
79
77
|
|
80
78
|
it "updates not available" do
|
81
|
-
described_class.
|
82
|
-
expect(described_class.updates_available?).to
|
79
|
+
allow(described_class).to receive_messages(:run => double(:exit_status => 0))
|
80
|
+
expect(described_class.updates_available?).to be_falsey
|
83
81
|
end
|
84
82
|
|
85
83
|
it "other exit code" do
|
86
|
-
described_class.
|
84
|
+
allow(described_class).to receive_messages(:run => double(:exit_status => 255))
|
87
85
|
expect { described_class.updates_available? }.to raise_error
|
88
86
|
end
|
89
87
|
|
90
88
|
it "other error" do
|
91
|
-
described_class.
|
89
|
+
allow(described_class).to receive(:run).and_raise(RuntimeError)
|
92
90
|
expect { described_class.updates_available? }.to raise_error(RuntimeError)
|
93
91
|
end
|
94
92
|
end
|
95
93
|
|
96
94
|
context ".update" do
|
97
95
|
it "no arguments" do
|
98
|
-
described_class.
|
96
|
+
expect(described_class).to receive(:run!).once.with("yum -y update", :params => nil).and_return(AwesomeSpawn::CommandResult.new("", "", "", 0))
|
99
97
|
described_class.update
|
100
98
|
end
|
101
99
|
|
102
100
|
it "with arguments" do
|
103
|
-
described_class.
|
101
|
+
expect(described_class).to receive(:run!).once.with("yum -y update", :params => {nil => ["1 2", "3"]}).and_return(AwesomeSpawn::CommandResult.new("", "", "", 0))
|
104
102
|
described_class.update("1 2", "3")
|
105
103
|
end
|
104
|
+
|
105
|
+
it "with bad arguments" do
|
106
|
+
error = AwesomeSpawn::CommandResult.new("", "Loaded plugins: product-id\nNo Packages marked for Update\n", "Blah blah ...\nNo Match for argument: \n", 0)
|
107
|
+
expect(described_class).to receive(:run!).once.with("yum -y update", :params => {nil => [""]}).and_return(error)
|
108
|
+
expect { described_class.update("") }.to raise_error(AwesomeSpawn::CommandResultError)
|
109
|
+
end
|
106
110
|
end
|
107
111
|
|
108
112
|
context ".version_available" do
|
@@ -111,12 +115,12 @@ describe LinuxAdmin::Yum do
|
|
111
115
|
end
|
112
116
|
|
113
117
|
it "with one package" do
|
114
|
-
described_class.
|
118
|
+
expect(described_class).to receive(:run!).once.with("repoquery --qf=\"%{name} %{version}\"", {:params=>{nil=>["subscription-manager"]}}).and_return(double(:output => sample_output("yum/output_repoquery_single")))
|
115
119
|
expect(described_class.version_available("subscription-manager")).to eq({"subscription-manager" => "1.1.23.1"})
|
116
120
|
end
|
117
121
|
|
118
122
|
it "with multiple packages" do
|
119
|
-
described_class.
|
123
|
+
expect(described_class).to receive(:run!).once.with("repoquery --qf=\"%{name} %{version}\"", {:params=>{nil=>["curl", "subscription-manager", "wget"]}}).and_return(double(:output => sample_output("yum/output_repoquery_multiple")))
|
120
124
|
expect(described_class.version_available("curl", "subscription-manager", "wget")).to eq({
|
121
125
|
"curl" => "7.19.7",
|
122
126
|
"subscription-manager" => "1.1.23.1",
|
@@ -127,13 +131,13 @@ describe LinuxAdmin::Yum do
|
|
127
131
|
|
128
132
|
context ".repo_list" do
|
129
133
|
it "with no arguments" do
|
130
|
-
described_class.
|
134
|
+
expect(described_class).to receive(:run!).with("yum repolist", {:params=>{nil=>"enabled"}}).and_return(double(:output => sample_output("yum/output_repo_list")))
|
131
135
|
expect(described_class.repo_list).to eq(["rhel-6-server-rpms", "rhel-ha-for-rhel-6-server-rpms", "rhel-lb-for-rhel-6-server-rpms"])
|
132
136
|
end
|
133
137
|
|
134
138
|
it "with argument" do
|
135
|
-
described_class.
|
139
|
+
expect(described_class).to receive(:run!).with("yum repolist", {:params=>{nil=>"enabled"}}).and_return(double(:output => sample_output("yum/output_repo_list")))
|
136
140
|
expect(described_class.repo_list("enabled")).to eq(["rhel-6-server-rpms", "rhel-ha-for-rhel-6-server-rpms", "rhel-lb-for-rhel-6-server-rpms"])
|
137
141
|
end
|
138
142
|
end
|
139
|
-
end
|
143
|
+
end
|