From 67a74e5029c5db0bffc63a4709ecf125353a247c Mon Sep 17 00:00:00 2001 From: danielsdeleo Date: Fri, 21 Dec 2012 12:03:06 -0800 Subject: [CHEF-3715] rename ChecksumCache => Digester --- lib/chef/checksum_cache.rb | 2 +- lib/chef/cookbook_version.rb | 2 +- lib/chef/mixin/checksum.rb | 4 +-- spec/unit/checksum_cache_spec.rb | 6 ++-- spec/unit/cookbook/syntax_check_spec.rb | 62 --------------------------------- spec/unit/mixin/checksum_spec.rb | 4 +-- 6 files changed, 9 insertions(+), 71 deletions(-) diff --git a/lib/chef/checksum_cache.rb b/lib/chef/checksum_cache.rb index 23ac195892..669ff8b8a5 100644 --- a/lib/chef/checksum_cache.rb +++ b/lib/chef/checksum_cache.rb @@ -21,7 +21,7 @@ require 'digest' class Chef - class ChecksumCache + class Digester def self.instance @instance ||= new diff --git a/lib/chef/cookbook_version.rb b/lib/chef/cookbook_version.rb index 0e11174a07..580a64ffbe 100644 --- a/lib/chef/cookbook_version.rb +++ b/lib/chef/cookbook_version.rb @@ -69,7 +69,7 @@ class Chef # This is the one and only method that knows how cookbook files' # checksums are generated. def self.checksum_cookbook_file(filepath) - Chef::ChecksumCache.generate_md5_checksum_for_file(filepath) + Chef::Digester.generate_md5_checksum_for_file(filepath) rescue Errno::ENOENT Chef::Log.debug("File #{filepath} does not exist, so there is no checksum to generate") nil diff --git a/lib/chef/mixin/checksum.rb b/lib/chef/mixin/checksum.rb index 7b716b6285..64dd21851a 100644 --- a/lib/chef/mixin/checksum.rb +++ b/lib/chef/mixin/checksum.rb @@ -24,9 +24,9 @@ class Chef module Checksum def checksum(file) - Chef::ChecksumCache.checksum_for_file(file) + Chef::Digester.checksum_for_file(file) end - + end end end diff --git a/spec/unit/checksum_cache_spec.rb b/spec/unit/checksum_cache_spec.rb index 9746e096e2..28e3e918fe 100644 --- a/spec/unit/checksum_cache_spec.rb +++ b/spec/unit/checksum_cache_spec.rb @@ -20,16 +20,16 @@ require 'spec_helper' -describe Chef::ChecksumCache do +describe Chef::Digester do before(:each) do - @cache = Chef::ChecksumCache.instance + @cache = Chef::Digester.instance end describe "when computing checksums of cookbook files and templates" do it "proxies the class method checksum_for_file to the instance" do @cache.should_receive(:checksum_for_file).with("a_file_or_a_fail") - Chef::ChecksumCache.checksum_for_file("a_file_or_a_fail") + Chef::Digester.checksum_for_file("a_file_or_a_fail") end it "computes a checksum of a file" do diff --git a/spec/unit/cookbook/syntax_check_spec.rb b/spec/unit/cookbook/syntax_check_spec.rb index 4297751432..948b3c5a38 100644 --- a/spec/unit/cookbook/syntax_check_spec.rb +++ b/spec/unit/cookbook/syntax_check_spec.rb @@ -16,68 +16,6 @@ # limitations under the License. # -################################################### -# OLD: -################################################### -# def test_ruby(cookbook_dir) -# cache = Chef::ChecksumCache.instance -# Dir[File.join(cookbook_dir, '**', '*.rb')].each do |ruby_file| -# key = cache.generate_key(ruby_file, "chef-test") -# fstat = File.stat(ruby_file) -# -# if cache.lookup_checksum(key, fstat) -# Chef::Log.info("No change in checksum of #{ruby_file}") -# else -# Chef::Log.info("Testing #{ruby_file} for syntax errors...") -# Chef::Mixin::Command.run_command(:command => "ruby -c #{ruby_file}", :output_on_failure => true) -# cache.generate_checksum(key, ruby_file, fstat) -# end -# end -# end -# -#def test_templates(cookbook_dir) -# cache = Chef::ChecksumCache.instance -# Dir[File.join(cookbook_dir, '**', '*.erb')].each do |erb_file| -# key = cache.generate_key(erb_file, "chef-test") -# fstat = File.stat(erb_file) -# -# if cache.lookup_checksum(key, fstat) -# Chef::Log.info("No change in checksum of #{erb_file}") -# else -# Chef::Log.info("Testing template #{erb_file} for syntax errors...") -# Chef::Mixin::Command.run_command(:command => "sh -c 'erubis -x #{erb_file} | ruby -c'", :output_on_failure => true) -# cache.generate_checksum(key, erb_file, fstat) -# end -# end -#end -# - -################################################### -# NEW: -################################################### -# def test_template_file(cookbook_dir, erb_file) -# Chef::Log.debug("Testing template #{erb_file} for syntax errors...") -# result = shell_out("sh -c 'erubis -x #{erb_file} | ruby -c'") -# result.error! -# rescue Mixlib::ShellOut::ShellCommandFailed -# file_relative_path = erb_file[/^#{Regexp.escape(cookbook_dir+File::Separator)}(.*)/, 1] -# Chef::Log.fatal("Erb template #{file_relative_path} has a syntax error:") -# result.stderr.each_line { |l| Chef::Log.fatal(l.chomp) } -# exit(1) -# end -# -# def test_ruby_file(cookbook_dir, ruby_file) -# Chef::Log.debug("Testing #{ruby_file} for syntax errors...") -# result = shell_out("ruby -c #{ruby_file}") -# result.error! -# rescue Mixlib::ShellOut::ShellCommandFailed -# file_relative_path = ruby_file[/^#{Regexp.escape(cookbook_dir+File::Separator)}(.*)/, 1] -# Chef::Log.fatal("Cookbook file #{file_relative_path} has a syntax error:") -# result.stderr.each_line { |l| Chef::Log.fatal(l.chomp) } -# exit(1) -# end -# - require 'spec_helper' require "chef/cookbook/syntax_check" diff --git a/spec/unit/mixin/checksum_spec.rb b/spec/unit/mixin/checksum_spec.rb index dec270e18f..19af1c7d2b 100644 --- a/spec/unit/mixin/checksum_spec.rb +++ b/spec/unit/mixin/checksum_spec.rb @@ -27,12 +27,12 @@ end describe Chef::Mixin::Checksum do before(:each) do @checksum_user = Chef::CMCCheck.new - @cache = Chef::ChecksumCache.instance + @cache = Chef::Digester.instance @file = CHEF_SPEC_DATA + "/checksum/random.txt" @stat = mock("File::Stat", { :mtime => Time.at(0) }) File.stub!(:stat).and_return(@stat) end - + it "gets the checksum of a file" do @checksum_user.checksum(@file).should == "09ee9c8cc70501763563bcf9c218d71b2fbf4186bf8e1e0da07f0f42c80a3394" end -- cgit v1.2.1