chef 11.6.0.rc.0 → 11.6.0.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- data/distro/common/html/chef-client.8.html +4 -4
- data/distro/common/html/chef-expander.8.html +4 -4
- data/distro/common/html/chef-expanderctl.8.html +4 -4
- data/distro/common/html/chef-server-webui.8.html +4 -4
- data/distro/common/html/chef-server.8.html +4 -4
- data/distro/common/html/chef-shell.1.html +4 -4
- data/distro/common/html/chef-solo.8.html +4 -4
- data/distro/common/html/chef-solr.8.html +4 -4
- data/distro/common/html/knife-bootstrap.1.html +4 -4
- data/distro/common/html/knife-client.1.html +4 -4
- data/distro/common/html/knife-configure.1.html +4 -4
- data/distro/common/html/knife-cookbook-site.1.html +4 -4
- data/distro/common/html/knife-cookbook.1.html +4 -4
- data/distro/common/html/knife-data-bag.1.html +4 -4
- data/distro/common/html/knife-environment.1.html +4 -4
- data/distro/common/html/knife-exec.1.html +4 -4
- data/distro/common/html/knife-index.1.html +4 -4
- data/distro/common/html/knife-node.1.html +4 -4
- data/distro/common/html/knife-role.1.html +4 -4
- data/distro/common/html/knife-search.1.html +4 -4
- data/distro/common/html/knife-ssh.1.html +4 -4
- data/distro/common/html/knife-status.1.html +4 -4
- data/distro/common/html/knife-tag.1.html +4 -4
- data/distro/common/html/knife.1.html +4 -4
- data/distro/common/man/man1/chef-shell.1 +1 -1
- data/distro/common/man/man1/knife-bootstrap.1 +1 -1
- data/distro/common/man/man1/knife-client.1 +1 -1
- data/distro/common/man/man1/knife-configure.1 +1 -1
- data/distro/common/man/man1/knife-cookbook-site.1 +1 -1
- data/distro/common/man/man1/knife-cookbook.1 +1 -1
- data/distro/common/man/man1/knife-data-bag.1 +1 -1
- data/distro/common/man/man1/knife-environment.1 +1 -1
- data/distro/common/man/man1/knife-exec.1 +1 -1
- data/distro/common/man/man1/knife-index.1 +1 -1
- data/distro/common/man/man1/knife-node.1 +1 -1
- data/distro/common/man/man1/knife-role.1 +1 -1
- data/distro/common/man/man1/knife-search.1 +1 -1
- data/distro/common/man/man1/knife-ssh.1 +1 -1
- data/distro/common/man/man1/knife-status.1 +1 -1
- data/distro/common/man/man1/knife-tag.1 +1 -1
- data/distro/common/man/man1/knife.1 +1 -1
- data/distro/common/man/man8/chef-client.8 +1 -1
- data/distro/common/man/man8/chef-expander.8 +1 -1
- data/distro/common/man/man8/chef-expanderctl.8 +1 -1
- data/distro/common/man/man8/chef-server-webui.8 +1 -1
- data/distro/common/man/man8/chef-server.8 +1 -1
- data/distro/common/man/man8/chef-solo.8 +1 -1
- data/distro/common/man/man8/chef-solr.8 +1 -1
- data/lib/chef/cookbook/cookbook_version_loader.rb +10 -19
- data/lib/chef/cookbook/file_system_file_vendor.rb +4 -7
- data/lib/chef/cookbook/metadata.rb +1 -10
- data/lib/chef/cookbook/syntax_check.rb +4 -4
- data/lib/chef/cookbook_uploader.rb +1 -1
- data/lib/chef/cookbook_version.rb +6 -10
- data/lib/chef/provider/file.rb +2 -1
- data/lib/chef/provider/package/yum.rb +1 -1
- data/lib/chef/resource/file.rb +2 -0
- data/lib/chef/scan_access_control.rb +6 -1
- data/lib/chef/util/diff.rb +31 -5
- data/lib/chef/version.rb +1 -1
- data/spec/functional/knife/exec_spec.rb +2 -2
- data/spec/spec_helper.rb +3 -0
- data/spec/support/platform_helpers.rb +12 -0
- data/spec/support/shared/functional/file_resource.rb +50 -10
- data/spec/support/shared/unit/provider/file.rb +4 -2
- data/spec/unit/cookbook/metadata_spec.rb +50 -56
- data/spec/unit/cookbook_loader_spec.rb +1 -22
- data/spec/unit/provider/package/yum_spec.rb +17 -36
- data/spec/unit/scan_access_control_spec.rb +4 -2
- data/spec/unit/util/diff_spec.rb +351 -11
- metadata +53 -9
- checksums.yaml +0 -15
- data/spec/data/cookbooks/not-nginx/attributes/default.rb +0 -1
- data/spec/data/cookbooks/not-nginx/metadata.rb +0 -1
- data/spec/data/kitchen/no-really-not-nginx/attributes/default.rb +0 -1
- data/spec/data/kitchen/no-really-not-nginx/metadata.rb +0 -1
@@ -68,8 +68,7 @@ describe Chef::CookbookLoader do
|
|
68
68
|
seen[2].should == "borken"
|
69
69
|
seen[3].should == "ignorken"
|
70
70
|
seen[4].should == "java"
|
71
|
-
seen[5].should == "
|
72
|
-
seen[6].should == "openldap"
|
71
|
+
seen[5].should == "openldap"
|
73
72
|
end
|
74
73
|
end
|
75
74
|
|
@@ -156,26 +155,6 @@ describe Chef::CookbookLoader do
|
|
156
155
|
end
|
157
156
|
@cookbook_loader.load_cookbooks
|
158
157
|
end
|
159
|
-
|
160
|
-
it "should index cookbooks by name, not pathname" do
|
161
|
-
@cookbook_loader.should_not have_key(:'not-nginx')
|
162
|
-
@cookbook_loader.should_not have_key(:'no-really-not-nginx')
|
163
|
-
@cookbook_loader.should have_key(:nginx)
|
164
|
-
end
|
165
|
-
|
166
|
-
it "should shadow cookbooks by name, not pathname" do
|
167
|
-
@cookbook_loader[:nginx].attribute_filenames.detect { |f|
|
168
|
-
f =~ /cookbooks\/not-nginx\/attributes\/default.rb/
|
169
|
-
}.should_not eql(nil)
|
170
|
-
@cookbook_loader[:nginx].attribute_filenames.detect { |f|
|
171
|
-
f =~ /kitchen\/no-really-not-nginx\/attributes\/default.rb/
|
172
|
-
}.should eql(nil)
|
173
|
-
end
|
174
|
-
|
175
|
-
it "should emit deprecation warning if name is not in metadata" do
|
176
|
-
Chef::Log.should_receive(:warn).at_least(:once).with(/Inferring cookbook name from directory name \([^)]+\) is deprecated, please set a name in the metadata./)
|
177
|
-
@cookbook_loader.load_cookbooks
|
178
|
-
end
|
179
158
|
end # load_cookbooks
|
180
159
|
|
181
160
|
end # loading all cookbooks
|
@@ -39,7 +39,6 @@ describe Chef::Provider::Package::Yum do
|
|
39
39
|
)
|
40
40
|
Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache)
|
41
41
|
@provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
|
42
|
-
@stderr = StringIO.new
|
43
42
|
@pid = mock("PID")
|
44
43
|
end
|
45
44
|
|
@@ -542,7 +541,7 @@ describe Chef::Provider::Package::Yum do
|
|
542
541
|
it "should call action_upgrade in the parent if the candidate version is nil" do
|
543
542
|
@provider.load_current_resource
|
544
543
|
@current_resource = Chef::Resource::Package.new('cups')
|
545
|
-
@provider.candidate_version = nil
|
544
|
+
@provider.candidate_version = nil
|
546
545
|
@provider.should_not_receive(:upgrade_package)
|
547
546
|
@provider.action_upgrade
|
548
547
|
end
|
@@ -1155,7 +1154,7 @@ describe Chef::Provider::Package::Yum::RPMDbPackage do
|
|
1155
1154
|
|
1156
1155
|
describe "repoid" do
|
1157
1156
|
it "should return the source repository repoid" do
|
1158
|
-
@rpm_x.repoid.should be == "base"
|
1157
|
+
@rpm_x.repoid.should be == "base"
|
1159
1158
|
@rpm_y.repoid.should be == "extras"
|
1160
1159
|
@rpm_z.repoid.should be == "other"
|
1161
1160
|
end
|
@@ -1544,7 +1543,10 @@ describe Chef::Provider::Package::Yum::YumCache do
|
|
1544
1543
|
end
|
1545
1544
|
|
1546
1545
|
before(:each) do
|
1547
|
-
|
1546
|
+
@stdin = mock("STDIN", :nil_object => true)
|
1547
|
+
@stdout = mock("STDOUT", :nil_object => true)
|
1548
|
+
|
1549
|
+
@stdout_good = <<EOF
|
1548
1550
|
[option installonlypkgs] kernel kernel-bigmem kernel-enterprise
|
1549
1551
|
erlang-mochiweb 0 1.4.1 5.el5 x86_64 ['erlang-mochiweb = 1.4.1-5.el5', 'mochiweb = 1.4.1-5.el5'] i installed
|
1550
1552
|
zip 0 2.31 2.el5 x86_64 ['zip = 2.31-2.el5'] r base
|
@@ -1560,9 +1562,16 @@ znc-extra 0 0.098 1.el5 x86_64 [] a base
|
|
1560
1562
|
znc-modtcl 0 0.098 1.el5 x86_64 [] a base
|
1561
1563
|
znc-test.beta1 0 0.098 1.el5 x86_64 [] a extras
|
1562
1564
|
znc-test.test.beta1 0 0.098 1.el5 x86_64 [] a base
|
1565
|
+
EOF
|
1566
|
+
@stdout_bad_type = <<EOF
|
1567
|
+
zip 0 2.31 2.el5 x86_64 ['zip = 2.31-2.el5'] r base
|
1568
|
+
zlib 0 1.2.3 3 x86_64 ['zlib = 1.2.3-3', 'libz.so.1()(64bit)'] c base
|
1569
|
+
zlib-devel 0 1.2.3 3 i386 [] a extras
|
1570
|
+
zlib-devel 0 1.2.3 3 x86_64 ['zlib-devel = 1.2.3-3'] bad installed
|
1571
|
+
znc-modtcl 0 0.098 1.el5 x86_64 [] a base
|
1563
1572
|
EOF
|
1564
1573
|
|
1565
|
-
|
1574
|
+
@stdout_bad_separators = <<EOF
|
1566
1575
|
zip 0 2.31 2.el5 x86_64 ['zip = 2.31-2.el5'] r base
|
1567
1576
|
zlib 0 1.2.3 3 x86_64 ['zlib = 1.2.3-3', 'libz.so.1()(64bit)'] i base bad
|
1568
1577
|
zlib-devel 0 1.2.3 3 i386 [] a extras
|
@@ -1570,41 +1579,13 @@ bad zlib-devel 0 1.2.3 3 x86_64 ['zlib-devel = 1.2.3-3'] i installed
|
|
1570
1579
|
znc-modtcl 0 0.098 1.el5 x86_64 [] a base bad
|
1571
1580
|
EOF
|
1572
1581
|
|
1573
|
-
|
1574
|
-
zip 0 2.31 2.el5 x86_64 ['zip = 2.31-2.el5'] r base
|
1575
|
-
zlib 0 1.2.3 3 x86_64 ['zlib = 1.2.3-3', 'libz.so.1()(64bit)'] c base
|
1576
|
-
zlib-devel 0 1.2.3 3 i386 [] a extras
|
1577
|
-
zlib-devel 0 1.2.3 3 x86_64 ['zlib-devel = 1.2.3-3'] bad installed
|
1578
|
-
znc-modtcl 0 0.098 1.el5 x86_64 [] a base
|
1579
|
-
EOF
|
1582
|
+
@stdout_no_output = ""
|
1580
1583
|
|
1581
|
-
|
1584
|
+
@stderr = <<EOF
|
1582
1585
|
yum-dump Config Error: File contains no section headers.
|
1583
1586
|
file: file://///etc/yum.repos.d/CentOS-Base.repo, line: 12
|
1584
1587
|
'qeqwewe\n'
|
1585
1588
|
EOF
|
1586
|
-
|
1587
|
-
@stdin = mock("STDIN", :nil_object => true)
|
1588
|
-
@stdout = mock("STDOUT", :nil_object => true)
|
1589
|
-
@stdout_good = mock("STDOUT", :nil_object => true)
|
1590
|
-
s = @stdout_good.stub!(:each_line)
|
1591
|
-
yum_dump_good_output.split("\n").each do |line|
|
1592
|
-
s.and_yield(line)
|
1593
|
-
end
|
1594
|
-
@stdout_bad_type = mock("STDOUT", :nil_object => true)
|
1595
|
-
s = @stdout_bad_type.stub!(:each_line)
|
1596
|
-
yum_dump_bad_output_type.split("\n").each do |line|
|
1597
|
-
s.and_yield(line)
|
1598
|
-
end
|
1599
|
-
@stdout_bad_separators = mock("STDOUT", :nil_object => true)
|
1600
|
-
s = @stdout_bad_separators.stub!(:each_line)
|
1601
|
-
yum_dump_bad_output_separators.split("\n").each do |line|
|
1602
|
-
s.and_yield(line)
|
1603
|
-
end
|
1604
|
-
@stdout_no_output = mock("STDOUT", :nil_object => true)
|
1605
|
-
@stdout_no_output.stub!(:each_line).and_return(nil)
|
1606
|
-
@stderr = mock("STDERR", :nil_object => true)
|
1607
|
-
@stderr.stub!(:readlines).and_return(yum_dump_error.split("\n"))
|
1608
1589
|
@status = mock("Status", :exitstatus => 0, :stdin => @stdin, :stdout => @stdout_good, :stderr => @stderr)
|
1609
1590
|
|
1610
1591
|
# new singleton each time
|
@@ -1808,7 +1789,7 @@ EOF
|
|
1808
1789
|
end
|
1809
1790
|
|
1810
1791
|
it "should return nil when no match for package-version, no arch" do
|
1811
|
-
@yc.package_repository("zisofs-tools", "pretend", nil).should be == nil
|
1792
|
+
@yc.package_repository("zisofs-tools", "pretend", nil).should be == nil
|
1812
1793
|
@yc.package_repository("zisofs-tools", "pretend").should be == nil
|
1813
1794
|
@yc.package_repository("pretend", "1.0.6-3.2.2").should be == nil
|
1814
1795
|
end
|
@@ -21,7 +21,8 @@ require 'chef/scan_access_control'
|
|
21
21
|
describe Chef::ScanAccessControl do
|
22
22
|
|
23
23
|
before do
|
24
|
-
@new_resource = Chef::Resource::File.new("/tmp/foo/bar/baz/
|
24
|
+
@new_resource = Chef::Resource::File.new("/tmp/foo/bar/baz/link")
|
25
|
+
@real_file = "/tmp/foo/bar/real/file"
|
25
26
|
@current_resource = Chef::Resource::File.new(@new_resource.path)
|
26
27
|
@scanner = Chef::ScanAccessControl.new(@new_resource, @current_resource)
|
27
28
|
end
|
@@ -49,7 +50,8 @@ describe Chef::ScanAccessControl do
|
|
49
50
|
|
50
51
|
before do
|
51
52
|
@stat = mock("File::Stat for #{@new_resource.path}", :uid => 0, :gid => 0, :mode => 00100644)
|
52
|
-
File.should_receive(:
|
53
|
+
File.should_receive(:realpath).with(@new_resource.path).and_return(@real_file)
|
54
|
+
File.should_receive(:stat).with(@real_file).and_return(@stat)
|
53
55
|
File.should_receive(:exist?).with(@new_resource.path).and_return(true)
|
54
56
|
end
|
55
57
|
|
data/spec/unit/util/diff_spec.rb
CHANGED
@@ -34,6 +34,12 @@ describe Chef::Util::Diff, :uses_diff => true do
|
|
34
34
|
let!(:old_file) { old_tempfile.path }
|
35
35
|
let!(:new_file) { new_tempfile.path }
|
36
36
|
|
37
|
+
let(:plain_ascii) { "This is a text file.\nWith more than one line.\nAnd a \tTab.\nAnd lets make sure that other printable chars work too: ~!@\#$%^&*()`:\"<>?{}|_+,./;'[]\\-=\n" }
|
38
|
+
# these are all byte sequences that are illegal in the other encodings... (but they may legally transcode)
|
39
|
+
let(:utf_8) { "testing utf-8 unicode...\n\n\non a new line: \xE2\x80\x93\n" } # unicode em-dash
|
40
|
+
let(:latin_1) { "It is more metal.\nif you have an \xFDmlaut.\n" } # NB: changed to y-with-diaresis, but i'm American so I don't know the difference
|
41
|
+
let(:shift_jis) { "I have no idea what this character is:\n \x83\x80.\n" } # seriously, no clue, but \x80 is nice and illegal in other encodings
|
42
|
+
|
37
43
|
let(:differ) do # subject
|
38
44
|
differ = Chef::Util::Diff.new
|
39
45
|
differ.diff(old_file, new_file)
|
@@ -114,6 +120,200 @@ describe Chef::Util::Diff, :uses_diff => true do
|
|
114
120
|
end
|
115
121
|
end
|
116
122
|
|
123
|
+
describe "when the default external encoding is UTF-8", :ruby_gte_19_only do
|
124
|
+
|
125
|
+
before do
|
126
|
+
@saved_default_external = Encoding.default_external
|
127
|
+
Encoding.default_external = Encoding::UTF_8
|
128
|
+
end
|
129
|
+
|
130
|
+
after do
|
131
|
+
Encoding.default_external = @saved_default_external
|
132
|
+
end
|
133
|
+
|
134
|
+
describe "when a file has ASCII text" do
|
135
|
+
before do
|
136
|
+
new_tempfile.write(plain_ascii)
|
137
|
+
new_tempfile.close
|
138
|
+
end
|
139
|
+
it "calling for_output should return a valid diff" do
|
140
|
+
differ.for_output.join("\\n").should match(/\A--- .*\\n\+\+\+ .*\\n@@/m)
|
141
|
+
end
|
142
|
+
it "calling for_reporting should return a utf-8 string" do
|
143
|
+
expect(differ.for_reporting.encoding).to equal(Encoding::UTF_8)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
describe "when a file has UTF-8 text" do
|
148
|
+
before do
|
149
|
+
new_tempfile.write(utf_8)
|
150
|
+
new_tempfile.close
|
151
|
+
end
|
152
|
+
it "calling for_output should return a valid diff" do
|
153
|
+
differ.for_output.join("\\n").should match(/\A--- .*\\n\+\+\+ .*\\n@@/m)
|
154
|
+
end
|
155
|
+
it "calling for_reporting should return a utf-8 string" do
|
156
|
+
expect(differ.for_reporting.encoding).to equal(Encoding::UTF_8)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe "when a file has Latin-1 text" do
|
161
|
+
before do
|
162
|
+
new_tempfile.write(latin_1)
|
163
|
+
new_tempfile.close
|
164
|
+
end
|
165
|
+
it "calling for_output should complain that the content is binary" do
|
166
|
+
expect(differ.for_output).to eql( [ "(new content is binary, diff output suppressed)" ])
|
167
|
+
end
|
168
|
+
it "calling for_reporting should be nil" do
|
169
|
+
expect(differ.for_reporting).to be_nil
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
describe "when a file has Shift-JIS text" do
|
174
|
+
before do
|
175
|
+
new_tempfile.write(shift_jis)
|
176
|
+
new_tempfile.close
|
177
|
+
end
|
178
|
+
it "calling for_output should complain that the content is binary" do
|
179
|
+
expect(differ.for_output).to eql( [ "(new content is binary, diff output suppressed)" ])
|
180
|
+
end
|
181
|
+
it "calling for_reporting should be nil" do
|
182
|
+
expect(differ.for_reporting).to be_nil
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
end
|
187
|
+
|
188
|
+
describe "when the default external encoding is Latin-1", :ruby_gte_19_only do
|
189
|
+
|
190
|
+
before do
|
191
|
+
@saved_default_external = Encoding.default_external
|
192
|
+
Encoding.default_external = Encoding::ISO_8859_1
|
193
|
+
end
|
194
|
+
|
195
|
+
after do
|
196
|
+
Encoding.default_external = @saved_default_external
|
197
|
+
end
|
198
|
+
|
199
|
+
describe "when a file has ASCII text" do
|
200
|
+
before do
|
201
|
+
new_tempfile.write(plain_ascii)
|
202
|
+
new_tempfile.close
|
203
|
+
end
|
204
|
+
it "calling for_output should return a valid diff" do
|
205
|
+
differ.for_output.join("\\n").should match(/\A--- .*\\n\+\+\+ .*\\n@@/m)
|
206
|
+
end
|
207
|
+
it "calling for_reporting should return a utf-8 string" do
|
208
|
+
expect(differ.for_reporting.encoding).to equal(Encoding::UTF_8)
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
describe "when a file has UTF-8 text" do
|
213
|
+
before do
|
214
|
+
new_tempfile.write(utf_8)
|
215
|
+
new_tempfile.close
|
216
|
+
end
|
217
|
+
it "calling for_output should complain that the content is binary" do
|
218
|
+
expect(differ.for_output).to eql( [ "(new content is binary, diff output suppressed)" ])
|
219
|
+
end
|
220
|
+
it "calling for_reporting should be nil" do
|
221
|
+
expect(differ.for_reporting).to be_nil
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
describe "when a file has Latin-1 text" do
|
226
|
+
before do
|
227
|
+
new_tempfile.write(latin_1)
|
228
|
+
new_tempfile.close
|
229
|
+
end
|
230
|
+
it "calling for_output should return a valid diff" do
|
231
|
+
differ.for_output.join("\\n").should match(/\A--- .*\\n\+\+\+ .*\\n@@/m)
|
232
|
+
end
|
233
|
+
it "calling for_reporting should return a utf-8 string" do
|
234
|
+
expect(differ.for_reporting.encoding).to equal(Encoding::UTF_8)
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
describe "when a file has Shift-JIS text" do
|
239
|
+
before do
|
240
|
+
new_tempfile.write(shift_jis)
|
241
|
+
new_tempfile.close
|
242
|
+
end
|
243
|
+
it "calling for_output should complain that the content is binary" do
|
244
|
+
expect(differ.for_output).to eql( [ "(new content is binary, diff output suppressed)" ])
|
245
|
+
end
|
246
|
+
it "calling for_reporting should be nil" do
|
247
|
+
expect(differ.for_reporting).to be_nil
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
end
|
252
|
+
describe "when the default external encoding is Shift_JIS", :ruby_gte_19_only do
|
253
|
+
|
254
|
+
before do
|
255
|
+
@saved_default_external = Encoding.default_external
|
256
|
+
Encoding.default_external = Encoding::Shift_JIS
|
257
|
+
end
|
258
|
+
|
259
|
+
after do
|
260
|
+
Encoding.default_external = @saved_default_external
|
261
|
+
end
|
262
|
+
|
263
|
+
describe "when a file has ASCII text" do
|
264
|
+
before do
|
265
|
+
new_tempfile.write(plain_ascii)
|
266
|
+
new_tempfile.close
|
267
|
+
end
|
268
|
+
it "calling for_output should return a valid diff" do
|
269
|
+
differ.for_output.join("\\n").should match(/\A--- .*\\n\+\+\+ .*\\n@@/m)
|
270
|
+
end
|
271
|
+
it "calling for_reporting should return a utf-8 string" do
|
272
|
+
expect(differ.for_reporting.encoding).to equal(Encoding::UTF_8)
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
describe "when a file has UTF-8 text" do
|
277
|
+
before do
|
278
|
+
new_tempfile.write(utf_8)
|
279
|
+
new_tempfile.close
|
280
|
+
end
|
281
|
+
it "calling for_output should complain that the content is binary" do
|
282
|
+
expect(differ.for_output).to eql( [ "(new content is binary, diff output suppressed)" ])
|
283
|
+
end
|
284
|
+
it "calling for_reporting should be nil" do
|
285
|
+
expect(differ.for_reporting).to be_nil
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
describe "when a file has Latin-1 text" do
|
290
|
+
before do
|
291
|
+
new_tempfile.write(latin_1)
|
292
|
+
new_tempfile.close
|
293
|
+
end
|
294
|
+
it "calling for_output should complain that the content is binary" do
|
295
|
+
expect(differ.for_output).to eql( [ "(new content is binary, diff output suppressed)" ])
|
296
|
+
end
|
297
|
+
it "calling for_reporting should be nil" do
|
298
|
+
expect(differ.for_reporting).to be_nil
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
describe "when a file has Shift-JIS text" do
|
303
|
+
before do
|
304
|
+
new_tempfile.write(shift_jis)
|
305
|
+
new_tempfile.close
|
306
|
+
end
|
307
|
+
it "calling for_output should return a valid diff" do
|
308
|
+
differ.for_output.join("\\n").should match(/\A--- .*\\n\+\+\+ .*\\n@@/m)
|
309
|
+
end
|
310
|
+
it "calling for_reporting should return a utf-8 string" do
|
311
|
+
expect(differ.for_reporting.encoding).to equal(Encoding::UTF_8)
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
end
|
316
|
+
|
117
317
|
describe "when testing the diff_filesize_threshold" do
|
118
318
|
before do
|
119
319
|
@diff_filesize_threshold_saved = Chef::Config[:diff_filesize_threshold]
|
@@ -165,11 +365,11 @@ describe Chef::Util::Diff, :uses_diff => true do
|
|
165
365
|
|
166
366
|
it "calling for_output should return a unified diff" do
|
167
367
|
differ.for_output.size.should eql(5)
|
168
|
-
differ.for_output.join("\\n").should match(
|
368
|
+
differ.for_output.join("\\n").should match(/\A--- .*\\n\+\+\+ .*\\n@@/m)
|
169
369
|
end
|
170
370
|
|
171
371
|
it "calling for_reporting should return a unified diff" do
|
172
|
-
differ.for_reporting.should match(
|
372
|
+
differ.for_reporting.should match(/\A--- .*\\n\+\+\+ .*\\n@@/m)
|
173
373
|
end
|
174
374
|
|
175
375
|
describe "when the diff output is too long" do
|
@@ -227,30 +427,170 @@ describe Chef::Util::Diff, :uses_diff => true do
|
|
227
427
|
describe "when checking if files are binary or text" do
|
228
428
|
|
229
429
|
it "should identify zero-length files as text" do
|
230
|
-
Tempfile.
|
231
|
-
|
430
|
+
Tempfile.open("chef-util-diff-spec") do |file|
|
431
|
+
file.close
|
432
|
+
differ.send(:is_binary?, file.path).should be_false
|
232
433
|
end
|
233
434
|
end
|
234
435
|
|
235
436
|
it "should identify text files as text" do
|
236
|
-
Tempfile.
|
237
|
-
file.write(
|
238
|
-
file.write("With more than one line.")
|
239
|
-
file.write("And lets make sure that other printable chars work too: ~!@\#$%^&*()`:\"<>?{}|_+,./;'[]\\-=")
|
437
|
+
Tempfile.open("chef-util-diff-spec") do |file|
|
438
|
+
file.write(plain_ascii)
|
240
439
|
file.close
|
241
|
-
differ.is_binary
|
440
|
+
differ.send(:is_binary?, file.path).should be_false
|
242
441
|
end
|
243
442
|
end
|
244
443
|
|
245
444
|
it "should identify a null-terminated string files as binary" do
|
246
|
-
Tempfile.
|
445
|
+
Tempfile.open("chef-util-diff-spec") do |file|
|
247
446
|
file.write("This is a binary file.\0")
|
248
447
|
file.close
|
249
|
-
differ.is_binary
|
448
|
+
differ.send(:is_binary?, file.path).should be_true
|
449
|
+
end
|
450
|
+
end
|
451
|
+
|
452
|
+
it "should identify null-teriminated multi-line string files as binary" do
|
453
|
+
Tempfile.open("chef-util-diff-spec") do |file|
|
454
|
+
file.write("This is a binary file.\nNo Really\nit is\0")
|
455
|
+
file.close
|
456
|
+
differ.send(:is_binary?, file.path).should be_true
|
457
|
+
end
|
458
|
+
end
|
459
|
+
|
460
|
+
describe "when the default external encoding is UTF-8", :ruby_gte_19_only do
|
461
|
+
|
462
|
+
before do
|
463
|
+
@saved_default_external = Encoding.default_external
|
464
|
+
Encoding.default_external = Encoding::UTF_8
|
465
|
+
end
|
466
|
+
|
467
|
+
after do
|
468
|
+
Encoding.default_external = @saved_default_external
|
469
|
+
end
|
470
|
+
|
471
|
+
it "should identify normal ASCII as text" do
|
472
|
+
Tempfile.open("chef-util-diff-spec") do |file|
|
473
|
+
file.write(plain_ascii)
|
474
|
+
file.close
|
475
|
+
differ.send(:is_binary?, file.path).should be_false
|
476
|
+
end
|
477
|
+
end
|
478
|
+
|
479
|
+
it "should identify UTF-8 as text" do
|
480
|
+
Tempfile.open("chef-util-diff-spec") do |file|
|
481
|
+
file.write(utf_8)
|
482
|
+
file.close
|
483
|
+
differ.send(:is_binary?, file.path).should be_false
|
484
|
+
end
|
485
|
+
end
|
486
|
+
|
487
|
+
it "should identify Latin-1 that is invalid UTF-8 as binary" do
|
488
|
+
Tempfile.open("chef-util-diff-spec") do |file|
|
489
|
+
file.write(latin_1)
|
490
|
+
file.close
|
491
|
+
differ.send(:is_binary?, file.path).should be_true
|
492
|
+
end
|
493
|
+
end
|
494
|
+
|
495
|
+
it "should identify Shift-JIS that is invalid UTF-8 as binary" do
|
496
|
+
Tempfile.open("chef-util-diff-spec") do |file|
|
497
|
+
file.write(shift_jis)
|
498
|
+
file.close
|
499
|
+
differ.send(:is_binary?, file.path).should be_true
|
500
|
+
end
|
501
|
+
end
|
502
|
+
|
503
|
+
end
|
504
|
+
|
505
|
+
describe "when the default external encoding is Latin-1", :ruby_gte_19_only do
|
506
|
+
|
507
|
+
before do
|
508
|
+
@saved_default_external = Encoding.default_external
|
509
|
+
Encoding.default_external = Encoding::ISO_8859_1
|
510
|
+
end
|
511
|
+
|
512
|
+
after do
|
513
|
+
Encoding.default_external = @saved_default_external
|
514
|
+
end
|
515
|
+
|
516
|
+
it "should identify normal ASCII as text" do
|
517
|
+
Tempfile.open("chef-util-diff-spec") do |file|
|
518
|
+
file.write(plain_ascii)
|
519
|
+
file.close
|
520
|
+
differ.send(:is_binary?, file.path).should be_false
|
521
|
+
end
|
522
|
+
end
|
523
|
+
|
524
|
+
it "should identify UTF-8 that is invalid Latin-1 as binary" do
|
525
|
+
Tempfile.open("chef-util-diff-spec") do |file|
|
526
|
+
file.write(utf_8)
|
527
|
+
file.close
|
528
|
+
differ.send(:is_binary?, file.path).should be_true
|
529
|
+
end
|
530
|
+
end
|
531
|
+
|
532
|
+
it "should identify Latin-1 as text" do
|
533
|
+
Tempfile.open("chef-util-diff-spec") do |file|
|
534
|
+
file.write(latin_1)
|
535
|
+
file.close
|
536
|
+
differ.send(:is_binary?, file.path).should be_false
|
537
|
+
end
|
538
|
+
end
|
539
|
+
|
540
|
+
it "should identify Shift-JIS that is invalid Latin-1 as binary" do
|
541
|
+
Tempfile.open("chef-util-diff-spec") do |file|
|
542
|
+
file.write(shift_jis)
|
543
|
+
file.close
|
544
|
+
differ.send(:is_binary?, file.path).should be_true
|
545
|
+
end
|
250
546
|
end
|
251
547
|
end
|
252
548
|
|
549
|
+
describe "when the default external encoding is Shift-JIS", :ruby_gte_19_only do
|
550
|
+
|
551
|
+
before do
|
552
|
+
@saved_default_external = Encoding.default_external
|
553
|
+
Encoding.default_external = Encoding::Shift_JIS
|
554
|
+
end
|
555
|
+
|
556
|
+
after do
|
557
|
+
Encoding.default_external = @saved_default_external
|
558
|
+
end
|
559
|
+
|
560
|
+
it "should identify normal ASCII as text" do
|
561
|
+
Tempfile.open("chef-util-diff-spec") do |file|
|
562
|
+
file.write(plain_ascii)
|
563
|
+
file.close
|
564
|
+
differ.send(:is_binary?, file.path).should be_false
|
565
|
+
end
|
566
|
+
end
|
567
|
+
it "should identify UTF-8 that is invalid Shift-JIS as binary" do
|
568
|
+
Tempfile.open("chef-util-diff-spec") do |file|
|
569
|
+
file.write(utf_8)
|
570
|
+
file.close
|
571
|
+
differ.send(:is_binary?, file.path).should be_true
|
572
|
+
end
|
573
|
+
end
|
574
|
+
|
575
|
+
it "should identify Latin-1 that is invalid Shift-JIS as binary" do
|
576
|
+
Tempfile.open("chef-util-diff-spec") do |file|
|
577
|
+
file.write(latin_1)
|
578
|
+
file.close
|
579
|
+
differ.send(:is_binary?, file.path).should be_true
|
580
|
+
end
|
581
|
+
end
|
582
|
+
|
583
|
+
it "should identify Shift-JIS as text" do
|
584
|
+
Tempfile.open("chef-util-diff-spec") do |file|
|
585
|
+
file.write(shift_jis)
|
586
|
+
file.close
|
587
|
+
differ.send(:is_binary?, file.path).should be_false
|
588
|
+
end
|
589
|
+
end
|
590
|
+
|
591
|
+
end
|
253
592
|
end
|
254
593
|
|
255
594
|
end
|
256
595
|
|
596
|
+
|