From 4f2467bfede471060cc3356eb9b6618eb4463651 Mon Sep 17 00:00:00 2001 From: Jon Cowie Date: Tue, 29 May 2018 17:55:56 +0100 Subject: [PATCH 1/4] Change policyfile generator to use 'policyfiles' directory instead of 'policies' directory Signed-off-by: Jon Cowie --- lib/chef-dk/command/generator_commands/policyfile.rb | 2 +- spec/unit/command/generator_commands/policyfile_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/chef-dk/command/generator_commands/policyfile.rb b/lib/chef-dk/command/generator_commands/policyfile.rb index 826c56a2f..20fe92591 100644 --- a/lib/chef-dk/command/generator_commands/policyfile.rb +++ b/lib/chef-dk/command/generator_commands/policyfile.rb @@ -104,7 +104,7 @@ def derive_policy_settings_from_args(new_file_path) given_policy_dirname = File.expand_path(File.dirname(new_file_path)) @policyfile_dir = if chef_repo_mode? && (given_policy_dirname == Dir.pwd) - File.expand_path("policies") + File.expand_path("policyfiles") else given_policy_dirname end diff --git a/spec/unit/command/generator_commands/policyfile_spec.rb b/spec/unit/command/generator_commands/policyfile_spec.rb index 07a639458..0005b9964 100644 --- a/spec/unit/command/generator_commands/policyfile_spec.rb +++ b/spec/unit/command/generator_commands/policyfile_spec.rb @@ -111,7 +111,7 @@ def generator_context let(:chef_repo_dot_txt) { File.join(tempdir, ".chef-repo.txt") } - let(:policies_dir) { File.join(tempdir, "policies") } + let(:policies_dir) { File.join(tempdir, "policyfiles") } let(:expected_policyfile_content) do <<-POLICYFILE_RB From d52620fb31beec05d9fd3039716c24c6d1f9e9d6 Mon Sep 17 00:00:00 2001 From: Jon Cowie Date: Mon, 4 Jun 2018 09:41:08 +0100 Subject: [PATCH 2/4] Add directory path change to README Signed-off-by: Jon Cowie --- .../code_generator/files/default/repo/policies/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/chef-dk/skeletons/code_generator/files/default/repo/policies/README.md b/lib/chef-dk/skeletons/code_generator/files/default/repo/policies/README.md index 37b7439d9..5162acfde 100644 --- a/lib/chef-dk/skeletons/code_generator/files/default/repo/policies/README.md +++ b/lib/chef-dk/skeletons/code_generator/files/default/repo/policies/README.md @@ -5,20 +5,20 @@ the same filename as the name set in the policyfile itself, and use the Compile the policy with a command like this: ``` -chef install policies/my-app-frontend.rb +chef install policyfiles/my-app-frontend.rb ``` -This will create a lockfile `policies/my-app-frontend.lock.json`. +This will create a lockfile `policyfiles/my-app-frontend.lock.json`. To update locked dependencies, run `chef update` like this: ``` -chef update policies/my-app-frontend.rb +chef update policyfiles/my-app-frontend.rb ``` You can upload the policy (with associated cookbooks) to the server using a command like: ``` -chef push staging policies/my-app-frontend.rb +chef push staging policyfiles/my-app-frontend.rb ``` From 5c3465b7fbd426043a626cec741140294131adab Mon Sep 17 00:00:00 2001 From: Jon Cowie Date: Tue, 5 Jun 2018 10:06:58 +0100 Subject: [PATCH 3/4] Fix repo generator recipe to use correct directory name Signed-off-by: Jon Cowie --- lib/chef-dk/skeletons/code_generator/recipes/repo.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/chef-dk/skeletons/code_generator/recipes/repo.rb b/lib/chef-dk/skeletons/code_generator/recipes/repo.rb index 4098eec90..b568fe0cb 100644 --- a/lib/chef-dk/skeletons/code_generator/recipes/repo.rb +++ b/lib/chef-dk/skeletons/code_generator/recipes/repo.rb @@ -32,7 +32,7 @@ directories_to_create += if context.use_roles %w( roles environments ) else - %w( policies ) + %w( policyfiles ) end directories_to_create.each do |tlo| From 63667081efeb0bf2e848ec96983171ba18db9a9d Mon Sep 17 00:00:00 2001 From: Jon Cowie Date: Tue, 5 Jun 2018 11:32:55 +0100 Subject: [PATCH 4/4] Oops, fix some test failures Signed-off-by: Jon Cowie --- .../default/repo/{policies => policyfiles}/README.md | 0 spec/unit/command/generator_commands/repo_spec.rb | 8 ++++---- .../policyfile/included_policies_cookbook_source_spec.rb | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) rename lib/chef-dk/skeletons/code_generator/files/default/repo/{policies => policyfiles}/README.md (100%) diff --git a/lib/chef-dk/skeletons/code_generator/files/default/repo/policies/README.md b/lib/chef-dk/skeletons/code_generator/files/default/repo/policyfiles/README.md similarity index 100% rename from lib/chef-dk/skeletons/code_generator/files/default/repo/policies/README.md rename to lib/chef-dk/skeletons/code_generator/files/default/repo/policyfiles/README.md diff --git a/spec/unit/command/generator_commands/repo_spec.rb b/spec/unit/command/generator_commands/repo_spec.rb index e69ee10f5..130b725dd 100644 --- a/spec/unit/command/generator_commands/repo_spec.rb +++ b/spec/unit/command/generator_commands/repo_spec.rb @@ -291,9 +291,9 @@ def generator_context expect(File).to_not exist(File.join(repo_path, "environments")) end - describe "policies" do + describe "policyfiles" do describe "README.md" do - let(:file) { "policies/README.md" } + let(:file) { "policyfiles/README.md" } let(:expected_content) do <<-README @@ -315,8 +315,8 @@ def generator_context let(:argv) { %w{new_repo --roles} } - it "does not create a policies directory" do - expect(File).to_not exist(File.join(repo_path, "policies")) + it "does not create a policyfiles directory" do + expect(File).to_not exist(File.join(repo_path, "policyfiles")) end describe "roles" do diff --git a/spec/unit/policyfile/included_policies_cookbook_source_spec.rb b/spec/unit/policyfile/included_policies_cookbook_source_spec.rb index df016fa84..9d1e794e7 100644 --- a/spec/unit/policyfile/included_policies_cookbook_source_spec.rb +++ b/spec/unit/policyfile/included_policies_cookbook_source_spec.rb @@ -137,9 +137,9 @@ def build_lockdata(cookbooks) end end - let(:policies) { [] } + let(:policyfiles) { [] } - let(:cookbook_source) { ChefDK::Policyfile::IncludedPoliciesCookbookSource.new(policies) } + let(:cookbook_source) { ChefDK::Policyfile::IncludedPoliciesCookbookSource.new(policyfiles) } context "when no policies are included" do it "returns false for preferred_source_for" do @@ -152,7 +152,7 @@ def build_lockdata(cookbooks) end context "when a single policy is to be included" do - let(:policies) { [policy1_location_spec] } + let(:policyfiles) { [policy1_location_spec] } it "does not have a preferred source for unlocked cookbooks" do expect(cookbook_source.preferred_source_for?("cookbookC")).to eq(false) @@ -185,7 +185,7 @@ def build_lockdata(cookbooks) end context "when multiple policies are to be included" do - let(:policies) { [policy1_location_spec, policy2_location_spec] } + let(:policyfiles) { [policy1_location_spec, policy2_location_spec] } context "when the policies use the same cookbooks with the same versions and sources" do let(:policy2_cookbooks) { policy1_cookbooks + [{ name: "cookbookC", version: "2.0.0" }] }