Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1590 from chef/jcowie/policyfiles_generator
Browse files Browse the repository at this point in the history
Change policyfile generator to use 'policyfiles' directory
  • Loading branch information
lamont-granquist authored Aug 27, 2018
2 parents 19e115f + 6366708 commit 6475108
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/chef-dk/command/generator_commands/policyfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
2 changes: 1 addition & 1 deletion lib/chef-dk/skeletons/code_generator/recipes/repo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/command/generator_commands/policyfile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions spec/unit/command/generator_commands/repo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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" }] }
Expand Down

0 comments on commit 6475108

Please sign in to comment.