blob: ac7f52cc2ba0d31eb79508eb17f6151adc6f1db4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
#
# Author:: Adam Edwards (<adamed@opscode.com>)
# Copyright:: Copyright 2013-2016, Opscode, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require "spec_helper"
require "uri"
describe Chef::Provider::RemoteFile::CacheControlData do
before do
@original_config = Chef::Config.hash_dup
end
after do
Chef::Config.configuration = @original_config if @original_config
end
before(:each) do
Chef::Config[:file_cache_path] = Dir.mktmpdir
end
after(:each) do
FileUtils.rm_rf(Chef::Config[:file_cache_path])
end
let(:uri) { URI.parse("http://www.bing.com/robots.txt") }
describe "when the cache control data save method is invoked" do
subject(:cache_control_data) do
Chef::Provider::RemoteFile::CacheControlData.load_and_validate(uri, file_checksum)
end
# the checksum of the file last we fetched it.
let(:file_checksum) { "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" }
let(:etag) { "\"a-strong-identifier\"" }
let(:mtime) { "Thu, 01 Aug 2013 08:16:32 GMT" }
before do
cache_control_data.etag = etag
cache_control_data.mtime = mtime
cache_control_data.checksum = file_checksum
end
it "writes data to the cache" do
cache_control_data.save
end
it "writes the data to the cache and the same data can be read back" do
cache_control_data.save
saved_cache_control_data = Chef::Provider::RemoteFile::CacheControlData.load_and_validate(uri, file_checksum)
expect(saved_cache_control_data.etag).to eq(cache_control_data.etag)
expect(saved_cache_control_data.mtime).to eq(cache_control_data.mtime)
expect(saved_cache_control_data.checksum).to eq(cache_control_data.checksum)
end
# Cover the very long remote file path case -- see CHEF-4422 where
# local cache file names generated from the long uri exceeded
# local file system path limits resulting in exceptions from
# file system API's on both Windows and Unix systems.
context "when the length of the uri exceeds the path length limits for the local file system" do
let(:uri_exceeds_file_system_limit) do
URI.parse("http://www.bing.com/" + ("0" * 1024))
end
let(:uri) { uri_exceeds_file_system_limit }
it "writes data to the cache" do
expect do
cache_control_data.save
end.not_to raise_error
end
it "writes the data to the cache and the same data can be read back" do
cache_control_data.save
saved_cache_control_data = Chef::Provider::RemoteFile::CacheControlData.load_and_validate(uri, file_checksum)
expect(saved_cache_control_data.etag).to eq(cache_control_data.etag)
expect(saved_cache_control_data.mtime).to eq(cache_control_data.mtime)
expect(saved_cache_control_data.checksum).to eq(cache_control_data.checksum)
end
end
end
end
|