chef-cli 5.6.11 → 5.6.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f99463373ae13f85a16df321c3bb756e8eba19d8e1e7f15b3ae3f2eb173253f2
4
- data.tar.gz: 9f7d1ebb555efa92cc22c8957f24b18f1bb823e19e140518838318584158b8c0
3
+ metadata.gz: 545307db6897b00d78f3b25421371e56f37fe7ef0f58698ad2cef26ff761ac1e
4
+ data.tar.gz: f66467c288febf6b0f1a7ab85fac3a2a9881ca9976b571f29abd966372d91548
5
5
  SHA512:
6
- metadata.gz: c602f596eac142ce3fbf2f81dbdc987f22768e3b4c35fbb0c1d5615eb94eaba4085444ae4a7270986229c1ff90b4f81eddb36b87a1ae9db353c96f43f613d25d
7
- data.tar.gz: e2956dcc853d9a61e74ad243e9fd7f8a391687f5be8e82a72ba89408b1a97025ef1a5f274867ca4ff99f807dee0432bb76ec1a75a3ea478132253d5f965acc50
6
+ metadata.gz: 398f7c876022b50b7f6f35788c28e40cc722d1ebc66930d0ae93a1a8b276c731ae44b5c679a8b52b930d5bbc4442b2875dcb2bf8dd90ac0a260bc58db31ff540
7
+ data.tar.gz: 18a0ff8e27a0d5aaabb95104091f134127f73db19c63fc1d4f3cb9b4ae6e475c09322b325fe624691f522058e4b78ea1cd2f1bea61324cf1e1a45a92636dd374
@@ -180,7 +180,11 @@ module ChefCLI
180
180
  end
181
181
 
182
182
  def cookbook_full_path
183
- File.expand_path(cookbook_name_or_path, Dir.pwd)
183
+ if !cookbook_name_or_path.nil? && !cookbook_name_or_path.empty?
184
+ File.expand_path(cookbook_name_or_path, Dir.pwd)
185
+ else
186
+ ""
187
+ end
184
188
  end
185
189
 
186
190
  def policy_mode?
@@ -205,6 +209,13 @@ module ChefCLI
205
209
  msg("Hyphens are discouraged in cookbook names as they may cause problems with custom resources. See https://docs.chef.io/workstation/ctl_chef/#chef-generate-cookbook for more information.")
206
210
  end
207
211
 
212
+ if !generator_cookbook_path.empty? &&
213
+ !cookbook_full_path.empty? &&
214
+ File.identical?(Pathname.new(cookbook_full_path).parent, generator_cookbook_path)
215
+ err("The generator and the cookbook cannot be in the same directory. Please specify a cookbook directory that is different from the generator's parent.")
216
+ @params_valid = false
217
+ end
218
+
208
219
  if config[:berks] && config[:policy]
209
220
  err("Berkshelf and Policyfiles are mutually exclusive. Please specify only one.")
210
221
  @params_valid = false
@@ -16,5 +16,5 @@
16
16
  #
17
17
 
18
18
  module ChefCLI
19
- VERSION = "5.6.11".freeze
19
+ VERSION = "5.6.12".freeze
20
20
  end
@@ -24,15 +24,13 @@ shared_examples_for "custom generator cookbook" do
24
24
  end
25
25
  end
26
26
 
27
- before do
27
+ it "configures the generator context" do
28
28
  reset_tempdir
29
29
  code_generator.read_and_validate_params
30
30
  allow(code_generator.config_loader).to receive(:load)
31
- end
32
31
 
33
- it "configures the generator context" do
34
32
  code_generator.setup_context
35
- expect(generator_context.cookbook_name).to eq(generator_arg)
33
+ expect(generator_context.cookbook_name).to eq(File.basename(generator_arg))
36
34
  expect(code_generator.chef_runner.cookbook_path).to eq(tempdir)
37
35
  expect(code_generator.chef_runner.run_list).to eq(["recipe[a_generator_cookbook::#{generator_name}]"])
38
36
  end
@@ -55,19 +53,33 @@ shared_examples_for "custom generator cookbook" do
55
53
  end
56
54
 
57
55
  before do
56
+ reset_tempdir
57
+ code_generator.read_and_validate_params
58
+ allow(code_generator.config_loader).to receive(:load)
58
59
  allow(code_generator).to receive(:chefcli_config).and_return(chefcli_config)
59
60
  end
60
61
 
61
62
  it "configures the generator context" do
62
63
  code_generator.setup_context
