knife-essentials 0.8.1 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/chef/knife/delete_essentials.rb +3 -3
- data/lib/chef/knife/deps_essentials.rb +19 -9
- data/lib/chef/knife/diff_essentials.rb +2 -2
- data/lib/chef/knife/download_essentials.rb +2 -2
- data/lib/chef/knife/list_essentials.rb +61 -29
- data/lib/chef/knife/raw_essentials.rb +5 -5
- data/lib/chef/knife/show_essentials.rb +4 -4
- data/lib/chef/knife/upload_essentials.rb +2 -2
- data/lib/chef_fs/file_system.rb +27 -27
- data/lib/chef_fs/file_system/base_fs_object.rb +6 -1
- data/lib/chef_fs/file_system/chef_repository_file_system_cookbooks_dir.rb +37 -0
- data/lib/chef_fs/file_system/chef_repository_file_system_entry.rb +28 -43
- data/lib/chef_fs/file_system/chef_repository_file_system_root_dir.rb +6 -1
- data/lib/chef_fs/knife.rb +8 -3
- data/lib/chef_fs/version.rb +1 -1
- data/spec/chef_fs/file_system_spec.rb +2 -2
- data/spec/integration/chef_repository_file_system_spec.rb +650 -0
- data/spec/integration/deps_spec.rb +314 -0
- data/spec/integration/list_spec.rb +315 -0
- data/spec/support/integration_helper.rb +95 -0
- data/spec/support/knife_support.rb +92 -0
- data/spec/support/stickywicket.pem +27 -0
- metadata +26 -3
@@ -108,7 +108,12 @@ module ChefFS
|
|
108
108
|
# are_same = (value == other_value)
|
109
109
|
# end
|
110
110
|
def compare_to(other)
|
111
|
-
|
111
|
+
nil
|
112
|
+
end
|
113
|
+
|
114
|
+
def chef_object
|
115
|
+
raise ChefFS::FileSystem::NotFoundError, "Nonexistent #{path_for_printing}" if !exists?
|
116
|
+
nil
|
112
117
|
end
|
113
118
|
|
114
119
|
# Important directory attributes: name, parent, path, root
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#
|
2
|
+
# Author:: John Keiser (<jkeiser@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2013 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'chef_fs/file_system/chef_repository_file_system_entry'
|
20
|
+
require 'chef/cookbook/chefignore'
|
21
|
+
|
22
|
+
module ChefFS
|
23
|
+
module FileSystem
|
24
|
+
class ChefRepositoryFileSystemCookbooksDir < ChefRepositoryFileSystemEntry
|
25
|
+
def initialize(name, parent, file_path)
|
26
|
+
super(name, parent, file_path)
|
27
|
+
@chefignore = Chef::Cookbook::Chefignore.new(self.file_path)
|
28
|
+
end
|
29
|
+
|
30
|
+
attr_reader :chefignore
|
31
|
+
|
32
|
+
def ignore_empty_directories?
|
33
|
+
true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -17,7 +17,6 @@
|
|
17
17
|
#
|
18
18
|
|
19
19
|
require 'chef_fs/file_system/file_system_entry'
|
20
|
-
require 'chef/cookbook/chefignore'
|
21
20
|
require 'chef/cookbook/cookbook_version_loader'
|
22
21
|
require 'chef/node'
|
23
22
|
require 'chef/role'
|
@@ -30,23 +29,16 @@ module ChefFS
|
|
30
29
|
# ChefRepositoryFileSystemEntry works just like FileSystemEntry,
|
31
30
|
# except can inflate Chef objects
|
32
31
|
class ChefRepositoryFileSystemEntry < FileSystemEntry
|
33
|
-
def initialize(name, parent, file_path = nil)
|
32
|
+
def initialize(name, parent, file_path = nil, ignore_empty_directories = nil, chefignore = nil)
|
34
33
|
super(name, parent, file_path)
|
35
|
-
# Load /cookbooks/chefignore
|
36
|
-
if path == '/cookbooks'
|
37
|
-
@chefignore = Chef::Cookbook::Chefignore.new(self.file_path)
|
38
|
-
@ignore_empty_directories = true
|
39
|
-
# If we are a cookbook or a cookbook subdirectory, empty directories
|
40
|
-
# underneath us are ignored (since they cannot be uploaded)
|
41
|
-
elsif parent && parent.ignore_empty_directories?
|
42
|
-
@ignore_empty_directories = true
|
43
|
-
end
|
44
34
|
end
|
45
35
|
|
46
|
-
|
36
|
+
def chefignore
|
37
|
+
nil
|
38
|
+
end
|
47
39
|
|
48
40
|
def ignore_empty_directories?
|
49
|
-
|
41
|
+
parent.ignore_empty_directories?
|
50
42
|
end
|
51
43
|
|
52
44
|
def chef_object
|
@@ -68,43 +60,36 @@ module ChefFS
|
|
68
60
|
def children
|
69
61
|
@children ||=
|
70
62
|
Dir.entries(file_path).
|
71
|
-
select { |entry| entry != '.' && entry != '..'
|
72
|
-
map { |entry| ChefRepositoryFileSystemEntry.new(entry, self) }
|
63
|
+
select { |entry| entry != '.' && entry != '..' }.
|
64
|
+
map { |entry| ChefRepositoryFileSystemEntry.new(entry, self) }.
|
65
|
+
select { |entry| !ignored?(entry) }
|
73
66
|
end
|
74
67
|
|
75
|
-
attr_reader :chefignore
|
76
|
-
|
77
68
|
private
|
78
69
|
|
79
|
-
def
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
def ignored?(child_name)
|
85
|
-
# empty directories inside a cookbook are ignored
|
86
|
-
if ignore_empty_directories?
|
87
|
-
child_path = PathUtils.join(file_path, child_name)
|
88
|
-
if File.directory?(child_path) && Dir.entries(child_path) == [ '.', '..' ]
|
70
|
+
def ignored?(child_entry)
|
71
|
+
if child_entry.dir?
|
72
|
+
# empty cookbooks and cookbook directories are ignored
|
73
|
+
if ignore_empty_directories? && child_entry.children.size == 0
|
89
74
|
return true
|
90
75
|
end
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
76
|
+
else
|
77
|
+
ignorer = parent
|
78
|
+
begin
|
79
|
+
if ignorer.chefignore
|
80
|
+
# Grab the path from entry to child
|
81
|
+
path_to_child = child_entry.name
|
82
|
+
child = self
|
83
|
+
while child.parent != ignorer
|
84
|
+
path_to_child = PathUtils.join(child.name, path_to_child)
|
85
|
+
child = child.parent
|
86
|
+
end
|
87
|
+
# Check whether that relative path is ignored
|
88
|
+
return ignorer.chefignore.ignored?(path_to_child)
|
102
89
|
end
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
ignorer = ignorer.parent
|
107
|
-
end while ignorer
|
90
|
+
ignorer = ignorer.parent
|
91
|
+
end while ignorer
|
92
|
+
end
|
108
93
|
end
|
109
94
|
|
110
95
|
end
|
@@ -18,6 +18,7 @@
|
|
18
18
|
|
19
19
|
require 'chef_fs/file_system/base_fs_dir'
|
20
20
|
require 'chef_fs/file_system/chef_repository_file_system_entry'
|
21
|
+
require 'chef_fs/file_system/chef_repository_file_system_cookbooks_dir'
|
21
22
|
require 'chef_fs/file_system/multiplexed_dir'
|
22
23
|
|
23
24
|
module ChefFS
|
@@ -62,7 +63,11 @@ module ChefFS
|
|
62
63
|
if paths.size == 0
|
63
64
|
return nil
|
64
65
|
end
|
65
|
-
|
66
|
+
if name == 'cookbooks'
|
67
|
+
dirs = paths.map { |path| ChefRepositoryFileSystemCookbooksDir.new(name, self, path) }
|
68
|
+
else
|
69
|
+
dirs = paths.map { |path| ChefRepositoryFileSystemEntry.new(name, self, path) }
|
70
|
+
end
|
66
71
|
MultiplexedDir.new(dirs)
|
67
72
|
end
|
68
73
|
end
|
data/lib/chef_fs/knife.rb
CHANGED
@@ -47,7 +47,7 @@ module ChefFS
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
# Smooth out some inappropriate (for
|
50
|
+
# Smooth out some inappropriate (for now) variable defaults in Chef.
|
51
51
|
def config_var(name)
|
52
52
|
case name
|
53
53
|
when :data_bag_path
|
@@ -66,7 +66,12 @@ module ChefFS
|
|
66
66
|
def object_paths
|
67
67
|
@object_paths ||= begin
|
68
68
|
result = {}
|
69
|
-
|
69
|
+
if config[:repo_mode] == 'everything'
|
70
|
+
object_names = %w(clients cookbooks data_bags environments nodes roles users)
|
71
|
+
else
|
72
|
+
object_names = %w(cookbooks data_bags environments roles)
|
73
|
+
end
|
74
|
+
object_names.each do |object_name|
|
70
75
|
variable_name = "#{object_name[0..-2]}_path" # cookbooks -> cookbook_path
|
71
76
|
paths = config_var(variable_name.to_sym)
|
72
77
|
if !paths
|
@@ -135,7 +140,7 @@ module ChefFS
|
|
135
140
|
|
136
141
|
# Print the given server path, relative to the current directory
|
137
142
|
def format_path(server_path)
|
138
|
-
if server_path[0,base_path.length] == base_path
|
143
|
+
if base_path && server_path[0,base_path.length] == base_path
|
139
144
|
if server_path == base_path
|
140
145
|
return "."
|
141
146
|
elsif server_path[base_path.length] == "/"
|
data/lib/chef_fs/version.rb
CHANGED
@@ -34,7 +34,7 @@ describe ChefFS::FileSystem do
|
|
34
34
|
list_should_yield_paths(fs, '/a', '/a')
|
35
35
|
end
|
36
36
|
it '/a/b' do
|
37
|
-
list_should_yield_paths(fs, '/a/b')
|
37
|
+
list_should_yield_paths(fs, '/a/b', '/a/b')
|
38
38
|
end
|
39
39
|
it '/*' do
|
40
40
|
list_should_yield_paths(fs, '/*', '/')
|
@@ -104,7 +104,7 @@ describe ChefFS::FileSystem do
|
|
104
104
|
end
|
105
105
|
it 'nonexistent /a/ab/blah/bjork' do
|
106
106
|
no_blocking_calls_allowed
|
107
|
-
list_should_yield_paths(fs, '/a/ab/blah/bjork')
|
107
|
+
list_should_yield_paths(fs, '/a/ab/blah/bjork', '/a/ab/blah/bjork')
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
@@ -0,0 +1,650 @@
|
|
1
|
+
require 'support/integration_helper'
|
2
|
+
require 'chef/knife/list_essentials'
|
3
|
+
|
4
|
+
describe 'knife list' do
|
5
|
+
extend IntegrationSupport
|
6
|
+
include KnifeSupport
|
7
|
+
|
8
|
+
context 'directories and files that should/should not be ignored' do
|
9
|
+
when_the_repository "has empty roles, environments and data bag item directories" do
|
10
|
+
directory "roles"
|
11
|
+
directory "environments"
|
12
|
+
directory "data_bags/bag1"
|
13
|
+
|
14
|
+
it "knife list --local -R / returns them" do
|
15
|
+
knife('list --local -R /').should_succeed <<EOM
|
16
|
+
/:
|
17
|
+
data_bags
|
18
|
+
environments
|
19
|
+
roles
|
20
|
+
|
21
|
+
/data_bags:
|
22
|
+
bag1
|
23
|
+
|
24
|
+
/data_bags/bag1:
|
25
|
+
|
26
|
+
/environments:
|
27
|
+
|
28
|
+
/roles:
|
29
|
+
EOM
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
when_the_repository "has an empty data_bags directory" do
|
34
|
+
directory "data_bags"
|
35
|
+
|
36
|
+
it "knife list --local / returns it" do
|
37
|
+
knife('list --local /').should_succeed "/data_bags\n"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
when_the_repository "has an empty cookbook directory" do
|
42
|
+
directory 'cookbooks/cookbook1'
|
43
|
+
|
44
|
+
it "knife list --local -R / does not return it" do
|
45
|
+
knife('list --local -R /').should_succeed <<EOM
|
46
|
+
/:
|
47
|
+
cookbooks
|
48
|
+
|
49
|
+
/cookbooks:
|
50
|
+
EOM
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
when_the_repository "has only empty cookbook subdirectories" do
|
55
|
+
directory 'cookbooks/cookbook1/recipes'
|
56
|
+
|
57
|
+
it "knife list --local -R / does not return it" do
|
58
|
+
knife('list --local -R /').should_succeed <<EOM
|
59
|
+
/:
|
60
|
+
cookbooks
|
61
|
+
|
62
|
+
/cookbooks:
|
63
|
+
EOM
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
when_the_repository "has empty and non-empty cookbook subdirectories" do
|
68
|
+
directory 'cookbooks/cookbook1/recipes'
|
69
|
+
file 'cookbooks/cookbook1/templates/default/x.txt', ''
|
70
|
+
|
71
|
+
it "knife list --local -R / does not return the empty ones" do
|
72
|
+
knife('list --local -R /').should_succeed <<EOM
|
73
|
+
/:
|
74
|
+
cookbooks
|
75
|
+
|
76
|
+
/cookbooks:
|
77
|
+
cookbook1
|
78
|
+
|
79
|
+
/cookbooks/cookbook1:
|
80
|
+
templates
|
81
|
+
|
82
|
+
/cookbooks/cookbook1/templates:
|
83
|
+
default
|
84
|
+
|
85
|
+
/cookbooks/cookbook1/templates/default:
|
86
|
+
x.txt
|
87
|
+
EOM
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
when_the_repository "has only empty cookbook sub-sub-directories" do
|
92
|
+
directory 'cookbooks/cookbook1/templates/default'
|
93
|
+
|
94
|
+
it "knife list --local -R / does not return it" do
|
95
|
+
knife('list --local -R /').should_succeed <<EOM
|
96
|
+
/:
|
97
|
+
cookbooks
|
98
|
+
|
99
|
+
/cookbooks:
|
100
|
+
EOM
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
when_the_repository "has empty cookbook sub-sub-directories alongside non-empty ones" do
|
105
|
+
file 'cookbooks/cookbook1/templates/default/x.txt', ''
|
106
|
+
directory 'cookbooks/cookbook1/templates/rhel'
|
107
|
+
directory 'cookbooks/cookbook1/files/default'
|
108
|
+
|
109
|
+
it "knife list --local -R / does not return the empty ones" do
|
110
|
+
knife('list --local -R /').should_succeed <<EOM
|
111
|
+
/:
|
112
|
+
cookbooks
|
113
|
+
|
114
|
+
/cookbooks:
|
115
|
+
cookbook1
|
116
|
+
|
117
|
+
/cookbooks/cookbook1:
|
118
|
+
templates
|
119
|
+
|
120
|
+
/cookbooks/cookbook1/templates:
|
121
|
+
default
|
122
|
+
|
123
|
+
/cookbooks/cookbook1/templates/default:
|
124
|
+
x.txt
|
125
|
+
EOM
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
when_the_repository "has an extra schmenvironments directory" do
|
130
|
+
directory "schmenvironments" do
|
131
|
+
file "_default.json", {}
|
132
|
+
end
|
133
|
+
|
134
|
+
it "knife list --local -R / should NOT return it" do
|
135
|
+
knife('list --local -R /').should_succeed ""
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
when_the_repository "has extra subdirectories and files under data bag items, roles, and environments" do
|
140
|
+
directory "data_bags/bag1" do
|
141
|
+
file "item1.json", {}
|
142
|
+
file "item2.xml", ""
|
143
|
+
file "another_subdir/item.json", {}
|
144
|
+
end
|
145
|
+
directory "roles" do
|
146
|
+
file "role1.json", {}
|
147
|
+
file "role2.xml", ""
|
148
|
+
file "subdir/role.json", {}
|
149
|
+
end
|
150
|
+
directory "environments" do
|
151
|
+
file "environment1.json", {}
|
152
|
+
file "environment2.xml", ""
|
153
|
+
file "subdir/environment.json", {}
|
154
|
+
end
|
155
|
+
|
156
|
+
it "knife list --local -R / should NOT return them" do
|
157
|
+
pending "Decide whether this is a good/bad idea" do
|
158
|
+
knife('list --local -R /').should_succeed <<EOM
|
159
|
+
/:
|
160
|
+
data_bags
|
161
|
+
environments
|
162
|
+
roles
|
163
|
+
|
164
|
+
/data_bags:
|
165
|
+
bag1
|
166
|
+
|
167
|
+
/data_bags/bag1:
|
168
|
+
item1.json
|
169
|
+
|
170
|
+
/environments:
|
171
|
+
environment1.json
|
172
|
+
|
173
|
+
/roles:
|
174
|
+
role1.json
|
175
|
+
EOM
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
when_the_repository "has extraneous subdirectories and files under cookbooks" do
|
181
|
+
directory 'cookbooks/cookbook1' do
|
182
|
+
file 'a.rb', ''
|
183
|
+
file 'blarghle/blah.rb', ''
|
184
|
+
directory 'attributes' do
|
185
|
+
file 'a.rb', ''
|
186
|
+
file 'b.json', {}
|
187
|
+
file 'c/d.rb', ''
|
188
|
+
file 'c/e.json', {}
|
189
|
+
end
|
190
|
+
directory 'definitions' do
|
191
|
+
file 'a.rb', ''
|
192
|
+
file 'b.json', {}
|
193
|
+
file 'c/d.rb', ''
|
194
|
+
file 'c/e.json', {}
|
195
|
+
end
|
196
|
+
directory 'recipes' do
|
197
|
+
file 'a.rb', ''
|
198
|
+
file 'b.json', {}
|
199
|
+
file 'c/d.rb', ''
|
200
|
+
file 'c/e.json', {}
|
201
|
+
end
|
202
|
+
directory 'libraries' do
|
203
|
+
file 'a.rb', ''
|
204
|
+
file 'b.json', {}
|
205
|
+
file 'c/d.rb', ''
|
206
|
+
file 'c/e.json', {}
|
207
|
+
end
|
208
|
+
directory 'templates' do
|
209
|
+
file 'a.rb', ''
|
210
|
+
file 'b.json', {}
|
211
|
+
file 'c/d.rb', ''
|
212
|
+
file 'c/e.json', {}
|
213
|
+
end
|
214
|
+
directory 'files' do
|
215
|
+
file 'a.rb', ''
|
216
|
+
file 'b.json', {}
|
217
|
+
file 'c/d.rb', ''
|
218
|
+
file 'c/e.json', {}
|
219
|
+
end
|
220
|
+
directory 'resources' do
|
221
|
+
file 'a.rb', ''
|
222
|
+
file 'b.json', {}
|
223
|
+
file 'c/d.rb', ''
|
224
|
+
file 'c/e.json', {}
|
225
|
+
end
|
226
|
+
directory 'providers' do
|
227
|
+
file 'a.rb', ''
|
228
|
+
file 'b.json', {}
|
229
|
+
file 'c/d.rb', ''
|
230
|
+
file 'c/e.json', {}
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
it "knife list --local -R / should NOT return them" do
|
235
|
+
pending "Decide whether this is a good idea" do
|
236
|
+
knife('list --local -R /').should_succeed <<EOM
|
237
|
+
/:
|
238
|
+
cookbooks
|
239
|
+
|
240
|
+
/cookbooks:
|
241
|
+
cookbook1
|
242
|
+
|
243
|
+
/cookbooks/cookbook1:
|
244
|
+
a.rb
|
245
|
+
attributes
|
246
|
+
definitions
|
247
|
+
files
|
248
|
+
libraries
|
249
|
+
providers
|
250
|
+
recipes
|
251
|
+
resources
|
252
|
+
templates
|
253
|
+
|
254
|
+
/cookbooks/cookbook1/attributes:
|
255
|
+
a.rb
|
256
|
+
|
257
|
+
/cookbooks/cookbook1/definitions:
|
258
|
+
a.rb
|
259
|
+
|
260
|
+
/cookbooks/cookbook1/files:
|
261
|
+
a.rb
|
262
|
+
b.json
|
263
|
+
c
|
264
|
+
|
265
|
+
/cookbooks/cookbook1/files/c:
|
266
|
+
d.rb
|
267
|
+
e.json
|
268
|
+
|
269
|
+
/cookbooks/cookbook1/libraries:
|
270
|
+
a.rb
|
271
|
+
|
272
|
+
/cookbooks/cookbook1/providers:
|
273
|
+
a.rb
|
274
|
+
c
|
275
|
+
|
276
|
+
/cookbooks/cookbook1/providers/c:
|
277
|
+
d.rb
|
278
|
+
|
279
|
+
/cookbooks/cookbook1/recipes:
|
280
|
+
a.rb
|
281
|
+
|
282
|
+
/cookbooks/cookbook1/resources:
|
283
|
+
a.rb
|
284
|
+
c
|
285
|
+
|
286
|
+
/cookbooks/cookbook1/resources/c:
|
287
|
+
d.rb
|
288
|
+
|
289
|
+
/cookbooks/cookbook1/templates:
|
290
|
+
a.rb
|
291
|
+
b.json
|
292
|
+
c
|
293
|
+
|
294
|
+
/cookbooks/cookbook1/templates/c:
|
295
|
+
d.rb
|
296
|
+
e.json
|
297
|
+
EOM
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
when_the_repository "has a file in cookbooks/" do
|
303
|
+
file 'cookbooks/file', ''
|
304
|
+
it 'does not show up in list -R' do
|
305
|
+
pending "don't show files when only directories are allowed" do
|
306
|
+
knife('list --local -R /').should_succeed <<EOM
|
307
|
+
/:
|
308
|
+
cookbooks
|
309
|
+
|
310
|
+
/cookbooks:
|
311
|
+
EOM
|
312
|
+
end
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
when_the_repository "has a file in data_bags/" do
|
317
|
+
file 'data_bags/file', ''
|
318
|
+
it 'does not show up in list -R' do
|
319
|
+
pending "don't show files when only directories are allowed" do
|
320
|
+
knife('list --local -R /').should_succeed <<EOM
|
321
|
+
/:
|
322
|
+
data_bags
|
323
|
+
|
324
|
+
/data_bags:
|
325
|
+
EOM
|
326
|
+
end
|
327
|
+
end
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
context 'chefignore tests' do
|
332
|
+
when_the_repository "has lots of stuff in it" do
|
333
|
+
file 'roles/x.json', {}
|
334
|
+
file 'environments/x.json', {}
|
335
|
+
file 'data_bags/bag1/x.json', {}
|
336
|
+
file 'cookbooks/cookbook1/x.json', {}
|
337
|
+
|
338
|
+
context "and has a chefignore everywhere except cookbooks" do
|
339
|
+
chefignore = "x.json\nroles/x.json\nenvironments/x.json\ndata_bags/bag1/x.json\nbag1/x.json\ncookbooks/cookbook1/x.json\ncookbook1/x.json\n"
|
340
|
+
file 'chefignore', chefignore
|
341
|
+
file 'roles/chefignore', chefignore
|
342
|
+
file 'environments/chefignore', chefignore
|
343
|
+
file 'data_bags/chefignore', chefignore
|
344
|
+
file 'data_bags/bag1/chefignore', chefignore
|
345
|
+
file 'cookbooks/cookbook1/chefignore', chefignore
|
346
|
+
|
347
|
+
it 'nothing is ignored' do
|
348
|
+
# NOTE: many of the "chefignore" files should probably not show up
|
349
|
+
# themselves, but we have other tests that talk about that
|
350
|
+
knife('list --local -R /').should_succeed <<EOM
|
351
|
+
/:
|
352
|
+
cookbooks
|
353
|
+
data_bags
|
354
|
+
environments
|
355
|
+
roles
|
356
|
+
|
357
|
+
/cookbooks:
|
358
|
+
cookbook1
|
359
|
+
|
360
|
+
/cookbooks/cookbook1:
|
361
|
+
chefignore
|
362
|
+
x.json
|
363
|
+
|
364
|
+
/data_bags:
|
365
|
+
bag1
|
366
|
+
chefignore
|
367
|
+
|
368
|
+
/data_bags/bag1:
|
369
|
+
chefignore
|
370
|
+
x.json
|
371
|
+
|
372
|
+
/environments:
|
373
|
+
chefignore
|
374
|
+
x.json
|
375
|
+
|
376
|
+
/roles:
|
377
|
+
chefignore
|
378
|
+
x.json
|
379
|
+
EOM
|
380
|
+
end
|
381
|
+
end
|
382
|
+
end
|
383
|
+
|
384
|
+
when_the_repository 'has a cookbook with only chefignored files' do
|
385
|
+
file 'cookbooks/cookbook1/templates/default/x.rb', ''
|
386
|
+
file 'cookbooks/cookbook1/libraries/x.rb', ''
|
387
|
+
file 'cookbooks/chefignore', "libraries/x.rb\ntemplates/default/x.rb\n"
|
388
|
+
|
389
|
+
it 'the cookbook is not listed' do
|
390
|
+
knife('list --local -R /').should_succeed <<EOM
|
391
|
+
/:
|
392
|
+
cookbooks
|
393
|
+
|
394
|
+
/cookbooks:
|
395
|
+
chefignore
|
396
|
+
EOM
|
397
|
+
end
|
398
|
+
end
|
399
|
+
|
400
|
+
when_the_repository "has multiple cookbooks" do
|
401
|
+
file 'cookbooks/cookbook1/x.json', {}
|
402
|
+
file 'cookbooks/cookbook1/y.json', {}
|
403
|
+
file 'cookbooks/cookbook2/x.json', {}
|
404
|
+
file 'cookbooks/cookbook2/y.json', {}
|
405
|
+
|
406
|
+
context 'and has a chefignore with filenames' do
|
407
|
+
file 'cookbooks/chefignore', "x.json\n"
|
408
|
+
|
409
|
+
it 'matching files and directories get ignored in all cookbooks' do
|
410
|
+
knife('list --local -R /').should_succeed <<EOM
|
411
|
+
/:
|
412
|
+
cookbooks
|
413
|
+
|
414
|
+
/cookbooks:
|
415
|
+
chefignore
|
416
|
+
cookbook1
|
417
|
+
cookbook2
|
418
|
+
|
419
|
+
/cookbooks/cookbook1:
|
420
|
+
y.json
|
421
|
+
|
422
|
+
/cookbooks/cookbook2:
|
423
|
+
y.json
|
424
|
+
EOM
|
425
|
+
end
|
426
|
+
end
|
427
|
+
|
428
|
+
context "and has a chefignore with wildcards" do
|
429
|
+
file 'cookbooks/chefignore', "x.*\n"
|
430
|
+
file 'cookbooks/cookbook1/x.rb', ''
|
431
|
+
|
432
|
+
it 'matching files and directories get ignored in all cookbooks' do
|
433
|
+
knife('list --local -R /').should_succeed <<EOM
|
434
|
+
/:
|
435
|
+
cookbooks
|
436
|
+
|
437
|
+
/cookbooks:
|
438
|
+
chefignore
|
439
|
+
cookbook1
|
440
|
+
cookbook2
|
441
|
+
|
442
|
+
/cookbooks/cookbook1:
|
443
|
+
y.json
|
444
|
+
|
445
|
+
/cookbooks/cookbook2:
|
446
|
+
y.json
|
447
|
+
EOM
|
448
|
+
end
|
449
|
+
end
|
450
|
+
|
451
|
+
context "and has a chefignore with relative paths" do
|
452
|
+
file 'cookbooks/cookbook1/recipes/x.rb', ''
|
453
|
+
file 'cookbooks/cookbook2/recipes/y.rb', ''
|
454
|
+
file 'cookbooks/chefignore', "recipes/x.rb\n"
|
455
|
+
|
456
|
+
it 'matching directories get ignored' do
|
457
|
+
knife('list --local -R /').should_succeed <<EOM
|
458
|
+
/:
|
459
|
+
cookbooks
|
460
|
+
|
461
|
+
/cookbooks:
|
462
|
+
chefignore
|
463
|
+
cookbook1
|
464
|
+
cookbook2
|
465
|
+
|
466
|
+
/cookbooks/cookbook1:
|
467
|
+
x.json
|
468
|
+
y.json
|
469
|
+
|
470
|
+
/cookbooks/cookbook2:
|
471
|
+
recipes
|
472
|
+
x.json
|
473
|
+
y.json
|
474
|
+
|
475
|
+
/cookbooks/cookbook2/recipes:
|
476
|
+
y.rb
|
477
|
+
EOM
|
478
|
+
end
|
479
|
+
end
|
480
|
+
|
481
|
+
context "and has a chefignore with subdirectories" do
|
482
|
+
file 'cookbooks/cookbook1/recipes/y.rb', ''
|
483
|
+
file 'cookbooks/chefignore', "recipes\n"
|
484
|
+
|
485
|
+
it 'matching directories do NOT get ignored' do
|
486
|
+
knife('list --local -R /').should_succeed <<EOM
|
487
|
+
/:
|
488
|
+
cookbooks
|
489
|
+
|
490
|
+
/cookbooks:
|
491
|
+
chefignore
|
492
|
+
cookbook1
|
493
|
+
cookbook2
|
494
|
+
|
495
|
+
/cookbooks/cookbook1:
|
496
|
+
recipes
|
497
|
+
x.json
|
498
|
+
y.json
|
499
|
+
|
500
|
+
/cookbooks/cookbook1/recipes:
|
501
|
+
y.rb
|
502
|
+
|
503
|
+
/cookbooks/cookbook2:
|
504
|
+
x.json
|
505
|
+
y.json
|
506
|
+
EOM
|
507
|
+
end
|
508
|
+
end
|
509
|
+
|
510
|
+
context "and has a chefignore that ignores all files in a subdirectory" do
|
511
|
+
file 'cookbooks/cookbook1/templates/default/x.rb', ''
|
512
|
+
file 'cookbooks/cookbook1/libraries/x.rb', ''
|
513
|
+
file 'cookbooks/chefignore', "libraries/x.rb\ntemplates/default/x.rb\n"
|
514
|
+
|
515
|
+
it 'ignores the subdirectory entirely' do
|
516
|
+
knife('list --local -R /').should_succeed <<EOM
|
517
|
+
/:
|
518
|
+
cookbooks
|
519
|
+
|
520
|
+
/cookbooks:
|
521
|
+
chefignore
|
522
|
+
cookbook1
|
523
|
+
cookbook2
|
524
|
+
|
525
|
+
/cookbooks/cookbook1:
|
526
|
+
x.json
|
527
|
+
y.json
|
528
|
+
|
529
|
+
/cookbooks/cookbook2:
|
530
|
+
x.json
|
531
|
+
y.json
|
532
|
+
EOM
|
533
|
+
end
|
534
|
+
end
|
535
|
+
|
536
|
+
context "and has an empty chefignore" do
|
537
|
+
file 'cookbooks/chefignore', "\n"
|
538
|
+
|
539
|
+
it 'nothing is ignored' do
|
540
|
+
knife('list --local -R /').should_succeed <<EOM
|
541
|
+
/:
|
542
|
+
cookbooks
|
543
|
+
|
544
|
+
/cookbooks:
|
545
|
+
chefignore
|
546
|
+
cookbook1
|
547
|
+
cookbook2
|
548
|
+
|
549
|
+
/cookbooks/cookbook1:
|
550
|
+
x.json
|
551
|
+
y.json
|
552
|
+
|
553
|
+
/cookbooks/cookbook2:
|
554
|
+
x.json
|
555
|
+
y.json
|
556
|
+
EOM
|
557
|
+
end
|
558
|
+
end
|
559
|
+
|
560
|
+
context "and has a chefignore with comments and empty lines" do
|
561
|
+
file 'cookbooks/chefignore', "\n\n # blah\n#\nx.json\n\n"
|
562
|
+
|
563
|
+
it 'matching files and directories get ignored in all cookbooks' do
|
564
|
+
knife('list --local -R /').should_succeed <<EOM
|
565
|
+
/:
|
566
|
+
cookbooks
|
567
|
+
|
568
|
+
/cookbooks:
|
569
|
+
chefignore
|
570
|
+
cookbook1
|
571
|
+
cookbook2
|
572
|
+
|
573
|
+
/cookbooks/cookbook1:
|
574
|
+
y.json
|
575
|
+
|
576
|
+
/cookbooks/cookbook2:
|
577
|
+
y.json
|
578
|
+
EOM
|
579
|
+
end
|
580
|
+
end
|
581
|
+
end
|
582
|
+
|
583
|
+
when_the_repository "has multiple cookbook paths" do
|
584
|
+
before :each do
|
585
|
+
Chef::Config.cookbook_path = [
|
586
|
+
File.join(Chef::Config.chef_repo_path, 'cookbooks1'),
|
587
|
+
File.join(Chef::Config.chef_repo_path, 'cookbooks2')
|
588
|
+
]
|
589
|
+
end
|
590
|
+
|
591
|
+
file 'cookbooks1/mycookbook/metadata.rb', ''
|
592
|
+
file 'cookbooks1/mycookbook/x.json', {}
|
593
|
+
file 'cookbooks2/yourcookbook/metadata.rb', ''
|
594
|
+
file 'cookbooks2/yourcookbook/x.json', ''
|
595
|
+
|
596
|
+
context "and multiple chefignores" do
|
597
|
+
file 'cookbooks1/chefignore', "metadata.rb\n"
|
598
|
+
file 'cookbooks2/chefignore', "x.json\n"
|
599
|
+
it "chefignores apply only to the directories they are in" do
|
600
|
+
knife('list --local -R /').should_succeed <<EOM
|
601
|
+
/:
|
602
|
+
cookbooks
|
603
|
+
|
604
|
+
/cookbooks:
|
605
|
+
chefignore
|
606
|
+
mycookbook
|
607
|
+
yourcookbook
|
608
|
+
|
609
|
+
/cookbooks/mycookbook:
|
610
|
+
x.json
|
611
|
+
|
612
|
+
/cookbooks/yourcookbook:
|
613
|
+
metadata.rb
|
614
|
+
EOM
|
615
|
+
end
|
616
|
+
|
617
|
+
context "and conflicting cookbooks" do
|
618
|
+
file 'cookbooks1/yourcookbook/metadata.rb', ''
|
619
|
+
file 'cookbooks1/yourcookbook/x.json', ''
|
620
|
+
file 'cookbooks1/yourcookbook/onlyincookbooks1.rb', ''
|
621
|
+
file 'cookbooks2/yourcookbook/onlyincookbooks2.rb', ''
|
622
|
+
|
623
|
+
it "chefignores apply only to the winning cookbook" do
|
624
|
+
knife('list --local -R /').should_succeed <<EOM
|
625
|
+
/:
|
626
|
+
cookbooks
|
627
|
+
|
628
|
+
/cookbooks:
|
629
|
+
chefignore
|
630
|
+
mycookbook
|
631
|
+
yourcookbook
|
632
|
+
|
633
|
+
/cookbooks/mycookbook:
|
634
|
+
x.json
|
635
|
+
|
636
|
+
/cookbooks/yourcookbook:
|
637
|
+
onlyincookbooks1.rb
|
638
|
+
x.json
|
639
|
+
EOM
|
640
|
+
end
|
641
|
+
end
|
642
|
+
end
|
643
|
+
end
|
644
|
+
end
|
645
|
+
|
646
|
+
# TODO alternate repo_path / *_path
|
647
|
+
# TODO multiple *_path
|
648
|
+
# TODO nonexistent repo_path / *_path
|
649
|
+
# TODO empty *_path
|
650
|
+
end
|