boxgrinder-build 0.10.0 → 0.10.1
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.
- data/CHANGELOG +11 -0
- data/Manifest +6 -7
- data/Rakefile +11 -6
- data/bash_completion +37 -0
- data/bin/boxgrinder-build +20 -5
- data/boxgrinder-build.gemspec +4 -4
- data/lib/boxgrinder-build.rb +2 -1
- data/lib/boxgrinder-build/appliance.rb +26 -24
- data/lib/boxgrinder-build/helpers/augeas-helper.rb +1 -1
- data/lib/boxgrinder-build/helpers/ec2-helper.rb +2 -2
- data/lib/boxgrinder-build/helpers/guestfs-helper.rb +1 -1
- data/lib/boxgrinder-build/helpers/s3-helper.rb +2 -2
- data/lib/boxgrinder-build/managers/plugin-manager.rb +1 -1
- data/lib/boxgrinder-build/plugins/delivery/ebs/ebs-plugin.rb +1 -1
- data/lib/boxgrinder-build/plugins/delivery/elastichosts/elastichosts-plugin.rb +2 -2
- data/lib/boxgrinder-build/plugins/delivery/openstack/openstack-plugin.rb +3 -3
- data/lib/boxgrinder-build/plugins/delivery/s3/s3-plugin.rb +16 -10
- data/lib/boxgrinder-build/plugins/os/centos/centos-plugin.rb +1 -1
- data/lib/boxgrinder-build/plugins/os/fedora/fedora-plugin.rb +1 -1
- data/lib/boxgrinder-build/plugins/os/rhel/rhel-plugin.rb +1 -1
- data/lib/boxgrinder-build/plugins/os/rpm-based/kickstart.rb +5 -1
- data/lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb +8 -3
- data/lib/boxgrinder-build/plugins/os/rpm-based/rpm-dependency-validator.rb +1 -1
- data/lib/boxgrinder-build/plugins/os/sl/sl-plugin.rb +1 -1
- data/lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb +1 -1
- data/lib/boxgrinder-build/util/concurrent/get_set.rb +46 -0
- data/lib/boxgrinder-build/util/permissions/fs-monitor.rb +182 -0
- data/lib/boxgrinder-build/util/permissions/fs-observer.rb +82 -0
- data/lib/boxgrinder-build/util/permissions/user-switcher.rb +42 -0
- data/rubygem-boxgrinder-build.spec +25 -3
- data/spec/appliance-spec.rb +69 -82
- data/spec/helpers/augeas-helper-spec.rb +0 -2
- data/spec/helpers/guestfs-helper-spec.rb +1 -3
- data/spec/helpers/image-helper-spec.rb +0 -2
- data/spec/helpers/linux-helper-spec.rb +0 -2
- data/spec/helpers/package-helper-spec.rb +0 -2
- data/spec/helpers/plugin-helper-spec.rb +0 -2
- data/spec/helpers/s3-helper-spec.rb +0 -2
- data/spec/managers/plugin-manager-spec.rb +0 -2
- data/spec/plugins/base-plugin-spec.rb +0 -2
- data/spec/plugins/delivery/ebs/ebs-plugin-spec.rb +0 -2
- data/spec/plugins/delivery/elastichosts/elastichosts-plugin-spec.rb +3 -5
- data/spec/plugins/delivery/libvirt/libvirt-plugin-spec.rb +19 -17
- data/spec/plugins/delivery/local/local-plugin-spec.rb +0 -2
- data/spec/plugins/delivery/s3/s3-plugin-spec.rb +6 -8
- data/spec/plugins/delivery/sftp/sftp-plugin-spec.rb +0 -2
- data/spec/plugins/os/centos/centos-plugin-spec.rb +0 -2
- data/spec/plugins/os/fedora/fedora-plugin-spec.rb +0 -2
- data/spec/plugins/os/rhel/rhel-plugin-spec.rb +0 -2
- data/spec/plugins/os/rpm-based/kickstart-spec.rb +0 -2
- data/spec/plugins/os/rpm-based/rpm-based-os-plugin-spec.rb +16 -4
- data/spec/plugins/os/rpm-based/rpm-dependency-validator-spec.rb +0 -2
- data/spec/plugins/platform/ec2/ec2-plugin-spec.rb +0 -2
- data/spec/plugins/platform/virtualbox/virtualbox-plugin-spec.rb +1 -3
- data/spec/plugins/platform/virtualpc/virtualpc-plugin-spec.rb +0 -1
- data/spec/plugins/platform/vmware/vmware-plugin-spec.rb +25 -24
- data/spec/rcov_helper.rb +2 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/util/concurrent/get-set-spec.rb +43 -0
- data/spec/util/permissions/fs-monitor-spec.rb +233 -0
- data/spec/util/permissions/fs-observer-spec.rb +141 -0
- data/spec/util/permissions/user-switcher-spec.rb +69 -0
- metadata +20 -5
@@ -16,8 +16,6 @@
|
|
16
16
|
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
17
17
|
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
18
18
|
|
19
|
-
require 'rubygems'
|
20
|
-
require 'rspec'
|
21
19
|
require 'boxgrinder-build/plugins/delivery/local/local-plugin'
|
22
20
|
require 'hashery/opencascade'
|
23
21
|
|
@@ -16,8 +16,6 @@
|
|
16
16
|
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
17
17
|
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
18
18
|
|
19
|
-
require 'rubygems'
|
20
|
-
require 'rspec'
|
21
19
|
require 'boxgrinder-build/plugins/delivery/s3/s3-plugin'
|
22
20
|
require 'hashery/opencascade'
|
23
21
|
require 'boxgrinder-core/models/config'
|
@@ -109,10 +107,10 @@ module BoxGrinder
|
|
109
107
|
@key1.should_receive(:exists?).and_return(true)
|
110
108
|
@key2.should_receive(:exists?).and_return(false)
|
111
109
|
|
112
|
-
@s3helper.should_receive(:stub_s3obj).with(@bucket, 'name/fedora/14/1.0-
|
113
|
-
@s3helper.should_receive(:stub_s3obj).with(@bucket, 'name/fedora/14/1.0-
|
110
|
+
@s3helper.should_receive(:stub_s3obj).with(@bucket, 'name/fedora/14/1.0-snapshot-1/x86_64/').and_return(@key1)
|
111
|
+
@s3helper.should_receive(:stub_s3obj).with(@bucket, 'name/fedora/14/1.0-snapshot-2/x86_64/').and_return(@key2)
|
114
112
|
|
115
|
-
@plugin.ami_key("name", "/").should == "name/fedora/14/1.0-
|
113
|
+
@plugin.ami_key("name", "/").should == "name/fedora/14/1.0-snapshot-2/x86_64"
|
116
114
|
end
|
117
115
|
|
118
116
|
it "should return valid ami_key with snapshot and overwrite enabled" do
|
@@ -121,10 +119,10 @@ module BoxGrinder
|
|
121
119
|
@key1.should_receive(:exists?).and_return(true)
|
122
120
|
@key2.should_receive(:exists?).and_return(false)
|
123
121
|
|
124
|
-
@s3helper.should_receive(:stub_s3obj).with(@bucket, 'name/fedora/14/1.0-
|
125
|
-
@s3helper.should_receive(:stub_s3obj).with(@bucket, 'name/fedora/14/1.0-
|
122
|
+
@s3helper.should_receive(:stub_s3obj).with(@bucket, 'name/fedora/14/1.0-snapshot-1/x86_64/').and_return(@key1)
|
123
|
+
@s3helper.should_receive(:stub_s3obj).with(@bucket, 'name/fedora/14/1.0-snapshot-2/x86_64/').and_return(@key2)
|
126
124
|
|
127
|
-
@plugin.ami_key("name", "/").should == "name/fedora/14/1.0-
|
125
|
+
@plugin.ami_key("name", "/").should == "name/fedora/14/1.0-snapshot-1/x86_64"
|
128
126
|
end
|
129
127
|
end
|
130
128
|
|
@@ -16,8 +16,6 @@
|
|
16
16
|
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
17
17
|
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
18
18
|
|
19
|
-
require 'rubygems'
|
20
|
-
require 'rspec'
|
21
19
|
require 'boxgrinder-build/plugins/delivery/sftp/sftp-plugin'
|
22
20
|
|
23
21
|
module BoxGrinder
|
@@ -16,8 +16,6 @@
|
|
16
16
|
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
17
17
|
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
18
18
|
|
19
|
-
require 'rubygems'
|
20
|
-
require 'rspec'
|
21
19
|
require 'boxgrinder-build/plugins/os/centos/centos-plugin'
|
22
20
|
require 'hashery/opencascade'
|
23
21
|
|
@@ -16,8 +16,6 @@
|
|
16
16
|
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
17
17
|
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
18
18
|
|
19
|
-
require 'rubygems'
|
20
|
-
require 'rspec'
|
21
19
|
require 'boxgrinder-build/plugins/os/fedora/fedora-plugin'
|
22
20
|
require 'hashery/opencascade'
|
23
21
|
|
@@ -16,8 +16,6 @@
|
|
16
16
|
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
17
17
|
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
18
18
|
|
19
|
-
require 'rubygems'
|
20
|
-
require 'rspec'
|
21
19
|
require 'boxgrinder-build/plugins/os/rhel/rhel-plugin'
|
22
20
|
require 'hashery/opencascade'
|
23
21
|
|
@@ -16,8 +16,6 @@
|
|
16
16
|
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
17
17
|
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
18
18
|
|
19
|
-
require 'rubygems'
|
20
|
-
require 'rspec'
|
21
19
|
require 'boxgrinder-build/plugins/os/rpm-based/kickstart'
|
22
20
|
require 'hashery/opencascade'
|
23
21
|
|
@@ -16,8 +16,6 @@
|
|
16
16
|
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
17
17
|
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
18
18
|
|
19
|
-
require 'rubygems'
|
20
|
-
require 'rspec'
|
21
19
|
require 'boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin'
|
22
20
|
require 'hashery/opencascade'
|
23
21
|
|
@@ -51,6 +49,19 @@ module BoxGrinder
|
|
51
49
|
@log = @plugin.instance_variable_get(:@log)
|
52
50
|
end
|
53
51
|
|
52
|
+
it "should create the /etc/yum.repos.d directory if it does not exist" do
|
53
|
+
@appliance_config.stub!(:repos).and_return([
|
54
|
+
{'name' => 'cirras', 'baseurl' => "http://repo.boxgrinder.org/packages/fedora/11/RPMS/x86_64"}
|
55
|
+
])
|
56
|
+
|
57
|
+
guestfs = mock("guestfs").as_null_object
|
58
|
+
|
59
|
+
guestfs.stub!(:exists).and_return(0)
|
60
|
+
guestfs.should_receive(:mkdir_p).with("/etc/yum.repos.d/")
|
61
|
+
|
62
|
+
@plugin.install_repos(guestfs)
|
63
|
+
end
|
64
|
+
|
54
65
|
it "should install repos" do
|
55
66
|
@appliance_config.should_receive(:repos).and_return(
|
56
67
|
[
|
@@ -58,7 +69,8 @@ module BoxGrinder
|
|
58
69
|
{'name' => 'abc', 'baseurl' => 'http://abc', 'mirrorlist' => "http://abc.org/packages/fedora/11/RPMS/x86_64"},
|
59
70
|
])
|
60
71
|
|
61
|
-
guestfs = mock("guestfs")
|
72
|
+
guestfs = mock("guestfs").as_null_object
|
73
|
+
|
62
74
|
guestfs.should_receive(:write_file).with("/etc/yum.repos.d/cirras.repo", "[cirras]\nname=cirras\nenabled=1\ngpgcheck=0\nbaseurl=http://repo.boxgrinder.org/packages/fedora/11/RPMS/x86_64\n", 0)
|
63
75
|
guestfs.should_receive(:write_file).with("/etc/yum.repos.d/abc.repo", "[abc]\nname=abc\nenabled=1\ngpgcheck=0\nbaseurl=http://abc\nmirrorlist=http://abc.org/packages/fedora/11/RPMS/x86_64\n", 0)
|
64
76
|
|
@@ -72,7 +84,7 @@ module BoxGrinder
|
|
72
84
|
{'name' => 'cirras', 'baseurl' => "http://repo.boxgrinder.org/packages/fedora/11/RPMS/x86_64", 'ephemeral' => true}
|
73
85
|
])
|
74
86
|
|
75
|
-
guestfs = mock("guestfs")
|
87
|
+
guestfs = mock("guestfs").as_null_object
|
76
88
|
guestfs.should_receive(:write_file).with("/etc/yum.repos.d/abc.repo", "[abc]\nname=abc\nenabled=1\ngpgcheck=0\nbaseurl=http://abc\nmirrorlist=http://abc.org/packages/fedora/11/RPMS/x86_64\n", 0)
|
77
89
|
|
78
90
|
@plugin.install_repos(guestfs)
|
@@ -16,8 +16,6 @@
|
|
16
16
|
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
17
17
|
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
18
18
|
|
19
|
-
require 'rubygems'
|
20
|
-
require 'rspec'
|
21
19
|
require 'boxgrinder-build/plugins/os/rpm-based/rpm-dependency-validator'
|
22
20
|
require 'hashery/opencascade'
|
23
21
|
|
@@ -16,8 +16,6 @@
|
|
16
16
|
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
17
17
|
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
18
18
|
|
19
|
-
require 'rubygems'
|
20
|
-
require 'rspec'
|
21
19
|
require 'boxgrinder-build/plugins/platform/ec2/ec2-plugin'
|
22
20
|
require 'boxgrinder-core/helpers/log-helper'
|
23
21
|
require 'hashery/opencascade'
|
@@ -16,11 +16,9 @@
|
|
16
16
|
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
17
17
|
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
18
18
|
|
19
|
-
require 'rubygems'
|
20
|
-
require 'rspec'
|
21
19
|
require 'boxgrinder-build/plugins/platform/virtualbox/virtualbox-plugin'
|
22
20
|
require 'hashery/opencascade'
|
23
|
-
require '
|
21
|
+
require 'rspec-plugin-helper'
|
24
22
|
|
25
23
|
module BoxGrinder
|
26
24
|
describe VirtualBoxPlugin do
|
@@ -16,8 +16,6 @@
|
|
16
16
|
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
17
17
|
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
18
18
|
|
19
|
-
require 'rubygems'
|
20
|
-
require 'rspec'
|
21
19
|
require 'boxgrinder-build/plugins/platform/vmware/vmware-plugin'
|
22
20
|
require 'hashery/opencascade'
|
23
21
|
|
@@ -122,7 +120,7 @@ module BoxGrinder
|
|
122
120
|
|
123
121
|
vmdk_image = @plugin.change_vmdk_values("vmfs")
|
124
122
|
|
125
|
-
vmdk_image.
|
123
|
+
vmdk_image.match(/^createType="(.*)"\s?$/)[1].should == "vmfs"
|
126
124
|
|
127
125
|
disk_attributes = vmdk_image.scan(/^RW (.*) (.*) "(.*).raw" (.*)\s?$/)[0]
|
128
126
|
|
@@ -131,11 +129,11 @@ module BoxGrinder
|
|
131
129
|
disk_attributes[2].should == "full"
|
132
130
|
disk_attributes[3].should == ""
|
133
131
|
|
134
|
-
vmdk_image.
|
135
|
-
vmdk_image.
|
136
|
-
vmdk_image.
|
132
|
+
vmdk_image.match(/^ddb.geometry.cylinders = "(.*)"\s?$/)[1].should == "652"
|
133
|
+
vmdk_image.match(/^ddb.geometry.heads = "(.*)"\s?$/)[1].should == "255"
|
134
|
+
vmdk_image.match(/^ddb.geometry.sectors = "(.*)"\s?$/)[1].should == "63"
|
137
135
|
|
138
|
-
vmdk_image.
|
136
|
+
vmdk_image.match(/^ddb.virtualHWVersion = "(.*)"\s?$/)[1].should == "7"
|
139
137
|
end
|
140
138
|
|
141
139
|
it "should change vmdk data (flat)" do
|
@@ -145,7 +143,7 @@ module BoxGrinder
|
|
145
143
|
|
146
144
|
vmdk_image = @plugin.change_vmdk_values("monolithicFlat")
|
147
145
|
|
148
|
-
vmdk_image.
|
146
|
+
vmdk_image.match(/^createType="(.*)"\s?$/)[1].should == "monolithicFlat"
|
149
147
|
|
150
148
|
disk_attributes = vmdk_image.scan(/^RW (.*) (.*) "(.*).raw" (.*)\s?$/)[0]
|
151
149
|
|
@@ -154,12 +152,12 @@ module BoxGrinder
|
|
154
152
|
disk_attributes[2].should == "full"
|
155
153
|
disk_attributes[3].should == "0"
|
156
154
|
|
157
|
-
vmdk_image.
|
158
|
-
vmdk_image.
|
159
|
-
vmdk_image.
|
155
|
+
vmdk_image.match(/^ddb.geometry.cylinders = "(.*)"\s?$/)[1].should == "652"
|
156
|
+
vmdk_image.match(/^ddb.geometry.heads = "(.*)"\s?$/)[1].should == "255"
|
157
|
+
vmdk_image.match(/^ddb.geometry.sectors = "(.*)"\s?$/)[1].should == "63"
|
160
158
|
|
161
|
-
vmdk_image.
|
162
|
-
vmdk_image.
|
159
|
+
vmdk_image.match(/^ddb.virtualHWVersion = "(.*)"\s?$/)[1].should == "7"
|
160
|
+
vmdk_image.match(/^ddb.thinProvisioned = "(.*)"\s?$/)[1].should == "0"
|
163
161
|
end
|
164
162
|
|
165
163
|
it "should change vmdk data (flat) enabling thin disk" do
|
@@ -169,7 +167,7 @@ module BoxGrinder
|
|
169
167
|
|
170
168
|
vmdk_image = @plugin.change_vmdk_values("monolithicFlat")
|
171
169
|
|
172
|
-
vmdk_image.
|
170
|
+
vmdk_image.match(/^ddb.thinProvisioned = "(.*)"\s?$/)[1].should == "1"
|
173
171
|
end
|
174
172
|
end
|
175
173
|
|
@@ -177,16 +175,19 @@ module BoxGrinder
|
|
177
175
|
prepare_image({'thin_disk' => false, 'type' => 'enterprise'})
|
178
176
|
|
179
177
|
vmx_file = @plugin.change_common_vmx_values
|
180
|
-
|
181
|
-
vmx_file.
|
182
|
-
vmx_file.
|
183
|
-
|
184
|
-
vmx_file.
|
185
|
-
|
186
|
-
|
187
|
-
vmx_file.
|
188
|
-
vmx_file.
|
189
|
-
vmx_file.
|
178
|
+
|
179
|
+
vmx_file.match(/^guestOS = "(.*)"\s?$/)[1].should == "linux"
|
180
|
+
vmx_file.match(/^displayName = "(.*)"\s?$/)[1].should == "full"
|
181
|
+
|
182
|
+
vmx_file.match(/^annotation = "(.*)"\s?$/)[1].
|
183
|
+
match(/^full | Version: 1\.0 | Built by: BoxGrinder 1\.0\.0/).should_not == nil
|
184
|
+
|
185
|
+
vmx_file.match(/^guestinfo.vmware.product.long = "(.*)"\s?$/)[1].should == "full"
|
186
|
+
vmx_file.match(/^guestinfo.vmware.product.url = "(.*)"\s?$/)[1].should == "http://boxgrinder.org"
|
187
|
+
vmx_file.match(/^numvcpus = "(.*)"\s?$/)[1].should == "1"
|
188
|
+
vmx_file.match(/^memsize = "(.*)"\s?$/)[1].should == "256"
|
189
|
+
vmx_file.match(/^log.fileName = "(.*)"\s?$/)[1].should == "full.log"
|
190
|
+
vmx_file.match(/^scsi0:0.fileName = "(.*)"\s?$/)[1].should == "full.vmdk"
|
190
191
|
end
|
191
192
|
|
192
193
|
describe ".build_vmware_personal" do
|
data/spec/rcov_helper.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require "rspec"
|
2
|
+
|
3
|
+
require 'boxgrinder-build/util/concurrent/get_set'
|
4
|
+
|
5
|
+
describe GetSet do
|
6
|
+
subject{ GetSet.new }
|
7
|
+
its(:get_set){ should be_false }
|
8
|
+
|
9
|
+
context "#initialize" do
|
10
|
+
it "should have a value of true with default init" do
|
11
|
+
GetSet.new.get_set.should be_false
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should have an arbitrary value after setting initial_state" do
|
15
|
+
GetSet.new(:boxgrinder).get_set.should equal(:boxgrinder)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "#get_set" do
|
20
|
+
context "without block" do
|
21
|
+
it "should return the existing value when none is set" do
|
22
|
+
subject.get_set(:some_value)
|
23
|
+
subject.get_set.should equal(:some_value)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should return the set non-nil value when explicitly provided" do
|
27
|
+
subject.get_set(:boxgrinder).should equal(:boxgrinder)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "with block" do
|
32
|
+
it "yield existing the value and set block return as the new value" do
|
33
|
+
expect{ subject.get_set(:blah){|v| :boo} }.
|
34
|
+
to change(subject, :get_set).from(false).to(:boo)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "parameter should be ignored" do
|
38
|
+
expect{ subject.get_set(:blah){|v| v} }.
|
39
|
+
not_to change(subject, :get_set)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,233 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2012 Red Hat, Inc.
|
3
|
+
#
|
4
|
+
# This is free software; you can redistribute it and/or modify it
|
5
|
+
# under the terms of the GNU Lesser General Public License as
|
6
|
+
# published by the Free Software Foundation; either version 3 of
|
7
|
+
# the License, or (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This software is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
+
# Lesser General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU Lesser General Public
|
15
|
+
# License along with this software; if not, write to the Free
|
16
|
+
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
17
|
+
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
18
|
+
|
19
|
+
require 'boxgrinder-build/util/permissions/fs-monitor'
|
20
|
+
|
21
|
+
module BoxGrinder
|
22
|
+
describe FSMonitor do
|
23
|
+
|
24
|
+
before(:each) do
|
25
|
+
# Singleton
|
26
|
+
@fs_monitor = FSMonitor.instance
|
27
|
+
end
|
28
|
+
|
29
|
+
after(:each) do
|
30
|
+
# Reset the singleton to avoid tests being serial
|
31
|
+
@fs_monitor.reset
|
32
|
+
end
|
33
|
+
|
34
|
+
subject{ @fs_monitor }
|
35
|
+
|
36
|
+
let(:observer){ mock('FSObserver-mock-1', :respond_to? => true) }
|
37
|
+
let(:observer_2){ mock('FSObserver-mock-2', :respond_to? => true) }
|
38
|
+
|
39
|
+
context "after singleton #initialize" do
|
40
|
+
its(:reset){ should be_nil }
|
41
|
+
its(:stop){ should be_false }
|
42
|
+
its(:trigger){ should be_false }
|
43
|
+
|
44
|
+
it "should insert wrappers for File{#open, #new, #rename, #symlink, #link},
|
45
|
+
Dir#mkdir." do
|
46
|
+
File.should respond_to(:__alias_open, :__alias_new, :__alias_rename,
|
47
|
+
:__alias_symlink, :__alias_link)
|
48
|
+
File.should respond_to(:open, :new, :rename, :symlink, :link)
|
49
|
+
Dir.should respond_to(:__alias_mkdir)
|
50
|
+
Dir.should respond_to(:mkdir)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "#capture" do
|
55
|
+
let(:mock_return){ mock('mock_return_value') }
|
56
|
+
let(:dumb_observer){ mock('dumb_observer').as_null_object }
|
57
|
+
let(:dumb_observer_2){ mock('dumb_observer_2').as_null_object }
|
58
|
+
|
59
|
+
before(:each) do
|
60
|
+
# Just reflect the path back so we can differentiate the paths
|
61
|
+
subject.stub(:realpath){ |reflect| reflect }
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should add observers to its observer set" do
|
65
|
+
expect {
|
66
|
+
subject.capture(dumb_observer, dumb_observer_2){}
|
67
|
+
}.to change(subject, :count_observers).
|
68
|
+
from(0).to(2)
|
69
|
+
end
|
70
|
+
|
71
|
+
def basic_capture_test_setup(klazz=File, meth_s=:open, &blk)
|
72
|
+
klazz.stub("__alias_#{meth_s}").and_return(mock_return)
|
73
|
+
|
74
|
+
observer.should_receive(:update).twice.ordered.
|
75
|
+
with({ :command => :stop_capture })
|
76
|
+
|
77
|
+
blk.call(observer)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should not capture outside of #capture block{}" do
|
81
|
+
basic_capture_test_setup do |observer|
|
82
|
+
# Ignore unscoped operations
|
83
|
+
observer.should_receive(:update).once.
|
84
|
+
with({ :data => '/a/y/r/s', :command => :add_path })
|
85
|
+
|
86
|
+
File.open('/m/a/s', 'w+')
|
87
|
+
|
88
|
+
subject.capture(observer) do
|
89
|
+
File.open('/a/y/r/s', 'a')
|
90
|
+
end
|
91
|
+
|
92
|
+
File.open('/c/y/s', 'w')
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should capture with manual #start, #stop delimiters" do
|
97
|
+
basic_capture_test_setup do |observer|
|
98
|
+
observer.should_receive(:update).once.
|
99
|
+
with({ :data => '/m/a/w', :command => :add_path })
|
100
|
+
|
101
|
+
File.open('no-capture', 'w+')
|
102
|
+
|
103
|
+
# Note: without block, hence no auto-stop
|
104
|
+
subject.capture(observer)
|
105
|
+
File.open('/m/a/w', 'a')
|
106
|
+
subject.stop
|
107
|
+
|
108
|
+
File.open('capture-no', 'w')
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def wrapper_spec_builder(klazz, method, pnum, include, exclude=[], &blk)
|
113
|
+
basic_capture_test_setup(klazz, method) do |observer|
|
114
|
+
|
115
|
+
include.each do |arg|
|
116
|
+
observer.should_receive(:update).once.
|
117
|
+
with({ :data => arg[pnum], :command => :add_path})
|
118
|
+
end
|
119
|
+
|
120
|
+
subject.capture(observer) do
|
121
|
+
(include+exclude).each{ |arg| klazz.send(method, *arg) }
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
let(:mode_new_inc) do
|
127
|
+
[['/ham/jam', 'a+'], ['/ham/jam', 'a'],
|
128
|
+
['/spam', 'w+'], ['/spam', 'w']]
|
129
|
+
end
|
130
|
+
|
131
|
+
let(:mode_new_exc){ [['/nocapture', 'r']] }
|
132
|
+
|
133
|
+
it "should capture File#new when mode=/^(t|b)?((w|a)[+]?)(t|b)?$/" do
|
134
|
+
wrapper_spec_builder(File, :new, 0, mode_new_inc,
|
135
|
+
mode_new_exc)
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should capture File#open when mode=/^(t|b)?((w|a)[+]?)(t|b)?$/" do
|
139
|
+
wrapper_spec_builder(File, :open, 0, mode_new_inc,
|
140
|
+
mode_new_exc)
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should capture File#rename new path" do
|
144
|
+
wrapper_spec_builder(File, :rename, 1,
|
145
|
+
# original -> expectation
|
146
|
+
[['/old/path', '/new/path']])
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should capture File#symlink" do
|
150
|
+
wrapper_spec_builder(File, :symlink, 1,
|
151
|
+
[['/some/file', '/the/symlink']])
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should capture File#link" do
|
155
|
+
wrapper_spec_builder(File, :link, 1,
|
156
|
+
[['/some/file', '/the/hardlink']])
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should capture Dir#mkdir" do
|
160
|
+
basic_capture_test_setup(Dir, :mkdir) do |observer|
|
161
|
+
observer.should_receive(:update).once.
|
162
|
+
with({ :data => '/a_new_dir/', :command => :add_path })
|
163
|
+
|
164
|
+
subject.capture(observer) do
|
165
|
+
Dir.mkdir('/a_new_dir/and/other/junk')
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
context "#add" do
|
172
|
+
context "valid usage" do
|
173
|
+
before(:each) do
|
174
|
+
subject.stub(:realpath).and_return('/custard/creme')
|
175
|
+
# Stub the 'real' method, use generated wrapper.
|
176
|
+
Dir.stub(:__alias_mkdir).and_return(0)
|
177
|
+
end
|
178
|
+
|
179
|
+
context "no observers provided" do
|
180
|
+
it "should return false, but most not raise any errors" do
|
181
|
+
subject.add_path('/exploding/sausage').should be_false
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
# NOTE: Normally #stop would only be received once, but due to
|
186
|
+
# resetting in after(:each) it is received twice in these
|
187
|
+
# specs.
|
188
|
+
it "should send captured paths to observers when capturing stopped" do
|
189
|
+
observer.should_receive(:update).once.
|
190
|
+
with({ :data => '/custard/creme', :command => :add_path })
|
191
|
+
|
192
|
+
observer.should_receive(:update).twice.
|
193
|
+
with({ :command => :stop_capture })
|
194
|
+
|
195
|
+
subject.capture(observer){ Dir.mkdir('custard/creme') }
|
196
|
+
end
|
197
|
+
|
198
|
+
it "should accept and update multiple observers" do
|
199
|
+
[observer, observer_2].each do |o|
|
200
|
+
o.should_receive(:update).once.
|
201
|
+
with({ :data => '/custard/creme', :command => :add_path })
|
202
|
+
end
|
203
|
+
|
204
|
+
[observer, observer_2].each do |o|
|
205
|
+
o.should_receive(:update).twice.
|
206
|
+
with({ :command => :stop_capture })
|
207
|
+
end
|
208
|
+
|
209
|
+
subject.capture(observer, observer_2) do
|
210
|
+
Dir.mkdir('custard/creme')
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
context "#trigger" do
|
217
|
+
before(:each) do
|
218
|
+
subject.stub(:_stop)
|
219
|
+
end
|
220
|
+
|
221
|
+
it "should return false when there are no observers, but *not* fail" do
|
222
|
+
expect{ subject.trigger }.to be_true
|
223
|
+
end
|
224
|
+
|
225
|
+
it "should send a :chown update to observers" do
|
226
|
+
observer.should_receive(:update).with({:command => :chown})
|
227
|
+
|
228
|
+
subject.send(:add_observer, observer)
|
229
|
+
subject.trigger
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|