63
- expect(generator_context.cookbook_name).to eq(generator_arg)
64
- expect(code_generator.chef_runner.cookbook_path).to eq(tempdir)
65
- expect(code_generator.chef_runner.run_list).to eq(["recipe[a_generator_cookbook::#{generator_name}]"])
64
+ expect(generator_context.cookbook_name).to eq(File.basename(generator_arg))
65
+ expect(code_generator.chef_runner.cookbook_path).to eq(File.expand_path("lib/chef-cli/skeletons", project_root))
66
+ expect(code_generator.chef_runner.run_list).to eq(["recipe[code_generator::#{generator_name}]"])
66
67
  end
67
68
  end
68
69
 
69
70
  context "with an invalid generator-cookbook path" do
70
71
 
72
+ let(:argv) { ["new_cookbook", "--generator-cookbook", "#{tempdir}/nested/a_generator_cookbook"] }
73
+
74
+ before do
75
+ reset_tempdir
76
+ FileUtils.mkdir_p("#{tempdir}/nested")
77
+ FileUtils.cp_r(default_generator_cookbook_path, "#{tempdir}/nested/")
78
+
79
+ code_generator.read_and_validate_params
80
+ allow(code_generator.config_loader).to receive(:load)
81
+ end
82
+
71
83
  it "fails with an informative error" do
72
84
  Dir.chdir(tempdir) do
73
85
  allow(code_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
@@ -88,6 +100,10 @@ shared_examples_for "custom generator cookbook" do
88
100
  let(:metadata_file) { File.join(generator_cookbook_path, "metadata.rb") }
89
101
 
90
102
  before do
103
+ reset_tempdir
104
+ code_generator.read_and_validate_params
105
+ allow(code_generator.config_loader).to receive(:load)
106
+
91
107
  FileUtils.cp_r(default_generator_cookbook_path, generator_cookbook_path)
92
108
 
93
109
  # have to update metadata with the correct name
@@ -95,7 +111,7 @@ shared_examples_for "custom generator cookbook" do
95
111
  end
96
112
 
97
113
  it "creates the new files" do
98
- expect(code_generator.chef_runner.cookbook_path).to eq(tempdir)
114
+ expect(code_generator.chef_runner.cookbook_path).to eq("#{tempdir}")
99
115
  expect(code_generator.chef_runner.run_list).to eq(["recipe[a_generator_cookbook::#{generator_name}]"])
100
116
 
101
117
  Dir.chdir(tempdir) do
@@ -108,11 +124,16 @@ shared_examples_for "custom generator cookbook" do
108
124
 
109
125
  context "with a generator-cookbook path to a directory containing a 'code_generator' cookbook" do
110
126
 
127
+ let(:argv) { ["#{tempdir}/new_cookbook", "--generator-cookbook", generator_cookbook_path] }
128
+
111
129
  before do
130
+ reset_tempdir
112
131
  FileUtils.mkdir_p(generator_cookbook_path)
113
132
  FileUtils.cp_r(default_generator_cookbook_path, generator_cookbook_path)
114
133
 
115
134
  allow(code_generator).to receive(:stderr).and_return(stderr_io)
135
+ code_generator.read_and_validate_params
136
+ allow(code_generator.config_loader).to receive(:load)
116
137
  end
117
138
 
118
139
  it "creates the new_files (and warns about deprecated usage)" do
@@ -121,7 +142,7 @@ shared_examples_for "custom generator cookbook" do
121
142
  Dir.chdir(tempdir) do
122
143
  code_generator.run
123
144
  end
124
- generated_files = Dir.glob("#{tempdir}/#{generator_arg}/**/*", File::FNM_DOTMATCH)
145
+ generated_files = Dir.glob("#{tempdir}/new_cookbook/**/*", File::FNM_DOTMATCH)
125
146
  expected_cookbook_files.each do |expected_file|
126
147
  expect(generated_files).to include(expected_file)
127
148
  end
@@ -152,6 +152,12 @@ describe ChefCLI::Command::GeneratorCommands::Cookbook do
152
152
  expect(stderr_io.string).to include(message)
153
153
  end
154
154
 
155
+ it "errors if cookbook parent folder is same as generator parent folder" do
156
+ expect(with_argv(%w{ my_cookbook -g my_generator }).run).to eq(1)
157
+ message = "The generator and the cookbook cannot be in the same directory. Please specify a cookbook directory that is different from the generator's parent."
158
+ expect(stderr_io.string).to include(message)
159
+ end
160
+
155
161
  it "warns if a hyphenated cookbook name is passed" do
156
162
  expect(with_argv(%w{my-cookbook}).run).to eq(0)
157
163
  message = "Hyphens are discouraged in cookbook names as they may cause problems with custom resources. See https://docs.chef.io/workstation/ctl_chef/#chef-generate-cookbook for more information."
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.6.11
4
+ version: 5.6.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chef Software, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-27 00:00:00.000000000 Z
11
+ date: 2023-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mixlib-cli