knife-essentials 0.7.6 → 0.8
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/Rakefile +2 -2
- data/lib/chef/knife/{delete.rb → delete_essentials.rb} +10 -2
- data/lib/chef/knife/dependencies_essentials.rb +117 -0
- data/lib/chef/knife/{diff.rb → diff_essentials.rb} +3 -1
- data/lib/chef/knife/{download.rb → download_essentials.rb} +9 -4
- data/lib/chef/knife/{list.rb → list_essentials.rb} +8 -2
- data/lib/chef/knife/{raw.rb → raw_essentials.rb} +2 -0
- data/lib/chef/knife/{show.rb → show_essentials.rb} +3 -1
- data/lib/chef/knife/{upload.rb → upload_essentials.rb} +9 -4
- data/lib/chef_fs/command_line.rb +18 -0
- data/lib/chef_fs/file_pattern.rb +18 -0
- data/lib/chef_fs/file_system.rb +18 -1
- data/lib/chef_fs/file_system/base_fs_dir.rb +18 -0
- data/lib/chef_fs/file_system/base_fs_object.rb +19 -1
- data/lib/chef_fs/file_system/chef_repository_file_system_entry.rb +49 -8
- data/lib/chef_fs/file_system/chef_repository_file_system_root_dir.rb +62 -3
- data/lib/chef_fs/file_system/chef_server_root_dir.rb +18 -0
- data/lib/chef_fs/file_system/cookbook_dir.rb +26 -0
- data/lib/chef_fs/file_system/cookbook_file.rb +18 -0
- data/lib/chef_fs/file_system/cookbook_subdir.rb +18 -0
- data/lib/chef_fs/file_system/cookbooks_dir.rb +18 -2
- data/lib/chef_fs/file_system/data_bag_dir.rb +18 -0
- data/lib/chef_fs/file_system/data_bag_item.rb +18 -0
- data/lib/chef_fs/file_system/data_bags_dir.rb +18 -0
- data/lib/chef_fs/file_system/file_system_entry.rb +18 -0
- data/lib/chef_fs/file_system/file_system_error.rb +18 -0
- data/lib/chef_fs/file_system/file_system_root_dir.rb +18 -0
- data/lib/chef_fs/file_system/multiplexed_dir.rb +46 -0
- data/lib/chef_fs/file_system/must_delete_recursively_error.rb +18 -0
- data/lib/chef_fs/file_system/nodes_dir.rb +18 -0
- data/lib/chef_fs/file_system/nonexistent_fs_object.rb +18 -0
- data/lib/chef_fs/file_system/not_found_error.rb +18 -0
- data/lib/chef_fs/file_system/rest_list_dir.rb +18 -0
- data/lib/chef_fs/file_system/rest_list_entry.rb +18 -0
- data/lib/chef_fs/knife.rb +128 -18
- data/lib/chef_fs/path_utils.rb +19 -1
- data/lib/chef_fs/version.rb +1 -1
- data/spec/chef_fs/diff_spec.rb +69 -44
- data/spec/chef_fs/file_pattern_spec.rb +497 -479
- data/spec/chef_fs/file_system/chef_server_root_dir_spec.rb +18 -0
- data/spec/chef_fs/file_system/cookbooks_dir_spec.rb +18 -0
- data/spec/chef_fs/file_system/data_bags_dir_spec.rb +18 -0
- data/spec/chef_fs/file_system_spec.rb +124 -106
- data/spec/support/file_system_support.rb +93 -75
- metadata +12 -11
- data/lib/chef/sandbox_uploader.rb +0 -208
@@ -1,508 +1,526 @@
|
|
1
|
+
#
|
2
|
+
# Author:: John Keiser (<jkeiser@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2012 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
|
+
|
1
19
|
require 'support/spec_helper'
|
2
20
|
require 'chef_fs/file_pattern'
|
3
21
|
|
4
22
|
describe ChefFS::FilePattern do
|
5
|
-
|
6
|
-
|
7
|
-
|
23
|
+
def p(str)
|
24
|
+
ChefFS::FilePattern.new(str)
|
25
|
+
end
|
8
26
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
27
|
+
# Different kinds of patterns
|
28
|
+
context 'with empty pattern ""' do
|
29
|
+
let(:pattern) { ChefFS::FilePattern.new('') }
|
30
|
+
it 'match?' do
|
31
|
+
pattern.match?('').should be_true
|
32
|
+
pattern.match?('/').should be_false
|
33
|
+
pattern.match?('a').should be_false
|
34
|
+
pattern.match?('a/b').should be_false
|
35
|
+
end
|
36
|
+
it 'exact_path' do
|
37
|
+
pattern.exact_path.should == ''
|
38
|
+
end
|
39
|
+
it 'could_match_children?' do
|
40
|
+
pattern.could_match_children?('').should be_false
|
41
|
+
pattern.could_match_children?('a/b').should be_false
|
42
|
+
end
|
43
|
+
end
|
26
44
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
45
|
+
context 'with root pattern "/"' do
|
46
|
+
let(:pattern) { ChefFS::FilePattern.new('/') }
|
47
|
+
it 'match?' do
|
48
|
+
pattern.match?('/').should be_true
|
49
|
+
pattern.match?('').should be_false
|
50
|
+
pattern.match?('a').should be_false
|
51
|
+
pattern.match?('/a').should be_false
|
52
|
+
end
|
53
|
+
it 'exact_path' do
|
54
|
+
pattern.exact_path.should == '/'
|
55
|
+
end
|
56
|
+
it 'could_match_children?' do
|
57
|
+
pattern.could_match_children?('').should be_false
|
58
|
+
pattern.could_match_children?('/').should be_false
|
59
|
+
pattern.could_match_children?('a').should be_false
|
60
|
+
pattern.could_match_children?('a/b').should be_false
|
61
|
+
pattern.could_match_children?('/a').should be_false
|
62
|
+
end
|
63
|
+
end
|
46
64
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
65
|
+
context 'with simple pattern "abc"' do
|
66
|
+
let(:pattern) { ChefFS::FilePattern.new('abc') }
|
67
|
+
it 'match?' do
|
68
|
+
pattern.match?('abc').should be_true
|
69
|
+
pattern.match?('a').should be_false
|
70
|
+
pattern.match?('abcd').should be_false
|
71
|
+
pattern.match?('/abc').should be_false
|
72
|
+
pattern.match?('').should be_false
|
73
|
+
pattern.match?('/').should be_false
|
74
|
+
end
|
75
|
+
it 'exact_path' do
|
76
|
+
pattern.exact_path.should == 'abc'
|
77
|
+
end
|
78
|
+
it 'could_match_children?' do
|
79
|
+
pattern.could_match_children?('').should be_false
|
80
|
+
pattern.could_match_children?('abc').should be_false
|
81
|
+
pattern.could_match_children?('/abc').should be_false
|
82
|
+
end
|
83
|
+
end
|
66
84
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
85
|
+
context 'with simple pattern "/abc"' do
|
86
|
+
let(:pattern) { ChefFS::FilePattern.new('/abc') }
|
87
|
+
it 'match?' do
|
88
|
+
pattern.match?('/abc').should be_true
|
89
|
+
pattern.match?('abc').should be_false
|
90
|
+
pattern.match?('a').should be_false
|
91
|
+
pattern.match?('abcd').should be_false
|
92
|
+
pattern.match?('').should be_false
|
93
|
+
pattern.match?('/').should be_false
|
94
|
+
end
|
95
|
+
it 'exact_path' do
|
96
|
+
pattern.exact_path.should == '/abc'
|
97
|
+
end
|
98
|
+
it 'could_match_children?' do
|
99
|
+
pattern.could_match_children?('abc').should be_false
|
100
|
+
pattern.could_match_children?('/abc').should be_false
|
101
|
+
pattern.could_match_children?('/').should be_true
|
102
|
+
pattern.could_match_children?('').should be_false
|
103
|
+
end
|
104
|
+
it 'exact_child_name_under' do
|
105
|
+
pattern.exact_child_name_under('/').should == 'abc'
|
106
|
+
end
|
107
|
+
end
|
90
108
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
109
|
+
context 'with simple pattern "abc/def/ghi"' do
|
110
|
+
let(:pattern) { ChefFS::FilePattern.new('abc/def/ghi') }
|
111
|
+
it 'match?' do
|
112
|
+
pattern.match?('abc/def/ghi').should be_true
|
113
|
+
pattern.match?('/abc/def/ghi').should be_false
|
114
|
+
pattern.match?('abc').should be_false
|
115
|
+
pattern.match?('abc/def').should be_false
|
116
|
+
end
|
117
|
+
it 'exact_path' do
|
118
|
+
pattern.exact_path.should == 'abc/def/ghi'
|
119
|
+
end
|
120
|
+
it 'could_match_children?' do
|
121
|
+
pattern.could_match_children?('abc').should be_true
|
122
|
+
pattern.could_match_children?('xyz').should be_false
|
123
|
+
pattern.could_match_children?('/abc').should be_false
|
124
|
+
pattern.could_match_children?('abc/def').should be_true
|
125
|
+
pattern.could_match_children?('abc/xyz').should be_false
|
126
|
+
pattern.could_match_children?('abc/def/ghi').should be_false
|
127
|
+
end
|
128
|
+
it 'exact_child_name_under' do
|
129
|
+
pattern.exact_child_name_under('abc').should == 'def'
|
130
|
+
pattern.exact_child_name_under('abc/def').should == 'ghi'
|
131
|
+
end
|
132
|
+
end
|
115
133
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
134
|
+
context 'with simple pattern "/abc/def/ghi"' do
|
135
|
+
let(:pattern) { ChefFS::FilePattern.new('/abc/def/ghi') }
|
136
|
+
it 'match?' do
|
137
|
+
pattern.match?('/abc/def/ghi').should be_true
|
138
|
+
pattern.match?('abc/def/ghi').should be_false
|
139
|
+
pattern.match?('/abc').should be_false
|
140
|
+
pattern.match?('/abc/def').should be_false
|
141
|
+
end
|
142
|
+
it 'exact_path' do
|
143
|
+
pattern.exact_path.should == '/abc/def/ghi'
|
144
|
+
end
|
145
|
+
it 'could_match_children?' do
|
146
|
+
pattern.could_match_children?('/abc').should be_true
|
147
|
+
pattern.could_match_children?('/xyz').should be_false
|
148
|
+
pattern.could_match_children?('abc').should be_false
|
149
|
+
pattern.could_match_children?('/abc/def').should be_true
|
150
|
+
pattern.could_match_children?('/abc/xyz').should be_false
|
151
|
+
pattern.could_match_children?('/abc/def/ghi').should be_false
|
152
|
+
end
|
153
|
+
it 'exact_child_name_under' do
|
154
|
+
pattern.exact_child_name_under('/').should == 'abc'
|
155
|
+
pattern.exact_child_name_under('/abc').should == 'def'
|
156
|
+
pattern.exact_child_name_under('/abc/def').should == 'ghi'
|
157
|
+
end
|
158
|
+
end
|
141
159
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
160
|
+
context 'with simple pattern "a\*\b"' do
|
161
|
+
let(:pattern) { ChefFS::FilePattern.new('a\*\b') }
|
162
|
+
it 'match?' do
|
163
|
+
pattern.match?('a*b').should be_true
|
164
|
+
pattern.match?('ab').should be_false
|
165
|
+
pattern.match?('acb').should be_false
|
166
|
+
pattern.match?('ab').should be_false
|
167
|
+
end
|
168
|
+
it 'exact_path' do
|
169
|
+
pattern.exact_path.should == 'a*b'
|
170
|
+
end
|
171
|
+
it 'could_match_children?' do
|
172
|
+
pattern.could_match_children?('a/*b').should be_false
|
173
|
+
end
|
174
|
+
end
|
157
175
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
176
|
+
context 'with star pattern "/abc/*/ghi"' do
|
177
|
+
let(:pattern) { ChefFS::FilePattern.new('/abc/*/ghi') }
|
178
|
+
it 'match?' do
|
179
|
+
pattern.match?('/abc/def/ghi').should be_true
|
180
|
+
pattern.match?('/abc/ghi').should be_false
|
181
|
+
end
|
182
|
+
it 'exact_path' do
|
183
|
+
pattern.exact_path.should be_nil
|
184
|
+
end
|
185
|
+
it 'could_match_children?' do
|
186
|
+
pattern.could_match_children?('/abc').should be_true
|
187
|
+
pattern.could_match_children?('/xyz').should be_false
|
188
|
+
pattern.could_match_children?('abc').should be_false
|
189
|
+
pattern.could_match_children?('/abc/def').should be_true
|
190
|
+
pattern.could_match_children?('/abc/xyz').should be_true
|
191
|
+
pattern.could_match_children?('/abc/def/ghi').should be_false
|
192
|
+
end
|
193
|
+
it 'exact_child_name_under' do
|
194
|
+
pattern.exact_child_name_under('/').should == 'abc'
|
195
|
+
pattern.exact_child_name_under('/abc').should == nil
|
196
|
+
pattern.exact_child_name_under('/abc/def').should == 'ghi'
|
197
|
+
end
|
198
|
+
end
|
181
199
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
200
|
+
context 'with star pattern "/abc/d*f/ghi"' do
|
201
|
+
let(:pattern) { ChefFS::FilePattern.new('/abc/d*f/ghi') }
|
202
|
+
it 'match?' do
|
203
|
+
pattern.match?('/abc/def/ghi').should be_true
|
204
|
+
pattern.match?('/abc/dxf/ghi').should be_true
|
205
|
+
pattern.match?('/abc/df/ghi').should be_true
|
206
|
+
pattern.match?('/abc/dxyzf/ghi').should be_true
|
207
|
+
pattern.match?('/abc/d/ghi').should be_false
|
208
|
+
pattern.match?('/abc/f/ghi').should be_false
|
209
|
+
pattern.match?('/abc/ghi').should be_false
|
210
|
+
pattern.match?('/abc/xyz/ghi').should be_false
|
211
|
+
end
|
212
|
+
it 'exact_path' do
|
213
|
+
pattern.exact_path.should be_nil
|
214
|
+
end
|
215
|
+
it 'could_match_children?' do
|
216
|
+
pattern.could_match_children?('/abc').should be_true
|
217
|
+
pattern.could_match_children?('/xyz').should be_false
|
218
|
+
pattern.could_match_children?('abc').should be_false
|
219
|
+
pattern.could_match_children?('/abc/def').should be_true
|
220
|
+
pattern.could_match_children?('/abc/xyz').should be_false
|
221
|
+
pattern.could_match_children?('/abc/dxyzf').should be_true
|
222
|
+
pattern.could_match_children?('/abc/df').should be_true
|
223
|
+
pattern.could_match_children?('/abc/d').should be_false
|
224
|
+
pattern.could_match_children?('/abc/f').should be_false
|
225
|
+
pattern.could_match_children?('/abc/def/ghi').should be_false
|
226
|
+
end
|
227
|
+
it 'exact_child_name_under' do
|
228
|
+
pattern.exact_child_name_under('/').should == 'abc'
|
229
|
+
pattern.exact_child_name_under('/abc').should == nil
|
230
|
+
pattern.exact_child_name_under('/abc/def').should == 'ghi'
|
231
|
+
end
|
232
|
+
end
|
215
233
|
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
234
|
+
context 'with star pattern "/abc/d??f/ghi"' do
|
235
|
+
let(:pattern) { ChefFS::FilePattern.new('/abc/d??f/ghi') }
|
236
|
+
it 'match?' do
|
237
|
+
pattern.match?('/abc/deef/ghi').should be_true
|
238
|
+
pattern.match?('/abc/deeef/ghi').should be_false
|
239
|
+
pattern.match?('/abc/def/ghi').should be_false
|
240
|
+
pattern.match?('/abc/df/ghi').should be_false
|
241
|
+
pattern.match?('/abc/d/ghi').should be_false
|
242
|
+
pattern.match?('/abc/f/ghi').should be_false
|
243
|
+
pattern.match?('/abc/ghi').should be_false
|
244
|
+
end
|
245
|
+
it 'exact_path' do
|
246
|
+
pattern.exact_path.should be_nil
|
247
|
+
end
|
248
|
+
it 'could_match_children?' do
|
249
|
+
pattern.could_match_children?('/abc').should be_true
|
250
|
+
pattern.could_match_children?('/xyz').should be_false
|
251
|
+
pattern.could_match_children?('abc').should be_false
|
252
|
+
pattern.could_match_children?('/abc/deef').should be_true
|
253
|
+
pattern.could_match_children?('/abc/deeef').should be_false
|
254
|
+
pattern.could_match_children?('/abc/def').should be_false
|
255
|
+
pattern.could_match_children?('/abc/df').should be_false
|
256
|
+
pattern.could_match_children?('/abc/d').should be_false
|
257
|
+
pattern.could_match_children?('/abc/f').should be_false
|
258
|
+
pattern.could_match_children?('/abc/deef/ghi').should be_false
|
259
|
+
end
|
260
|
+
it 'exact_child_name_under' do
|
261
|
+
pattern.exact_child_name_under('/').should == 'abc'
|
262
|
+
pattern.exact_child_name_under('/abc').should == nil
|
263
|
+
pattern.exact_child_name_under('/abc/deef').should == 'ghi'
|
264
|
+
end
|
265
|
+
end
|
248
266
|
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
267
|
+
context 'with star pattern "/abc/d[a-z][0-9]f/ghi"' do
|
268
|
+
let(:pattern) { ChefFS::FilePattern.new('/abc/d[a-z][0-9]f/ghi') }
|
269
|
+
it 'match?' do
|
270
|
+
pattern.match?('/abc/de1f/ghi').should be_true
|
271
|
+
pattern.match?('/abc/deef/ghi').should be_false
|
272
|
+
pattern.match?('/abc/d11f/ghi').should be_false
|
273
|
+
pattern.match?('/abc/de11f/ghi').should be_false
|
274
|
+
pattern.match?('/abc/dee1f/ghi').should be_false
|
275
|
+
pattern.match?('/abc/df/ghi').should be_false
|
276
|
+
pattern.match?('/abc/d/ghi').should be_false
|
277
|
+
pattern.match?('/abc/f/ghi').should be_false
|
278
|
+
pattern.match?('/abc/ghi').should be_false
|
279
|
+
end
|
280
|
+
it 'exact_path' do
|
281
|
+
pattern.exact_path.should be_nil
|
282
|
+
end
|
283
|
+
it 'could_match_children?' do
|
284
|
+
pattern.could_match_children?('/abc').should be_true
|
285
|
+
pattern.could_match_children?('/xyz').should be_false
|
286
|
+
pattern.could_match_children?('abc').should be_false
|
287
|
+
pattern.could_match_children?('/abc/de1f').should be_true
|
288
|
+
pattern.could_match_children?('/abc/deef').should be_false
|
289
|
+
pattern.could_match_children?('/abc/d11f').should be_false
|
290
|
+
pattern.could_match_children?('/abc/de11f').should be_false
|
291
|
+
pattern.could_match_children?('/abc/dee1f').should be_false
|
292
|
+
pattern.could_match_children?('/abc/def').should be_false
|
293
|
+
pattern.could_match_children?('/abc/df').should be_false
|
294
|
+
pattern.could_match_children?('/abc/d').should be_false
|
295
|
+
pattern.could_match_children?('/abc/f').should be_false
|
296
|
+
pattern.could_match_children?('/abc/de1f/ghi').should be_false
|
297
|
+
end
|
298
|
+
it 'exact_child_name_under' do
|
299
|
+
pattern.exact_child_name_under('/').should == 'abc'
|
300
|
+
pattern.exact_child_name_under('/abc').should == nil
|
301
|
+
pattern.exact_child_name_under('/abc/de1f').should == 'ghi'
|
302
|
+
end
|
303
|
+
end
|
286
304
|
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
305
|
+
context 'with star pattern "/abc/**/ghi"' do
|
306
|
+
let(:pattern) { ChefFS::FilePattern.new('/abc/**/ghi') }
|
307
|
+
it 'match?' do
|
308
|
+
pattern.match?('/abc/def/ghi').should be_true
|
309
|
+
pattern.match?('/abc/d/e/f/ghi').should be_true
|
310
|
+
pattern.match?('/abc/ghi').should be_false
|
311
|
+
pattern.match?('/abcdef/d/ghi').should be_false
|
312
|
+
pattern.match?('/abc/d/defghi').should be_false
|
313
|
+
pattern.match?('/xyz').should be_false
|
314
|
+
end
|
315
|
+
it 'exact_path' do
|
316
|
+
pattern.exact_path.should be_nil
|
317
|
+
end
|
318
|
+
it 'could_match_children?' do
|
319
|
+
pattern.could_match_children?('/abc').should be_true
|
320
|
+
pattern.could_match_children?('/abc/d').should be_true
|
321
|
+
pattern.could_match_children?('/abc/d/e').should be_true
|
322
|
+
pattern.could_match_children?('/abc/d/e/f').should be_true
|
323
|
+
pattern.could_match_children?('/abc/def/ghi').should be_true
|
324
|
+
pattern.could_match_children?('abc').should be_false
|
325
|
+
pattern.could_match_children?('/xyz').should be_false
|
326
|
+
end
|
327
|
+
it 'exact_child_name_under' do
|
328
|
+
pattern.exact_child_name_under('/').should == 'abc'
|
329
|
+
pattern.exact_child_name_under('/abc').should == nil
|
330
|
+
pattern.exact_child_name_under('/abc/def').should == nil
|
331
|
+
end
|
332
|
+
end
|
315
333
|
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
334
|
+
context 'with star pattern "/abc**/ghi"' do
|
335
|
+
let(:pattern) { ChefFS::FilePattern.new('/abc**/ghi') }
|
336
|
+
it 'match?' do
|
337
|
+
pattern.match?('/abc/def/ghi').should be_true
|
338
|
+
pattern.match?('/abc/d/e/f/ghi').should be_true
|
339
|
+
pattern.match?('/abc/ghi').should be_true
|
340
|
+
pattern.match?('/abcdef/ghi').should be_true
|
341
|
+
pattern.match?('/abc/defghi').should be_false
|
342
|
+
pattern.match?('/xyz').should be_false
|
343
|
+
end
|
344
|
+
it 'exact_path' do
|
345
|
+
pattern.exact_path.should be_nil
|
346
|
+
end
|
347
|
+
it 'could_match_children?' do
|
348
|
+
pattern.could_match_children?('/abc').should be_true
|
349
|
+
pattern.could_match_children?('/abcdef').should be_true
|
350
|
+
pattern.could_match_children?('/abc/d/e').should be_true
|
351
|
+
pattern.could_match_children?('/abc/d/e/f').should be_true
|
352
|
+
pattern.could_match_children?('/abc/def/ghi').should be_true
|
353
|
+
pattern.could_match_children?('abc').should be_false
|
354
|
+
end
|
355
|
+
it 'could_match_children? /abc** returns false for /xyz' do
|
356
|
+
pending 'Make could_match_children? more rigorous' do
|
357
|
+
# At the moment, we return false for this, but in the end it would be nice to return true:
|
358
|
+
pattern.could_match_children?('/xyz').should be_false
|
359
|
+
end
|
360
|
+
end
|
361
|
+
it 'exact_child_name_under' do
|
362
|
+
pattern.exact_child_name_under('/').should == nil
|
363
|
+
pattern.exact_child_name_under('/abc').should == nil
|
364
|
+
pattern.exact_child_name_under('/abc/def').should == nil
|
365
|
+
end
|
366
|
+
end
|
349
367
|
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
368
|
+
context 'with star pattern "/abc/**ghi"' do
|
369
|
+
let(:pattern) { ChefFS::FilePattern.new('/abc/**ghi') }
|
370
|
+
it 'match?' do
|
371
|
+
pattern.match?('/abc/def/ghi').should be_true
|
372
|
+
pattern.match?('/abc/def/ghi/ghi').should be_true
|
373
|
+
pattern.match?('/abc/def/ghi/jkl').should be_false
|
374
|
+
pattern.match?('/abc/d/e/f/ghi').should be_true
|
375
|
+
pattern.match?('/abc/ghi').should be_true
|
376
|
+
pattern.match?('/abcdef/ghi').should be_false
|
377
|
+
pattern.match?('/abc/defghi').should be_true
|
378
|
+
pattern.match?('/xyz').should be_false
|
379
|
+
end
|
380
|
+
it 'exact_path' do
|
381
|
+
pattern.exact_path.should be_nil
|
382
|
+
end
|
383
|
+
it 'could_match_children?' do
|
384
|
+
pattern.could_match_children?('/abc').should be_true
|
385
|
+
pattern.could_match_children?('/abcdef').should be_false
|
386
|
+
pattern.could_match_children?('/abc/d/e').should be_true
|
387
|
+
pattern.could_match_children?('/abc/d/e/f').should be_true
|
388
|
+
pattern.could_match_children?('/abc/def/ghi').should be_true
|
389
|
+
pattern.could_match_children?('abc').should be_false
|
390
|
+
pattern.could_match_children?('/xyz').should be_false
|
391
|
+
end
|
392
|
+
it 'exact_child_name_under' do
|
393
|
+
pattern.exact_child_name_under('/').should == 'abc'
|
394
|
+
pattern.exact_child_name_under('/abc').should == nil
|
395
|
+
pattern.exact_child_name_under('/abc/def').should == nil
|
396
|
+
end
|
397
|
+
end
|
380
398
|
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
399
|
+
context 'with star pattern "a**b**c"' do
|
400
|
+
let(:pattern) { ChefFS::FilePattern.new('a**b**c') }
|
401
|
+
it 'match?' do
|
402
|
+
pattern.match?('axybzwc').should be_true
|
403
|
+
pattern.match?('abc').should be_true
|
404
|
+
pattern.match?('axyzwc').should be_false
|
405
|
+
pattern.match?('ac').should be_false
|
406
|
+
pattern.match?('a/x/y/b/z/w/c').should be_true
|
407
|
+
end
|
408
|
+
it 'exact_path' do
|
409
|
+
pattern.exact_path.should be_nil
|
410
|
+
end
|
411
|
+
end
|
394
412
|
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
413
|
+
context 'normalization tests' do
|
414
|
+
it 'handles trailing slashes' do
|
415
|
+
p('abc/').normalized_pattern.should == 'abc'
|
416
|
+
p('abc/').exact_path.should == 'abc'
|
417
|
+
p('abc/').match?('abc').should be_true
|
418
|
+
p('//').normalized_pattern.should == '/'
|
419
|
+
p('//').exact_path.should == '/'
|
420
|
+
p('//').match?('/').should be_true
|
421
|
+
p('/./').normalized_pattern.should == '/'
|
422
|
+
p('/./').exact_path.should == '/'
|
423
|
+
p('/./').match?('/').should be_true
|
424
|
+
end
|
425
|
+
it 'handles multiple slashes' do
|
426
|
+
p('abc//def').normalized_pattern.should == 'abc/def'
|
427
|
+
p('abc//def').exact_path.should == 'abc/def'
|
428
|
+
p('abc//def').match?('abc/def').should be_true
|
429
|
+
p('abc//').normalized_pattern.should == 'abc'
|
430
|
+
p('abc//').exact_path.should == 'abc'
|
431
|
+
p('abc//').match?('abc').should be_true
|
432
|
+
end
|
433
|
+
it 'handles dot' do
|
434
|
+
p('abc/./def').normalized_pattern.should == 'abc/def'
|
435
|
+
p('abc/./def').exact_path.should == 'abc/def'
|
436
|
+
p('abc/./def').match?('abc/def').should be_true
|
437
|
+
p('./abc/def').normalized_pattern.should == 'abc/def'
|
438
|
+
p('./abc/def').exact_path.should == 'abc/def'
|
439
|
+
p('./abc/def').match?('abc/def').should be_true
|
440
|
+
p('/.').normalized_pattern.should == '/'
|
441
|
+
p('/.').exact_path.should == '/'
|
442
|
+
p('/.').match?('/').should be_true
|
443
|
+
end
|
444
|
+
it 'handles dot by itself', :pending => "decide what to do with dot by itself" do
|
445
|
+
p('.').normalized_pattern.should == '.'
|
446
|
+
p('.').exact_path.should == '.'
|
447
|
+
p('.').match?('.').should be_true
|
448
|
+
p('./').normalized_pattern.should == '.'
|
449
|
+
p('./').exact_path.should == '.'
|
450
|
+
p('./').match?('.').should be_true
|
451
|
+
end
|
452
|
+
it 'handles dotdot' do
|
453
|
+
p('abc/../def').normalized_pattern.should == 'def'
|
454
|
+
p('abc/../def').exact_path.should == 'def'
|
455
|
+
p('abc/../def').match?('def').should be_true
|
456
|
+
p('abc/def/../..').normalized_pattern.should == ''
|
457
|
+
p('abc/def/../..').exact_path.should == ''
|
458
|
+
p('abc/def/../..').match?('').should be_true
|
459
|
+
p('/*/../def').normalized_pattern.should == '/def'
|
460
|
+
p('/*/../def').exact_path.should == '/def'
|
461
|
+
p('/*/../def').match?('/def').should be_true
|
462
|
+
p('/*/*/../def').normalized_pattern.should == '/*/def'
|
463
|
+
p('/*/*/../def').exact_path.should be_nil
|
464
|
+
p('/*/*/../def').match?('/abc/def').should be_true
|
465
|
+
p('/abc/def/../..').normalized_pattern.should == '/'
|
466
|
+
p('/abc/def/../..').exact_path.should == '/'
|
467
|
+
p('/abc/def/../..').match?('/').should be_true
|
468
|
+
p('abc/../../def').normalized_pattern.should == '../def'
|
469
|
+
p('abc/../../def').exact_path.should == '../def'
|
470
|
+
p('abc/../../def').match?('../def').should be_true
|
471
|
+
end
|
472
|
+
it 'handles dotdot with double star' do
|
473
|
+
p('abc**/def/../ghi').exact_path.should be_nil
|
474
|
+
p('abc**/def/../ghi').match?('abc/ghi').should be_true
|
475
|
+
p('abc**/def/../ghi').match?('abc/x/y/z/ghi').should be_true
|
476
|
+
p('abc**/def/../ghi').match?('ghi').should be_false
|
477
|
+
end
|
478
|
+
it 'raises error on dotdot with overlapping double star' do
|
479
|
+
lambda { ChefFS::FilePattern.new('abc/**/../def').exact_path }.should raise_error(ArgumentError)
|
480
|
+
lambda { ChefFS::FilePattern.new('abc/**/abc/../../def').exact_path }.should raise_error(ArgumentError)
|
481
|
+
end
|
482
|
+
it 'handles leading dotdot' do
|
483
|
+
p('../abc/def').exact_path.should == '../abc/def'
|
484
|
+
p('../abc/def').match?('../abc/def').should be_true
|
485
|
+
p('/../abc/def').exact_path.should == '/abc/def'
|
486
|
+
p('/../abc/def').match?('/abc/def').should be_true
|
487
|
+
p('..').exact_path.should == '..'
|
488
|
+
p('..').match?('..').should be_true
|
489
|
+
p('/..').exact_path.should == '/'
|
490
|
+
p('/..').match?('/').should be_true
|
491
|
+
end
|
492
|
+
end
|
475
493
|
|
476
494
|
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
495
|
+
# match?
|
496
|
+
# - single element matches (empty, fixed, ?, *, characters, escapes)
|
497
|
+
# - nested matches
|
498
|
+
# - absolute matches
|
499
|
+
# - trailing slashes
|
500
|
+
# - **
|
483
501
|
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
502
|
+
# exact_path
|
503
|
+
# - empty
|
504
|
+
# - single element and nested matches, with escapes
|
505
|
+
# - absolute and relative
|
506
|
+
# - ?, *, characters, **
|
489
507
|
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
508
|
+
# could_match_children?
|
509
|
+
#
|
510
|
+
#
|
511
|
+
#
|
512
|
+
#
|
513
|
+
context 'with pattern "abc"' do
|
514
|
+
end
|
497
515
|
|
498
|
-
|
499
|
-
|
516
|
+
context 'with pattern "/abc"' do
|
517
|
+
end
|
500
518
|
|
501
|
-
|
502
|
-
|
519
|
+
context 'with pattern "abc/def/ghi"' do
|
520
|
+
end
|
503
521
|
|
504
|
-
|
505
|
-
|
522
|
+
context 'with pattern "/abc/def/ghi"' do
|
523
|
+
end
|
506
524
|
|
507
|
-
|
525
|
+
# Exercise the different methods to their maximum
|
508
526
|
end
|