diff options
author | Thom May <thom@chef.io> | 2017-03-21 10:31:40 +0000 |
---|---|---|
committer | Thom May <thom@chef.io> | 2017-04-04 07:18:09 +0100 |
commit | 8f62f18a24e3213ef4b2f13a5abf0135bf6c2429 (patch) | |
tree | 7e3073c1b9a7aeb1fd54b08a191ad3bfcf0674f0 /spec/unit | |
parent | e3b9e67a880bcd658517f90a6add837c0e026798 (diff) | |
download | chef-8f62f18a24e3213ef4b2f13a5abf0135bf6c2429.tar.gz |
RFC 67: Remove cookbook segments
This implements RFC 67, which removes cookbook segments, and moves to a
single list of all the files contained in a cookbook. This allows us to
move forward with better audit modes and also proper shipping of ohai
plugins.
Signed-off-by: Thom May <thom@chef.io>
Diffstat (limited to 'spec/unit')
-rw-r--r-- | spec/unit/client_spec.rb | 4 | ||||
-rw-r--r-- | spec/unit/cookbook/cookbook_version_loader_spec.rb | 41 | ||||
-rw-r--r-- | spec/unit/cookbook/file_vendor_spec.rb | 29 | ||||
-rw-r--r-- | spec/unit/cookbook/metadata_spec.rb | 5 | ||||
-rw-r--r-- | spec/unit/cookbook/synchronizer_spec.rb | 11 | ||||
-rw-r--r-- | spec/unit/cookbook_loader_spec.rb | 28 | ||||
-rw-r--r-- | spec/unit/cookbook_manifest_spec.rb | 56 | ||||
-rw-r--r-- | spec/unit/cookbook_site_streaming_uploader_spec.rb | 4 | ||||
-rw-r--r-- | spec/unit/cookbook_spec.rb | 24 | ||||
-rw-r--r-- | spec/unit/cookbook_uploader_spec.rb | 2 | ||||
-rw-r--r-- | spec/unit/cookbook_version_file_specificity_spec.rb | 83 | ||||
-rw-r--r-- | spec/unit/cookbook_version_spec.rb | 147 | ||||
-rw-r--r-- | spec/unit/http/socketless_chef_zero_client_spec.rb | 3 | ||||
-rw-r--r-- | spec/unit/knife/cookbook_download_spec.rb | 74 | ||||
-rw-r--r-- | spec/unit/knife/cookbook_show_spec.rb | 51 | ||||
-rw-r--r-- | spec/unit/policy_builder/policyfile_spec.rb | 24 | ||||
-rw-r--r-- | spec/unit/run_context/cookbook_compiler_spec.rb | 4 |
17 files changed, 269 insertions, 321 deletions
diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb index ec3f70b9b0..7ffc17c4fc 100644 --- a/spec/unit/client_spec.rb +++ b/spec/unit/client_spec.rb @@ -188,7 +188,7 @@ describe Chef::Client do # ---Client#sync_cookbooks -- downloads the list of cookbooks to sync # expect_any_instance_of(Chef::CookbookSynchronizer).to receive(:sync_cookbooks) - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(http_cookbook_sync) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], version_class: Chef::CookbookManifestVersions).and_return(http_cookbook_sync) expect(http_cookbook_sync).to receive(:post). with("environments/_default/cookbook_versions", { :run_list => ["override_recipe"] }). and_return({}) @@ -222,7 +222,7 @@ describe Chef::Client do # ---Client#sync_cookbooks -- downloads the list of cookbooks to sync # expect_any_instance_of(Chef::CookbookSynchronizer).to receive(:sync_cookbooks) - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(http_cookbook_sync) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], version_class: Chef::CookbookManifestVersions).and_return(http_cookbook_sync) expect(http_cookbook_sync).to receive(:post). with("environments/_default/cookbook_versions", { :run_list => ["new_run_list_recipe"] }). and_return({}) diff --git a/spec/unit/cookbook/cookbook_version_loader_spec.rb b/spec/unit/cookbook/cookbook_version_loader_spec.rb index 786e17f35b..40a054abee 100644 --- a/spec/unit/cookbook/cookbook_version_loader_spec.rb +++ b/spec/unit/cookbook/cookbook_version_loader_spec.rb @@ -40,42 +40,45 @@ describe Chef::Cookbook::CookbookVersionLoader do File.join(cookbook_path, cookbook_relative_path) end + def full_paths_for_part(part) + loaded_cookbook.files_for(part).inject([]) { |memo, f| memo << f[:full_path]; memo } + end + it "loads attribute files of the cookbook" do - expect(loaded_cookbook.attribute_filenames).to include(full_path("/attributes/default.rb")) - expect(loaded_cookbook.attribute_filenames).to include(full_path("/attributes/smokey.rb")) + expect(full_paths_for_part("attributes")).to include(full_path("/attributes/default.rb")) + expect(full_paths_for_part("attributes")).to include(full_path("/attributes/smokey.rb")) end it "loads definition files" do - expect(loaded_cookbook.definition_filenames).to include(full_path("/definitions/client.rb")) - expect(loaded_cookbook.definition_filenames).to include(full_path("/definitions/server.rb")) + expect(full_paths_for_part("definitions")).to include(full_path("/definitions/client.rb")) + expect(full_paths_for_part("definitions")).to include(full_path("/definitions/server.rb")) end it "loads recipes" do - expect(loaded_cookbook.recipe_filenames).to include(full_path("/recipes/default.rb")) - expect(loaded_cookbook.recipe_filenames).to include(full_path("/recipes/gigantor.rb")) - expect(loaded_cookbook.recipe_filenames).to include(full_path("/recipes/one.rb")) - expect(loaded_cookbook.recipe_filenames).to include(full_path("/recipes/return.rb")) + expect(full_paths_for_part("recipes")).to include(full_path("/recipes/default.rb")) + expect(full_paths_for_part("recipes")).to include(full_path("/recipes/gigantor.rb")) + expect(full_paths_for_part("recipes")).to include(full_path("/recipes/one.rb")) + expect(full_paths_for_part("recipes")).to include(full_path("/recipes/return.rb")) end it "loads libraries" do - expect(loaded_cookbook.library_filenames).to include(full_path("/libraries/openldap.rb")) - expect(loaded_cookbook.library_filenames).to include(full_path("/libraries/openldap/version.rb")) + expect(full_paths_for_part("libraries")).to include(full_path("/libraries/openldap.rb")) + expect(full_paths_for_part("libraries")).to include(full_path("/libraries/openldap/version.rb")) end it "loads static files in the files/ dir" do - expect(loaded_cookbook.file_filenames).to include(full_path("/files/default/remotedir/remotesubdir/remote_subdir_file1.txt")) - expect(loaded_cookbook.file_filenames).to include(full_path("/files/default/remotedir/remotesubdir/remote_subdir_file2.txt")) + expect(full_paths_for_part("files")).to include(full_path("/files/default/remotedir/remotesubdir/remote_subdir_file1.txt")) + expect(full_paths_for_part("files")).to include(full_path("/files/default/remotedir/remotesubdir/remote_subdir_file2.txt")) end it "loads files that start with a ." do - expect(loaded_cookbook.file_filenames).to include(full_path("/files/default/.dotfile")) - expect(loaded_cookbook.file_filenames).to include(full_path("/files/default/.ssh/id_rsa")) - expect(loaded_cookbook.file_filenames).to include(full_path("/files/default/remotedir/.a_dotdir/.a_dotfile_in_a_dotdir")) + expect(full_paths_for_part("files")).to include(full_path("/files/default/.dotfile")) + expect(full_paths_for_part("files")).to include(full_path("/files/default/.ssh/id_rsa")) + expect(full_paths_for_part("files")).to include(full_path("/files/default/remotedir/.a_dotdir/.a_dotfile_in_a_dotdir")) end it "loads root files that start with a ." do expect(loaded_cookbook.all_files).to include(full_path(".root_dotfile")) - expect(loaded_cookbook.root_filenames).to include(full_path(".root_dotfile")) end it "loads all unignored files, even if they don't match a segment type" do @@ -97,9 +100,9 @@ describe Chef::Cookbook::CookbookVersionLoader do let(:cookbook_path) { File.join(CHEF_SPEC_DATA, "kitchen/openldap") } it "skips ignored files" do - expect(loaded_cookbook.recipe_filenames).to include(full_path("recipes/gigantor.rb")) - expect(loaded_cookbook.recipe_filenames).to include(full_path("recipes/woot.rb")) - expect(loaded_cookbook.recipe_filenames).to_not include(full_path("recipes/ignoreme.rb")) + expect(full_paths_for_part("recipes")).to include(full_path("recipes/gigantor.rb")) + expect(full_paths_for_part("recipes")).to include(full_path("recipes/woot.rb")) + expect(full_paths_for_part("recipes")).to_not include(full_path("recipes/ignoreme.rb")) end end diff --git a/spec/unit/cookbook/file_vendor_spec.rb b/spec/unit/cookbook/file_vendor_spec.rb index 164fbd8177..557e1b8775 100644 --- a/spec/unit/cookbook/file_vendor_spec.rb +++ b/spec/unit/cookbook/file_vendor_spec.rb @@ -16,6 +16,7 @@ # limitations under the License. # require "spec_helper" +require "chef/cookbook_version" describe Chef::Cookbook::FileVendor do @@ -25,6 +26,12 @@ describe Chef::Cookbook::FileVendor do let(:http) { double("Chef::ServerAPI") } + # A manifest is a Hash of the format defined by Chef::CookbookVersion#manifest + let(:manifest) do + cbv = Chef::CookbookVersion.new("bob", Array(Dir.tmpdir)) + cbv.cookbook_manifest + end + before do file_vendor_class.fetch_from_remote(http) end @@ -39,8 +46,11 @@ describe Chef::Cookbook::FileVendor do context "with a manifest from a cookbook version" do - # A manifest is a Hash of the format defined by Chef::CookbookVersion#manifest - let(:manifest) { { :cookbook_name => "bob", :name => "bob-1.2.3" } } + # # A manifest is a Hash of the format defined by Chef::CookbookVersion#manifest + # let(:manifest) do + # cbv = Chef::CookbookVersion.new("bob", Array(Dir.tmpdir)) + # cbv.cookbook_manifest + # end it "creates a RemoteFileVendor for a given manifest" do file_vendor = file_vendor_class.create_from_manifest(manifest) @@ -53,9 +63,6 @@ describe Chef::Cookbook::FileVendor do context "with a manifest from a cookbook artifact" do - # A manifest is a Hash of the format defined by Chef::CookbookVersion#manifest - let(:manifest) { { :name => "bob" } } - it "creates a RemoteFileVendor for a given manifest" do file_vendor = file_vendor_class.create_from_manifest(manifest) expect(file_vendor).to be_a_kind_of(Chef::Cookbook::RemoteFileVendor) @@ -70,8 +77,10 @@ describe Chef::Cookbook::FileVendor do let(:cookbook_path) { %w{/var/chef/cookbooks /var/chef/other_cookbooks} } - # A manifest is a Hash of the format defined by Chef::CookbookVersion#manifest - let(:manifest) { { :cookbook_name => "bob" } } + let(:manifest) do + cbv = Chef::CookbookVersion.new("bob", Array(Dir.tmpdir)) + cbv.cookbook_manifest + end before do file_vendor_class.fetch_from_disk(cookbook_path) @@ -97,8 +106,10 @@ describe Chef::Cookbook::FileVendor do context "when vendoring a cookbook with a name mismatch" do let(:cookbook_path) { File.join(CHEF_SPEC_DATA, "cookbooks") } - # A manifest is a Hash of the format defined by Chef::CookbookVersion#manifest - let(:manifest) { { :cookbook_name => "name-mismatch" } } + let(:manifest) do + cbv = Chef::CookbookVersion.new("name-mismatch", Array(Dir.tmpdir)) + cbv.cookbook_manifest + end before do file_vendor_class.fetch_from_disk(cookbook_path) diff --git a/spec/unit/cookbook/metadata_spec.rb b/spec/unit/cookbook/metadata_spec.rb index d1117127f1..4a18244ea0 100644 --- a/spec/unit/cookbook/metadata_spec.rb +++ b/spec/unit/cookbook/metadata_spec.rb @@ -765,7 +765,10 @@ describe Chef::Cookbook::Metadata do describe "recipes" do let(:cookbook) do c = Chef::CookbookVersion.new("test_cookbook") - c.recipe_files = [ "default.rb", "enlighten.rb" ] + c.manifest = { all_files: [ + { name: "recipes/default.rb", path: "recipes/default.rb", checksum: "my_only_friend" }, + { name: "recipes/enlighten.rb", path: "recipes/enlighten.rb", checksum: "my_only_friend" }, + ] } c end diff --git a/spec/unit/cookbook/synchronizer_spec.rb b/spec/unit/cookbook/synchronizer_spec.rb index 82876273e7..77e64482da 100644 --- a/spec/unit/cookbook/synchronizer_spec.rb +++ b/spec/unit/cookbook/synchronizer_spec.rb @@ -62,6 +62,7 @@ describe Chef::CookbookSynchronizer do let(:cookbook_a_default_recipe) do { "path" => "recipes/default.rb", + "name" => "recipes/default.rb", "url" => "http://chef.example.com/abc123", "checksum" => "abc123", } @@ -70,6 +71,7 @@ describe Chef::CookbookSynchronizer do let(:cookbook_a_default_attrs) do { "path" => "attributes/default.rb", + "name" => "attributes/default.rb", "url" => "http://chef.example.com/abc456", "checksum" => "abc456", } @@ -78,6 +80,7 @@ describe Chef::CookbookSynchronizer do let(:cookbook_a_template) do { "path" => "templates/default/apache2.conf.erb", + "name" => "templates/apache2.conf.erb", "url" => "http://chef.example.com/ffffff", "checksum" => "abc125", } @@ -86,18 +89,14 @@ describe Chef::CookbookSynchronizer do let(:cookbook_a_file) do { "path" => "files/default/megaman.conf", + "name" => "files/megaman.conf", "url" => "http://chef.example.com/megaman.conf", "checksum" => "abc124", } end let(:cookbook_a_manifest) do - segments = [ :resources, :providers, :recipes, :definitions, :libraries, :attributes, :files, :templates, :root_files ] - cookbook_a_manifest = segments.inject({}) { |h, segment| h[segment.to_s] = []; h } - cookbook_a_manifest["recipes"] = [ cookbook_a_default_recipe ] - cookbook_a_manifest["attributes"] = [ cookbook_a_default_attrs ] - cookbook_a_manifest["templates"] = [ cookbook_a_template ] - cookbook_a_manifest["files"] = [ cookbook_a_file ] + cookbook_a_manifest = { all_files: [ cookbook_a_default_recipe, cookbook_a_default_attrs, cookbook_a_template, cookbook_a_file ] } cookbook_a_manifest end diff --git a/spec/unit/cookbook_loader_spec.rb b/spec/unit/cookbook_loader_spec.rb index eef5d2afd5..dd731b53d3 100644 --- a/spec/unit/cookbook_loader_spec.rb +++ b/spec/unit/cookbook_loader_spec.rb @@ -31,6 +31,10 @@ describe Chef::CookbookLoader do let(:cookbook_loader) { Chef::CookbookLoader.new(repo_paths) } + def full_paths_for_part(cb, part) + cookbook_loader[cb].files_for(part).inject([]) { |memo, f| memo << f[:full_path]; memo } + end + it "checks each directory only once when loading (CHEF-3487)" do cookbook_paths = [] repo_paths.each do |repo_path| @@ -112,61 +116,61 @@ describe Chef::CookbookLoader do end it "should allow you to override an attribute file via cookbook_path" do - expect(cookbook_loader[:openldap].attribute_filenames.detect do |f| + expect(full_paths_for_part(:openldap, "attributes").detect do |f| f =~ /cookbooks\/openldap\/attributes\/default.rb/ end).not_to eql(nil) - expect(cookbook_loader[:openldap].attribute_filenames.detect do |f| + expect(full_paths_for_part(:openldap, "attributes").detect do |f| f =~ /kitchen\/openldap\/attributes\/default.rb/ end).to eql(nil) end it "should load different attribute files from deeper paths" do - expect(cookbook_loader[:openldap].attribute_filenames.detect do |f| + expect(full_paths_for_part(:openldap, "attributes").detect do |f| f =~ /kitchen\/openldap\/attributes\/robinson.rb/ end).not_to eql(nil) end it "should allow you to override a definition file via cookbook_path" do - expect(cookbook_loader[:openldap].definition_filenames.detect do |f| + expect(full_paths_for_part(:openldap, "definitions").detect do |f| f =~ /cookbooks\/openldap\/definitions\/client.rb/ end).not_to eql(nil) - expect(cookbook_loader[:openldap].definition_filenames.detect do |f| + expect(full_paths_for_part(:openldap, "definitions").detect do |f| f =~ /kitchen\/openldap\/definitions\/client.rb/ end).to eql(nil) end it "should load definition files from deeper paths" do - expect(cookbook_loader[:openldap].definition_filenames.detect do |f| + expect(full_paths_for_part(:openldap, "definitions").detect do |f| f =~ /kitchen\/openldap\/definitions\/drewbarrymore.rb/ end).not_to eql(nil) end it "should allow you to override a recipe file via cookbook_path" do - expect(cookbook_loader[:openldap].recipe_filenames.detect do |f| + expect(full_paths_for_part(:openldap, "recipes").detect do |f| f =~ /cookbooks\/openldap\/recipes\/gigantor.rb/ end).not_to eql(nil) - expect(cookbook_loader[:openldap].recipe_filenames.detect do |f| + expect(full_paths_for_part(:openldap, "recipes").detect do |f| f =~ /kitchen\/openldap\/recipes\/gigantor.rb/ end).to eql(nil) end it "should load recipe files from deeper paths" do - expect(cookbook_loader[:openldap].recipe_filenames.detect do |f| + expect(full_paths_for_part(:openldap, "recipes").detect do |f| f =~ /kitchen\/openldap\/recipes\/woot.rb/ end).not_to eql(nil) end it "should allow you to have an 'ignore' file, which skips loading files in later cookbooks" do - expect(cookbook_loader[:openldap].recipe_filenames.detect do |f| + expect(full_paths_for_part(:openldap, "recipes").detect do |f| f =~ /kitchen\/openldap\/recipes\/ignoreme.rb/ end).to eql(nil) end it "should find files that start with a ." do - expect(cookbook_loader[:openldap].file_filenames.detect do |f| + expect(full_paths_for_part(:openldap, "files").detect do |f| f =~ /\.dotfile$/ end).to match(/\.dotfile$/) - expect(cookbook_loader[:openldap].file_filenames.detect do |f| + expect(full_paths_for_part(:openldap, "files").detect do |f| f =~ /\.ssh\/id_rsa$/ end).to match(/\.ssh\/id_rsa$/) end diff --git a/spec/unit/cookbook_manifest_spec.rb b/spec/unit/cookbook_manifest_spec.rb index acf0ade9f9..d77c07e0f7 100644 --- a/spec/unit/cookbook_manifest_spec.rb +++ b/spec/unit/cookbook_manifest_spec.rb @@ -81,11 +81,6 @@ describe Chef::CookbookManifest do expect(cookbook_manifest.frozen_version?).to be(false) end - it "delegates `segment_filenames' to cookbook_version" do - expect(cookbook_version).to receive(:segment_filenames).with(:recipes).and_return([]) - expect(cookbook_manifest.segment_filenames(:recipes)).to eq([]) - end - end context "when given an empty cookbook" do @@ -101,15 +96,7 @@ describe Chef::CookbookManifest do "frozen?" => false, - "recipes" => [], - "definitions" => [], - "libraries" => [], - "attributes" => [], - "files" => [], - "templates" => [], - "resources" => [], - "providers" => [], - "root_files" => [], + "all_files" => [], } end @@ -123,16 +110,7 @@ describe Chef::CookbookManifest do let(:cookbook_root) { File.join(CHEF_SPEC_DATA, "cb_version_cookbooks", "tatft") } - let(:attribute_filenames) { Dir[File.join(cookbook_root, "attributes", "**", "*.rb")] } - let(:definition_filenames) { Dir[File.join(cookbook_root, "definitions", "**", "*.rb")] } - let(:file_filenames) { Dir[File.join(cookbook_root, "files", "**", "*.tgz")] } - let(:recipe_filenames) { Dir[File.join(cookbook_root, "recipes", "**", "*.rb")] } - let(:template_filenames) { Dir[File.join(cookbook_root, "templates", "**", "*.erb")] } - let(:library_filenames) { Dir[File.join(cookbook_root, "libraries", "**", "*.rb")] } - let(:resource_filenames) { Dir[File.join(cookbook_root, "resources", "**", "*.rb")] } - let(:provider_filenames) { Dir[File.join(cookbook_root, "providers", "**", "*.rb")] } - let(:root_filenames) { Array(File.join(cookbook_root, "README.rdoc")) } - let(:metadata_filenames) { Array(File.join(cookbook_root, "metadata.json")) } + let(:all_files) { Dir[File.join(cookbook_root, "**", "**")].reject { |f| File.directory? f } } let(:match_md5) { /[0-9a-f]{32}/ } @@ -141,8 +119,15 @@ describe Chef::CookbookManifest do relative_path = Pathname.new(path).relative_path_from(Pathname.new(cookbook_root)).to_s + parts = relative_path.split("/") + name = if %w{templates files}.include?(parts[0]) && parts.length == 3 + File.join(parts[0], parts[2]) + else + relative_path + end + { - "name" => File.basename(path), + "name" => name, "path" => relative_path, "checksum" => Chef::Digester.generate_md5_checksum_for_file(path), "specificity" => "default", @@ -161,29 +146,12 @@ describe Chef::CookbookManifest do "frozen?" => false, - "recipes" => map_to_file_specs(recipe_filenames), - "definitions" => map_to_file_specs(definition_filenames), - "libraries" => map_to_file_specs(library_filenames), - "attributes" => map_to_file_specs(attribute_filenames), - "files" => map_to_file_specs(file_filenames), - "templates" => map_to_file_specs(template_filenames), - "resources" => map_to_file_specs(resource_filenames), - "providers" => map_to_file_specs(provider_filenames), - "root_files" => map_to_file_specs(root_filenames), + "all_files" => map_to_file_specs(all_files), } end before do - cookbook_version.attribute_filenames = attribute_filenames - cookbook_version.definition_filenames = definition_filenames - cookbook_version.file_filenames = file_filenames - cookbook_version.recipe_filenames = recipe_filenames - cookbook_version.template_filenames = template_filenames - cookbook_version.library_filenames = library_filenames - cookbook_version.resource_filenames = resource_filenames - cookbook_version.provider_filenames = provider_filenames - cookbook_version.root_filenames = root_filenames - cookbook_version.metadata_filenames = metadata_filenames + cookbook_version.all_files = all_files end it "converts the CookbookVersion to a ruby Hash representation" do diff --git a/spec/unit/cookbook_site_streaming_uploader_spec.rb b/spec/unit/cookbook_site_streaming_uploader_spec.rb index 10963386dd..0e9c277b11 100644 --- a/spec/unit/cookbook_site_streaming_uploader_spec.rb +++ b/spec/unit/cookbook_site_streaming_uploader_spec.rb @@ -49,10 +49,6 @@ describe Chef::CookbookSiteStreamingUploader do cookbook = @loader[:openldap] files_count = Dir.glob(File.join(@cookbook_repo, cookbook.name.to_s, "**", "*"), File::FNM_DOTMATCH).count { |file| File.file?(file) } - # The fixture cookbook contains a spec/spec_helper.rb file, which is not - # a part of any cookbook segment, so it is not uploaded. - files_count -= 1 - expect(Tempfile).to receive(:new).with("chef-#{cookbook.name}-build").and_return(FakeTempfile.new("chef-#{cookbook.name}-build")) expect(FileUtils).to receive(:mkdir_p).exactly(files_count + 1).times expect(FileUtils).to receive(:cp).exactly(files_count).times diff --git a/spec/unit/cookbook_spec.rb b/spec/unit/cookbook_spec.rb index 33b4a3ccd8..ac3a1373ea 100644 --- a/spec/unit/cookbook_spec.rb +++ b/spec/unit/cookbook_spec.rb @@ -19,7 +19,8 @@ require "spec_helper" describe Chef::CookbookVersion do -# COOKBOOK_PATH = File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "cookbooks", "openldap")) + COOKBOOK_PATH = File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "cookbooks", "openldap")) + before(:each) do @cookbook_repo = File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "cookbooks")) cl = Chef::CookbookLoader.new(@cookbook_repo) @@ -37,26 +38,21 @@ describe Chef::CookbookVersion do end it "should allow you to set the list of attribute files and create the mapping from short names to paths" do - @cookbook.attribute_filenames = [ "attributes/one.rb", "attributes/two.rb" ] - expect(@cookbook.attribute_filenames).to eq([ "attributes/one.rb", "attributes/two.rb" ]) - expect(@cookbook.attribute_filenames_by_short_filename.keys.sort).to eql(%w{one two}) - expect(@cookbook.attribute_filenames_by_short_filename["one"]).to eq("attributes/one.rb") - expect(@cookbook.attribute_filenames_by_short_filename["two"]).to eq("attributes/two.rb") + expect(@cookbook.attribute_filenames_by_short_filename.keys.sort).to eql(%w{default smokey}) + expect(@cookbook.attribute_filenames_by_short_filename["default"]).to eq(File.join(COOKBOOK_PATH, "attributes/default.rb")) + expect(@cookbook.attribute_filenames_by_short_filename["smokey"]).to eq(File.join(COOKBOOK_PATH, "attributes/smokey.rb")) end it "should allow you to set the list of recipe files and create the mapping of recipe short name to filename" do - @cookbook.recipe_filenames = [ "recipes/one.rb", "recipes/two.rb" ] - expect(@cookbook.recipe_filenames).to eq([ "recipes/one.rb", "recipes/two.rb" ]) - expect(@cookbook.recipe_filenames_by_name.keys.sort).to eql(%w{one two}) - expect(@cookbook.recipe_filenames_by_name["one"]).to eq("recipes/one.rb") - expect(@cookbook.recipe_filenames_by_name["two"]).to eq("recipes/two.rb") + expect(@cookbook.recipe_filenames_by_name.keys.sort).to eql(%w{default gigantor one return}) + expect(@cookbook.recipe_filenames_by_name["one"]).to eq(File.join(COOKBOOK_PATH, "recipes/one.rb")) + expect(@cookbook.recipe_filenames_by_name["gigantor"]).to eq(File.join(COOKBOOK_PATH, "recipes/gigantor.rb")) end it "should generate a list of recipes by fully-qualified name" do - @cookbook.recipe_filenames = [ "recipes/one.rb", "/recipes/two.rb", "three.rb" ] expect(@cookbook.fully_qualified_recipe_names.include?("openldap::one")).to eq(true) - expect(@cookbook.fully_qualified_recipe_names.include?("openldap::two")).to eq(true) - expect(@cookbook.fully_qualified_recipe_names.include?("openldap::three")).to eq(true) + expect(@cookbook.fully_qualified_recipe_names.include?("openldap::gigantor")).to eq(true) + expect(@cookbook.fully_qualified_recipe_names.include?("openldap::return")).to eq(true) end it "should raise an ArgumentException if you try to load a bad recipe name" do diff --git a/spec/unit/cookbook_uploader_spec.rb b/spec/unit/cookbook_uploader_spec.rb index c30df71e34..2c36c2c9c7 100644 --- a/spec/unit/cookbook_uploader_spec.rb +++ b/spec/unit/cookbook_uploader_spec.rb @@ -65,7 +65,7 @@ describe Chef::CookbookUploader do it "creates an HTTP client with default configuration when not initialized with one" do default_http_client = double("Chef::ServerAPI") - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(default_http_client) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], version_class: Chef::CookbookManifestVersions).and_return(default_http_client) uploader = described_class.new(cookbooks_to_upload) expect(uploader.rest).to eq(default_http_client) end diff --git a/spec/unit/cookbook_version_file_specificity_spec.rb b/spec/unit/cookbook_version_file_specificity_spec.rb index 3b5450cb2d..ba7aaa59f5 100644 --- a/spec/unit/cookbook_version_file_specificity_spec.rb +++ b/spec/unit/cookbook_version_file_specificity_spec.rb @@ -23,177 +23,204 @@ describe Chef::CookbookVersion, "file specificity" do before(:each) do @cookbook = Chef::CookbookVersion.new("test-cookbook", "/cookbook-folder") @cookbook.manifest = { - "files" => + "all_files" => [ # afile.rb { - :name => "afile.rb", + :name => "files/afile.rb", :path => "files/host-examplehost.example.org/afile.rb", + :full_path => "/cookbook-folder/files/host-examplehost.example.org/afile.rb", :checksum => "csum-host", :specificity => "host-examplehost.example.org", }, { - :name => "afile.rb", + :name => "files/afile.rb", :path => "files/ubuntu-9.10/afile.rb", + :full_path => "/cookbook-folder/files/ubuntu-9.10/afile.rb", :checksum => "csum-platver-full", :specificity => "ubuntu-9.10", }, { - :name => "afile.rb", + :name => "files/afile.rb", :path => "files/newubuntu-9/afile.rb", + :full_path => "/cookbook-folder/files/newubuntu-9/afile.rb", :checksum => "csum-platver-partial", :specificity => "newubuntu-9", }, { - :name => "afile.rb", + :name => "files/afile.rb", :path => "files/ubuntu/afile.rb", + :full_path => "/cookbook-folder/files/ubuntu/afile.rb", :checksum => "csum-plat", :specificity => "ubuntu", }, { - :name => "afile.rb", + :name => "files/afile.rb", :path => "files/default/afile.rb", + :full_path => "/cookbook-folder/files/default/afile.rb", :checksum => "csum-default", :specificity => "default", }, # for different/odd platform_versions { - :name => "bfile.rb", + :name => "files/bfile.rb", :path => "files/fakeos-2.0.rc.1/bfile.rb", + :full_path => "/cookbook-folder/files/fakeos-2.0.rc.1/bfile.rb", :checksum => "csum2-platver-full", :specificity => "fakeos-2.0.rc.1", }, { - :name => "bfile.rb", + :name => "files/bfile.rb", :path => "files/newfakeos-2.0.rc/bfile.rb", + :full_path => "/cookbook-folder/files/newfakeos-2.0.rc/bfile.rb", :checksum => "csum2-platver-partial", :specificity => "newfakeos-2.0.rc", }, { - :name => "bfile.rb", + :name => "files/bfile.rb", :path => "files/fakeos-maple tree/bfile.rb", + :full_path => "/cookbook-folder/files/fakeos-maple tree/bfile.rb", :checksum => "csum3-platver-full", :specificity => "maple tree", }, { - :name => "bfile.rb", + :name => "files/bfile.rb", :path => "files/fakeos-1/bfile.rb", + :full_path => "/cookbook-folder/files/fakeos-1/bfile.rb", :checksum => "csum4-platver-full", :specificity => "fakeos-1", }, # directory adirectory { - :name => "anotherfile1.rb", + :name => "files/anotherfile1.rb", :path => "files/host-examplehost.example.org/adirectory/anotherfile1.rb.host", + :full_path => "/cookbook-folder/files/host-examplehost.example.org/adirectory/anotherfile1.rb.host", :checksum => "csum-host-1", :specificity => "host-examplehost.example.org", }, { - :name => "anotherfile2.rb", + :name => "files/anotherfile2.rb", :path => "files/host-examplehost.example.org/adirectory/anotherfile2.rb.host", + :full_path => "/cookbook-folder/files/host-examplehost.example.org/adirectory/anotherfile2.rb.host", :checksum => "csum-host-2", :specificity => "host-examplehost.example.org", }, { - :name => "anotherfile1.rb", + :name => "files/anotherfile1.rb", :path => "files/ubuntu-9.10/adirectory/anotherfile1.rb.platform-full-version", + :full_path => "/cookbook-folder/files/ubuntu-9.10/adirectory/anotherfile1.rb.platform-full-version", :checksum => "csum-platver-full-1", :specificity => "ubuntu-9.10", }, { - :name => "anotherfile2.rb", + :name => "files/anotherfile2.rb", :path => "files/ubuntu-9.10/adirectory/anotherfile2.rb.platform-full-version", + :full_path => "/cookbook-folder/files/ubuntu-9.10/adirectory/anotherfile2.rb.platform-full-version", :checksum => "csum-platver-full-2", :specificity => "ubuntu-9.10", }, { - :name => "anotherfile1.rb", + :name => "files/anotherfile1.rb", :path => "files/newubuntu-9/adirectory/anotherfile1.rb.platform-partial-version", + :full_path => "/cookbook-folder/files/newubuntu-9/adirectory/anotherfile1.rb.platform-partial-version", :checksum => "csum-platver-partial-1", :specificity => "newubuntu-9", }, { - :name => "anotherfile2.rb", + :name => "files/anotherfile2.rb", :path => "files/newubuntu-9/adirectory/anotherfile2.rb.platform-partial-version", + :full_path => "/cookbook-folder/files/newubuntu-9/adirectory/anotherfile2.rb.platform-partial-version", :checksum => "csum-platver-partial-2", :specificity => "nweubuntu-9", }, { - :name => "anotherfile1.rb", + :name => "files/anotherfile1.rb", :path => "files/ubuntu/adirectory/anotherfile1.rb.platform", + :full_path => "/cookbook-folder/files/ubuntu/adirectory/anotherfile1.rb.platform", :checksum => "csum-plat-1", :specificity => "ubuntu", }, { - :name => "anotherfile2.rb", + :name => "files/anotherfile2.rb", :path => "files/ubuntu/adirectory/anotherfile2.rb.platform", + :full_path => "/cookbook-folder/files/ubuntu/adirectory/anotherfile2.rb.platform", :checksum => "csum-plat-2", :specificity => "ubuntu", }, { - :name => "anotherfile1.rb", + :name => "files/anotherfile1.rb", :path => "files/default/adirectory/anotherfile1.rb.default", + :full_path => "/cookbook-folder/files/default/adirectory/anotherfile1.rb.default", :checksum => "csum-default-1", :specificity => "default", }, { - :name => "anotherfile2.rb", + :name => "files/anotherfile2.rb", :path => "files/default/adirectory/anotherfile2.rb.default", + :full_path => "/cookbook-folder/files/default/adirectory/anotherfile2.rb.default", :checksum => "csum-default-2", :specificity => "default", }, # for different/odd platform_versions { - :name => "anotherfile1.rb", + :name => "files/anotherfile1.rb", :path => "files/fakeos-2.0.rc.1/adirectory/anotherfile1.rb.platform-full-version", + :full_path => "/cookbook-folder/files/fakeos-2.0.rc.1/adirectory/anotherfile1.rb.platform-full-version", :checksum => "csum2-platver-full-1", :specificity => "fakeos-2.0.rc.1", }, { - :name => "anotherfile2.rb", + :name => "files/anotherfile2.rb", :path => "files/fakeos-2.0.rc.1/adirectory/anotherfile2.rb.platform-full-version", + :full_path => "/cookbook-folder/files/fakeos-2.0.rc.1/adirectory/anotherfile2.rb.platform-full-version", :checksum => "csum2-platver-full-2", :specificity => "fakeos-2.0.rc.1", }, { - :name => "anotherfile1.rb", + :name => "files/anotherfile1.rb", :path => "files/newfakeos-2.0.rc.1/adirectory/anotherfile1.rb.platform-partial-version", + :full_path => "/cookbook-folder/files/newfakeos-2.0.rc.1/adirectory/anotherfile1.rb.platform-partial-version", :checksum => "csum2-platver-partial-1", :specificity => "newfakeos-2.0.rc", }, { - :name => "anotherfile2.rb", + :name => "files/anotherfile2.rb", :path => "files/newfakeos-2.0.rc.1/adirectory/anotherfile2.rb.platform-partial-version", + :full_path => "/cookbook-folder/files/newfakeos-2.0.rc.1/adirectory/anotherfile2.rb.platform-partial-version", :checksum => "csum2-platver-partial-2", :specificity => "newfakeos-2.0.rc", }, { - :name => "anotherfile1.rb", + :name => "files/anotherfile1.rb", :path => "files/fakeos-maple tree/adirectory/anotherfile1.rb.platform-full-version", + :full_path => "/cookbook-folder/files/fakeos-maple tree/adirectory/anotherfile1.rb.platform-full-version", :checksum => "csum3-platver-full-1", :specificity => "fakeos-maple tree", }, { - :name => "anotherfile2.rb", + :name => "files/anotherfile2.rb", :path => "files/fakeos-maple tree/adirectory/anotherfile2.rb.platform-full-version", + :full_path => "/cookbook-folder/files/fakeos-maple tree/adirectory/anotherfile2.rb.platform-full-version", :checksum => "csum3-platver-full-2", :specificity => "fakeos-maple tree", }, { - :name => "anotherfile1.rb", + :name => "files/anotherfile1.rb", :path => "files/fakeos-1/adirectory/anotherfile1.rb.platform-full-version", + :full_path => "/cookbook-folder/files/fakeos-1/adirectory/anotherfile1.rb.platform-full-version", :checksum => "csum4-platver-full-1", :specificity => "fakeos-1", }, { - :name => "anotherfile2.rb", + :name => "files/anotherfile2.rb", :path => "files/fakeos-1/adirectory/anotherfile2.rb.platform-full-version", + :full_path => "/cookbook-folder/files/fakeos-1/adirectory/anotherfile2.rb.platform-full-version", :checksum => "csum4-platver-full-2", :specificity => "fakeos-1", }, diff --git a/spec/unit/cookbook_version_spec.rb b/spec/unit/cookbook_version_spec.rb index 81ea161bfe..83fb3f578f 100644 --- a/spec/unit/cookbook_version_spec.rb +++ b/spec/unit/cookbook_version_spec.rb @@ -25,38 +25,6 @@ describe Chef::CookbookVersion do expect(cookbook_version.name).to eq("tatft") end - it "has no attribute files" do - expect(cookbook_version.attribute_filenames).to be_empty - end - - it "has no resource definition files" do - expect(cookbook_version.definition_filenames).to be_empty - end - - it "has no cookbook files" do - expect(cookbook_version.file_filenames).to be_empty - end - - it "has no recipe files" do - expect(cookbook_version.recipe_filenames).to be_empty - end - - it "has no library files" do - expect(cookbook_version.library_filenames).to be_empty - end - - it "has no LWRP resource files" do - expect(cookbook_version.resource_filenames).to be_empty - end - - it "has no LWRP provider files" do - expect(cookbook_version.provider_filenames).to be_empty - end - - it "has no metadata files" do - expect(cookbook_version.metadata_filenames).to be_empty - end - it "has an empty set of all_files" do expect(cookbook_version.all_files).to be_empty end @@ -82,17 +50,7 @@ describe Chef::CookbookVersion do let(:cookbook_paths_by_type) do { # Dunno if the paths here are representitive of what is set by CookbookLoader... - all_files: Dir[File.join(cookbook_root, "**", "*.rb")], - attribute_filenames: Dir[File.join(cookbook_root, "attributes", "**", "*.rb")], - definition_filenames: Dir[File.join(cookbook_root, "definitions", "**", "*.rb")], - file_filenames: Dir[File.join(cookbook_root, "files", "**", "*.tgz")], - recipe_filenames: Dir[File.join(cookbook_root, "recipes", "**", "*.rb")], - template_filenames: Dir[File.join(cookbook_root, "templates", "**", "*.erb")], - library_filenames: Dir[File.join(cookbook_root, "libraries", "**", "*.rb")], - resource_filenames: Dir[File.join(cookbook_root, "resources", "**", "*.rb")], - provider_filenames: Dir[File.join(cookbook_root, "providers", "**", "*.rb")], - root_filenames: Array(File.join(cookbook_root, "README.rdoc")), - metadata_filenames: Array(File.join(cookbook_root, "metadata.json")), + all_files: Dir[File.join(cookbook_root, "**", "**")], } end @@ -102,18 +60,9 @@ describe Chef::CookbookVersion do let(:cookbook_version) do Chef::CookbookVersion.new("tatft", cookbook_root).tap do |c| - # Currently the cookbook loader finds all the files then tells CookbookVersion - # where they are. - c.attribute_filenames = cookbook_paths_by_type[:attribute_filenames] - c.definition_filenames = cookbook_paths_by_type[:definition_filenames] - c.recipe_filenames = cookbook_paths_by_type[:recipe_filenames] - c.template_filenames = cookbook_paths_by_type[:template_filenames] - c.file_filenames = cookbook_paths_by_type[:file_filenames] - c.library_filenames = cookbook_paths_by_type[:library_filenames] - c.resource_filenames = cookbook_paths_by_type[:resource_filenames] - c.provider_filenames = cookbook_paths_by_type[:provider_filenames] - c.root_filenames = cookbook_paths_by_type[:root_filenames] - c.metadata_filenames = cookbook_paths_by_type[:metadata_filenames] + # Currently the cookbook loader finds all the files then tells CookbookVersion + # where they are. + c.all_files = cookbook_paths_by_type[:all_files] end end @@ -168,18 +117,7 @@ describe Chef::CookbookVersion do let(:cookbook_paths_by_type) do { - # Dunno if the paths here are representitive of what is set by CookbookLoader... - all_files: Dir[File.join(cookbook_root, "**", "*.rb")], - attribute_filenames: Dir[File.join(cookbook_root, "attributes", "**", "*.rb")], - definition_filenames: Dir[File.join(cookbook_root, "definitions", "**", "*.rb")], - file_filenames: Dir[File.join(cookbook_root, "files", "**", "*.*")], - recipe_filenames: Dir[File.join(cookbook_root, "recipes", "**", "*.rb")], - template_filenames: Dir[File.join(cookbook_root, "templates", "**", "*.*")], - library_filenames: Dir[File.join(cookbook_root, "libraries", "**", "*.rb")], - resource_filenames: Dir[File.join(cookbook_root, "resources", "**", "*.rb")], - provider_filenames: Dir[File.join(cookbook_root, "providers", "**", "*.rb")], - root_filenames: Array(File.join(cookbook_root, "README.rdoc")), - metadata_filenames: Array(File.join(cookbook_root, "metadata.json")), + all_files: Dir[File.join(cookbook_root, "**", "**")], } end @@ -187,16 +125,7 @@ describe Chef::CookbookVersion do let(:cookbook_version) do Chef::CookbookVersion.new("cookbook2", cookbook_root).tap do |c| - c.attribute_filenames = cookbook_paths_by_type[:attribute_filenames] - c.definition_filenames = cookbook_paths_by_type[:definition_filenames] - c.recipe_filenames = cookbook_paths_by_type[:recipe_filenames] - c.template_filenames = cookbook_paths_by_type[:template_filenames] - c.file_filenames = cookbook_paths_by_type[:file_filenames] - c.library_filenames = cookbook_paths_by_type[:library_filenames] - c.resource_filenames = cookbook_paths_by_type[:resource_filenames] - c.provider_filenames = cookbook_paths_by_type[:provider_filenames] - c.root_filenames = cookbook_paths_by_type[:root_filenames] - c.metadata_filenames = cookbook_paths_by_type[:metadata_filenames] + c.all_files = cookbook_paths_by_type[:all_files] end end @@ -255,19 +184,19 @@ describe Chef::CookbookVersion do it "should sort based on the version number" do examples = [ - # smaller, larger - ["1.0", "2.0"], - ["1.2.3", "1.2.4"], - ["1.2.3", "1.3.0"], - ["1.2.3", "1.3"], - ["1.2.3", "2.1.1"], - ["1.2.3", "2.1"], - ["1.2", "1.2.4"], - ["1.2", "1.3.0"], - ["1.2", "1.3"], - ["1.2", "2.1.1"], - ["1.2", "2.1"], - ] + # smaller, larger + ["1.0", "2.0"], + ["1.2.3", "1.2.4"], + ["1.2.3", "1.3.0"], + ["1.2.3", "1.3"], + ["1.2.3", "2.1.1"], + ["1.2.3", "2.1"], + ["1.2", "1.2.4"], + ["1.2", "1.3.0"], + ["1.2", "1.3"], + ["1.2", "2.1.1"], + ["1.2", "2.1"], + ] examples.each do |smaller, larger| sm = Chef::CookbookVersion.new("foo", "/tmp/blah") lg = Chef::CookbookVersion.new("foo", "/tmp/blah") @@ -318,42 +247,4 @@ describe Chef::CookbookVersion do end - describe "when deprecation warnings are errors" do - - subject(:cbv) { Chef::CookbookVersion.new("version validation", "/tmp/blah") } - - it "errors on #status and #status=" do - expect { cbv.status = :wat }.to raise_error(Chef::Exceptions::DeprecatedFeatureError) - expect { cbv.status }.to raise_error(Chef::Exceptions::DeprecatedFeatureError) - end - - end - - describe "deprecated features" do - - subject(:cbv) { Chef::CookbookVersion.new("tatft", "/tmp/blah").tap { |c| c.version = "1.2.3" } } - - before do - Chef::Config[:treat_deprecation_warnings_as_errors] = false - end - - it "gives a save URL for the standard cookbook API" do - expect(cbv.save_url).to eq("cookbooks/tatft/1.2.3") - end - - it "gives a force save URL for the standard cookbook API" do - expect(cbv.force_save_url).to eq("cookbooks/tatft/1.2.3?force=true") - end - - it "is \"ready\"" do - # WTF is this? what are the valid states? and why aren't they set with encapsulating methods? - # [Dan 15-Jul-2010] - expect(cbv.status).to eq(:ready) - end - - include_examples "to_json equivalent to Chef::JSONCompat.to_json" do - let(:jsonable) { Chef::CookbookVersion.new("tatft", "/tmp/blah") } - end - - end end diff --git a/spec/unit/http/socketless_chef_zero_client_spec.rb b/spec/unit/http/socketless_chef_zero_client_spec.rb index 637e562799..4f3aed13c5 100644 --- a/spec/unit/http/socketless_chef_zero_client_spec.rb +++ b/spec/unit/http/socketless_chef_zero_client_spec.rb @@ -132,7 +132,7 @@ describe Chef::HTTP::SocketlessChefZeroClient do let(:method) { :GET } let(:relative_url) { "clients" } - let(:headers) { { "Accept" => "application/json" } } + let(:headers) { { "Accept" => "application/json", "X-Ops-Server-API-Version" => "2" } } let(:body) { false } let(:expected_rack_req) do @@ -144,6 +144,7 @@ describe Chef::HTTP::SocketlessChefZeroClient do "QUERY_STRING" => uri.query, "SERVER_PORT" => uri.port, "HTTP_HOST" => "localhost:#{uri.port}", + "HTTP_X_OPS_SERVER_API_VERSION" => "2", "rack.url_scheme" => "chefzero", "rack.input" => an_instance_of(StringIO), } diff --git a/spec/unit/knife/cookbook_download_spec.rb b/spec/unit/knife/cookbook_download_spec.rb index 38a4974774..1fb995f71d 100644 --- a/spec/unit/knife/cookbook_download_spec.rb +++ b/spec/unit/knife/cookbook_download_spec.rb @@ -47,44 +47,62 @@ describe Chef::Knife::CookbookDownload do @rest_mock = double("rest") allow(@knife).to receive(:rest).and_return(@rest_mock) - @manifest_data = { - :recipes => [ - { "path" => "recipes/foo.rb", - "url" => "http://example.org/files/foo.rb" }, - { "path" => "recipes/bar.rb", - "url" => "http://example.org/files/bar.rb" }, - ], - :templates => [ - { "path" => "templates/default/foo.erb", - "url" => "http://example.org/files/foo.erb" }, - { "path" => "templates/default/bar.erb", - "url" => "http://example.org/files/bar.erb" }, - ], - :attributes => [ - { "path" => "attributes/default.rb", - "url" => "http://example.org/files/default.rb" }, + expect(Chef::CookbookVersion).to receive(:load).with("foobar", "1.0.0"). + and_return(cookbook) + end + + let(:manifest_data) do + { + :all_files => [ + { + "path" => "recipes/foo.rb", + "name" => "recipes/foo.rb", + "url" => "http://example.org/files/foo.rb", + }, + { + "path" => "recipes/bar.rb", + "name" => "recipes/bar.rb", + "url" => "http://example.org/files/bar.rb", + }, + { + "path" => "templates/default/foo.erb", + "name" => "templates/foo.erb", + "url" => "http://example.org/files/foo.erb", + }, + { + "path" => "templates/default/bar.erb", + "name" => "templates/bar.erb", + "url" => "http://example.org/files/bar.erb", + }, + { + "path" => "attributes/default.rb", + "name" => "attributes/default.rb", + "url" => "http://example.org/files/default.rb", + }, ], } + end - @cookbook_mock = double("cookbook") - allow(@cookbook_mock).to receive(:version).and_return("1.0.0") - allow(@cookbook_mock).to receive(:manifest).and_return(@manifest_data) - expect(Chef::CookbookVersion).to receive(:load).with("foobar", "1.0.0"). - and_return(@cookbook_mock) + let (:cookbook) do + cb = Chef::CookbookVersion.new("foobar") + cb.version = "1.0.0" + cb.manifest = manifest_data + cb end - it "should determine which version if one was not explicitly specified" do - allow(@cookbook_mock).to receive(:manifest).and_return({}) - expect(@knife).to receive(:determine_version).and_return("1.0.0") - expect(File).to receive(:exists?).with("/var/tmp/chef/foobar-1.0.0").and_return(false) - allow(Chef::CookbookVersion).to receive(:COOKBOOK_SEGEMENTS).and_return([]) - @knife.run + describe "and no version" do + let (:manifest_data) { { all_files: [] } } + it "should determine which version to download" do + expect(@knife).to receive(:determine_version).and_return("1.0.0") + expect(File).to receive(:exists?).with("/var/tmp/chef/foobar-1.0.0").and_return(false) + @knife.run + end end describe "and a version" do before(:each) do @knife.name_args << "1.0.0" - @files = @manifest_data.values.map { |v| v.map { |i| i["path"] } }.flatten.uniq + @files = manifest_data.values.map { |v| v.map { |i| i["path"] } }.flatten.uniq @files_mocks = {} @files.map { |f| File.basename(f) }.flatten.uniq.each do |f| @files_mocks[f] = double("#{f}_mock") diff --git a/spec/unit/knife/cookbook_show_spec.rb b/spec/unit/knife/cookbook_show_spec.rb index 749e50c647..1e8ea836d7 100644 --- a/spec/unit/knife/cookbook_show_spec.rb +++ b/spec/unit/knife/cookbook_show_spec.rb @@ -47,9 +47,9 @@ describe Chef::Knife::CookbookShow do let (:manifest) do { - "recipes" => [ + "all_files" => [ { - :name => "default.rb", + :name => "recipes/default.rb", :path => "recipes/default.rb", :checksum => "1234", :url => "http://example.org/files/default.rb", @@ -101,9 +101,42 @@ describe Chef::Knife::CookbookShow do knife.name_args << "0.1.0" end + let(:output) do + { "cookbook_name" => "cookbook_name", + "name" => "cookbook_name-0.0.0", + "frozen?" => false, + "version" => "0.0.0", + "metadata" => { + "name" => nil, + "description" => "", + "long_description" => "", + "maintainer" => nil, + "maintainer_email" => nil, + "license" => "All rights reserved", + "platforms" => {}, + "dependencies" => {}, + "providing" => {}, + "attributes" => {}, + "recipes" => {}, + "version" => "0.0.0", + "source_url" => "", + "issues_url" => "", + "privacy" => false, + "chef_versions" => [], + "ohai_versions" => [], + "gems" => [], + }, + "recipes" => + [{ "name" => "recipes/default.rb", + "path" => "recipes/default.rb", + "checksum" => "1234", + "url" => "http://example.org/files/default.rb" }], + } + end + it "should show the specific part of a cookbook" do expect(Chef::CookbookVersion).to receive(:load).with("cookbook_name", "0.1.0").and_return(cb) - expect(knife).to receive(:output).with(cb) + expect(knife).to receive(:output).with(output) knife.run end end @@ -115,7 +148,7 @@ describe Chef::Knife::CookbookShow do it "should print the json of the part" do expect(Chef::CookbookVersion).to receive(:load).with("cookbook_name", "0.1.0").and_return(cb) - expect(knife).to receive(:output).with(cb.manifest["recipes"]) + expect(knife).to receive(:output).with(cb.files_for("recipes")) knife.run end end @@ -137,30 +170,30 @@ describe Chef::Knife::CookbookShow do before(:each) do knife.name_args = [ "cookbook_name", "0.1.0", "files", "afile.rb" ] cb.manifest = { - "files" => [ + "all_files" => [ { - :name => "afile.rb", + :name => "files/afile.rb", :path => "files/host-examplehost.example.org/afile.rb", :checksum => "1111", :specificity => "host-examplehost.example.org", :url => "http://example.org/files/1111", }, { - :name => "afile.rb", + :name => "files/afile.rb", :path => "files/ubuntu-9.10/afile.rb", :checksum => "2222", :specificity => "ubuntu-9.10", :url => "http://example.org/files/2222", }, { - :name => "afile.rb", + :name => "files/afile.rb", :path => "files/ubuntu/afile.rb", :checksum => "3333", :specificity => "ubuntu", :url => "http://example.org/files/3333", }, { - :name => "afile.rb", + :name => "files/afile.rb", :path => "files/default/afile.rb", :checksum => "4444", :specificity => "default", diff --git a/spec/unit/policy_builder/policyfile_spec.rb b/spec/unit/policy_builder/policyfile_spec.rb index 307bd45c18..c9086c2f63 100644 --- a/spec/unit/policy_builder/policyfile_spec.rb +++ b/spec/unit/policy_builder/policyfile_spec.rb @@ -100,8 +100,8 @@ describe Chef::PolicyBuilder::Policyfile do http = double("Chef::ServerAPI") server_url = "https://api.opscode.com/organizations/example" Chef::Config[:chef_server_url] = server_url - expect(Chef::ServerAPI).to receive(:new).with(server_url).and_return(http) - expect(policy_builder.http_api).to eq(http) + expect(Chef::ServerAPI).to receive(:new).with(server_url, version_class: Chef::CookbookManifestVersions).and_return(http) + expect(policy_builder.api_service).to eq(http) end describe "reporting unsupported features" do @@ -150,7 +150,7 @@ describe Chef::PolicyBuilder::Policyfile do describe "loading policy data" do - let(:http_api) { double("Chef::ServerAPI") } + let(:api_service) { double("Chef::ServerAPI") } let(:configured_environment) { nil } @@ -172,7 +172,7 @@ describe Chef::PolicyBuilder::Policyfile do before do Chef::Config[:policy_document_native_api] = false Chef::Config[:deployment_group] = "example-policy-stage" - allow(policy_builder).to receive(:http_api).and_return(http_api) + allow(policy_builder).to receive(:api_service).and_return(api_service) end describe "when using compatibility mode (policy_document_native_api == false)" do @@ -185,7 +185,7 @@ describe Chef::PolicyBuilder::Policyfile do let(:error404) { Net::HTTPServerException.new("404 message", :body) } before do - expect(http_api).to receive(:get). + expect(api_service).to receive(:get). with("data/policyfiles/example-policy-stage"). and_raise(error404) end @@ -212,7 +212,7 @@ describe Chef::PolicyBuilder::Policyfile do let(:policy_relative_url) { "data/policyfiles/example-policy-stage" } before do - expect(http_api).to receive(:get).with(policy_relative_url).and_return(parsed_policyfile_json) + expect(api_service).to receive(:get).with(policy_relative_url).and_return(parsed_policyfile_json) end it "fetches the policy file from a data bag item" do @@ -253,7 +253,7 @@ describe Chef::PolicyBuilder::Policyfile do let(:policy_relative_url) { "policy_groups/policy-stage/policies/example" } before do - expect(http_api).to receive(:get).with(policy_relative_url).and_return(parsed_policyfile_json) + expect(api_service).to receive(:get).with(policy_relative_url).and_return(parsed_policyfile_json) end it "fetches the policy file from a data bag item" do @@ -617,7 +617,7 @@ describe Chef::PolicyBuilder::Policyfile do policy_builder.finish_load_node(node) policy_builder.build_node - expect(http_api).to receive(:get).with(cookbook1_url). + expect(api_service).to receive(:get).with(cookbook1_url). and_raise(error404) end @@ -687,9 +687,9 @@ describe Chef::PolicyBuilder::Policyfile do context "when the cookbooks exist on the server" do before do - expect(http_api).to receive(:get).with(cookbook1_url). + expect(api_service).to receive(:get).with(cookbook1_url). and_return(example1_cookbook_data) - expect(http_api).to receive(:get).with(cookbook2_url). + expect(api_service).to receive(:get).with(cookbook2_url). and_return(example2_cookbook_data) expect(Chef::CookbookVersion).to receive(:from_cb_artifact_data).with(example1_cookbook_data). @@ -720,9 +720,9 @@ describe Chef::PolicyBuilder::Policyfile do context "when the cookbooks exist on the server" do before do - expect(http_api).to receive(:get).with(cookbook1_url). + expect(api_service).to receive(:get).with(cookbook1_url). and_return(example1_cookbook_data) - expect(http_api).to receive(:get).with(cookbook2_url). + expect(api_service).to receive(:get).with(cookbook2_url). and_return(example2_cookbook_data) expect(Chef::CookbookVersion).to receive(:from_cb_artifact_data).with(example1_cookbook_data). diff --git a/spec/unit/run_context/cookbook_compiler_spec.rb b/spec/unit/run_context/cookbook_compiler_spec.rb index feb39615b6..e93088cd5f 100644 --- a/spec/unit/run_context/cookbook_compiler_spec.rb +++ b/spec/unit/run_context/cookbook_compiler_spec.rb @@ -163,9 +163,7 @@ describe Chef::RunContext::CookbookCompiler do describe "event dispatch" do let(:recipe) { "dependency1::default" } let(:recipe_path) do - File.expand_path("../../../data/run_context/cookbooks/dependency1/recipes/default.rb", __FILE__).tap do |path| - path.gsub!(File::SEPARATOR, File::ALT_SEPARATOR) if File::ALT_SEPARATOR - end + File.expand_path("../../../data/run_context/cookbooks/dependency1/recipes/default.rb", __FILE__) end before do node.run_list(recipe) |