knife-essentials 0.1.1 → 0.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.
@@ -0,0 +1,202 @@
1
+ require 'chef_fs/file_system/chef_server_root_dir'
2
+
3
+ describe ChefFS::FileSystem::DataBagsDir do
4
+ let(:root_dir) {
5
+ ChefFS::FileSystem::ChefServerRootDir.new('remote',
6
+ {
7
+ :chef_server_url => 'url',
8
+ :node_name => 'username',
9
+ :client_key => 'key',
10
+ :environment => 'env'
11
+ })
12
+ }
13
+ let(:data_bags_dir) { root_dir.child('data_bags') }
14
+ let(:should_list_data_bags) do
15
+ @rest.should_receive(:get_rest).with('data').once.and_return(
16
+ {
17
+ "achild" => "http://opscode.com/achild",
18
+ "bchild" => "http://opscode.com/bchild"
19
+ })
20
+ end
21
+ before(:each) do
22
+ @rest = double("rest")
23
+ Chef::REST.stub(:new).with('url','username','key') { @rest }
24
+ end
25
+
26
+ it 'has / as parent' do
27
+ data_bags_dir.parent.should == root_dir
28
+ end
29
+ it 'is a directory' do
30
+ data_bags_dir.dir?.should be_true
31
+ end
32
+ it 'exists' do
33
+ data_bags_dir.exists?.should be_true
34
+ end
35
+ it 'has name data_bags' do
36
+ data_bags_dir.name.should == 'data_bags'
37
+ end
38
+ it 'has path /data_bags' do
39
+ data_bags_dir.path.should == '/data_bags'
40
+ end
41
+ it 'has path_for_printing remote/data_bags' do
42
+ data_bags_dir.path_for_printing.should == 'remote/data_bags'
43
+ end
44
+ it 'has correct children' do
45
+ should_list_data_bags
46
+ data_bags_dir.children.map { |child| child.name }.should =~ %w(achild bchild)
47
+ end
48
+ it 'can have directories as children' do
49
+ data_bags_dir.can_have_child?('blah', true).should be_true
50
+ end
51
+ it 'cannot have files as children' do
52
+ data_bags_dir.can_have_child?('blah', false).should be_false
53
+ end
54
+
55
+ shared_examples_for 'a data bag item' do
56
+ it 'has data bag as parent' do
57
+ data_bag_item.parent.should == data_bag_dir
58
+ end
59
+ it 'is not a directory' do
60
+ data_bag_item.dir?.should be_false
61
+ end
62
+ it 'exists' do
63
+ should_list_data_bag_items
64
+ data_bag_item.exists?.should be_true
65
+ end
66
+ it 'has correct name' do
67
+ data_bag_item.name.should == data_bag_item_name
68
+ end
69
+ it 'has correct path' do
70
+ data_bag_item.path.should == "/data_bags/#{data_bag_dir_name}/#{data_bag_item_name}"
71
+ end
72
+ it 'has correct path_for_printing' do
73
+ data_bag_item.path_for_printing.should == "remote/data_bags/#{data_bag_dir_name}/#{data_bag_item_name}"
74
+ end
75
+ it 'reads correctly' do
76
+ @rest.should_receive(:get_rest).with("data/#{data_bag_dir_name}/#{data_bag_item_short_name}/environments/env").once.and_return({
77
+ 'a' => 'b'
78
+ })
79
+ data_bag_item.read.should == '{
80
+ "a": "b"
81
+ }'
82
+ end
83
+ end
84
+
85
+ shared_examples_for 'a data bag' do
86
+ let(:should_list_data_bag_items) do
87
+ @rest.should_receive(:get_rest).with("data/#{data_bag_dir_name}").once.and_return(
88
+ {
89
+ "aitem" => "http://opscode.com/achild",
90
+ "bitem" => "http://opscode.com/bchild"
91
+ })
92
+ end
93
+ it 'has /data as a parent' do
94
+ data_bag_dir.parent.should == data_bags_dir
95
+ end
96
+ it 'is a directory' do
97
+ should_list_data_bags
98
+ data_bag_dir.dir?.should be_true
99
+ end
100
+ it 'exists' do
101
+ should_list_data_bags
102
+ data_bag_dir.exists?.should be_true
103
+ end
104
+ it 'has correct name' do
105
+ data_bag_dir.name.should == data_bag_dir_name
106
+ end
107
+ it 'has correct path' do
108
+ data_bag_dir.path.should == "/data_bags/#{data_bag_dir_name}"
109
+ end
110
+ it 'has correct path_for_printing' do
111
+ data_bag_dir.path_for_printing.should == "remote/data_bags/#{data_bag_dir_name}"
112
+ end
113
+ it 'has correct children' do
114
+ should_list_data_bag_items
115
+ data_bag_dir.children.map { |child| child.name }.should =~ %w(aitem.json bitem.json)
116
+ end
117
+ it 'can have json files as children' do
118
+ data_bag_dir.can_have_child?('blah.json', false).should be_true
119
+ end
120
+ it 'cannot have non-json files as children' do
121
+ data_bag_dir.can_have_child?('blah', false).should be_false
122
+ end
123
+ it 'cannot have directories as children' do
124
+ data_bag_dir.can_have_child?('blah', true).should be_false
125
+ data_bag_dir.can_have_child?('blah.json', true).should be_false
126
+ end
127
+ context 'aitem from data_bag.children' do
128
+ let(:data_bag_item) do
129
+ should_list_data_bag_items
130
+ data_bag_dir.children.select { |child| child.name == 'aitem.json' }.first
131
+ end
132
+ let(:data_bag_item_short_name) { 'aitem' }
133
+ let(:data_bag_item_name) { 'aitem.json' }
134
+ it_behaves_like 'a data bag item'
135
+ end
136
+ context 'data_bag.child(aitem)' do
137
+ let(:data_bag_item) { data_bag_dir.child('aitem.json') }
138
+ let(:data_bag_item_short_name) { 'aitem' }
139
+ let(:data_bag_item_name) { 'aitem.json' }
140
+ it_behaves_like 'a data bag item'
141
+ end
142
+ context 'nonexistent child()' do
143
+ let(:nonexistent_child) { data_bag_dir.child('blah.json') }
144
+ it 'has correct parent, name, path and path_for_printing' do
145
+ nonexistent_child.parent.should == data_bag_dir
146
+ nonexistent_child.name.should == "blah.json"
147
+ nonexistent_child.path.should == "/data_bags/#{data_bag_dir_name}/blah.json"
148
+ nonexistent_child.path_for_printing.should == "remote/data_bags/#{data_bag_dir_name}/blah.json"
149
+ end
150
+ it 'does not exist' do
151
+ should_list_data_bag_items
152
+ nonexistent_child.exists?.should be_false
153
+ end
154
+ it 'is not a directory' do
155
+ nonexistent_child.dir?.should be_false
156
+ end
157
+ it 'read returns NotFoundError' do
158
+ @rest.should_receive(:get_rest).with("data/#{data_bag_dir_name}/blah/environments/env").once.and_raise(Net::HTTPServerException.new(nil,Net::HTTPResponse.new(nil,'404',nil)))
159
+ expect { nonexistent_child.read }.to raise_error(ChefFS::FileSystem::NotFoundError)
160
+ end
161
+ end
162
+ end
163
+
164
+ context 'achild from data_bags.children' do
165
+ let(:data_bag_dir) do
166
+ should_list_data_bags
167
+ data_bags_dir.children.select { |child| child.name == 'achild' }.first
168
+ end
169
+ let(:data_bag_dir_name) { 'achild' }
170
+ it_behaves_like 'a data bag'
171
+ end
172
+
173
+ context 'data_bags.child(achild)' do
174
+ let(:data_bag_dir) do
175
+ data_bags_dir.child('achild')
176
+ end
177
+ let(:data_bag_dir_name) { 'achild' }
178
+ it_behaves_like 'a data bag'
179
+ end
180
+
181
+ context 'nonexistent child()' do
182
+ let(:nonexistent_child) { data_bags_dir.child('blah') }
183
+ it 'has correct parent, name, path and path_for_printing' do
184
+ nonexistent_child.parent.should == data_bags_dir
185
+ nonexistent_child.name.should == "blah"
186
+ nonexistent_child.path.should == "/data_bags/blah"
187
+ nonexistent_child.path_for_printing.should == "remote/data_bags/blah"
188
+ end
189
+ it 'does not exist' do
190
+ should_list_data_bags
191
+ nonexistent_child.exists?.should be_false
192
+ end
193
+ it 'is not a directory' do
194
+ should_list_data_bags
195
+ nonexistent_child.dir?.should be_false
196
+ end
197
+ it 'read returns NotFoundError' do
198
+ expect { nonexistent_child.read }.to raise_error(ChefFS::FileSystem::NotFoundError)
199
+ end
200
+ end
201
+
202
+ end
@@ -25,24 +25,30 @@ module FileSystemSupport
25
25
  def add_child(child)
26
26
  @children.push(child)
27
27
  end
28
+ def can_have_child?(name, is_dir)
29
+ root.cannot_be_in_regex ? (name !~ root.cannot_be_in_regex) : true
30
+ end
28
31
  end
29
32
 
30
33
  class MemoryRoot < MemoryDir
31
- def initialize(pretty_name)
34
+ def initialize(pretty_name, cannot_be_in_regex = nil)
32
35
  super('', nil)
33
36
  @pretty_name = pretty_name
37
+ @cannot_be_in_regex = cannot_be_in_regex
34
38
  end
35
39
 
40
+ attr_reader :cannot_be_in_regex
41
+
36
42
  def path_for_printing
37
43
  @pretty_name
38
44
  end
39
45
  end
40
46
 
41
- def memory_fs(pretty_name, value)
47
+ def memory_fs(pretty_name, value, cannot_be_in_regex = nil)
42
48
  if !value.is_a?(Hash)
43
49
  raise "memory_fs() must take a Hash"
44
50
  end
45
- dir = MemoryRoot.new(pretty_name)
51
+ dir = MemoryRoot.new(pretty_name, cannot_be_in_regex)
46
52
  value.each do |key, child|
47
53
  dir.add_child(memory_fs_value(child, key.to_s, dir))
48
54
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-essentials
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: '0.2'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-26 00:00:00.000000000Z
12
+ date: 2012-04-28 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: Universal knife verbs that work with your Chef repository
15
15
  email: jkeiser@opscode.com
@@ -30,6 +30,8 @@ files:
30
30
  - lib/chef_fs/file_pattern.rb
31
31
  - lib/chef_fs/file_system/base_fs_dir.rb
32
32
  - lib/chef_fs/file_system/base_fs_object.rb
33
+ - lib/chef_fs/file_system/chef_repository_file_system_entry.rb
34
+ - lib/chef_fs/file_system/chef_repository_file_system_root_dir.rb
33
35
  - lib/chef_fs/file_system/chef_server_root_dir.rb
34
36
  - lib/chef_fs/file_system/cookbook_dir.rb
35
37
  - lib/chef_fs/file_system/cookbook_file.rb
@@ -40,7 +42,7 @@ files:
40
42
  - lib/chef_fs/file_system/file_system_entry.rb
41
43
  - lib/chef_fs/file_system/file_system_root_dir.rb
42
44
  - lib/chef_fs/file_system/nonexistent_fs_object.rb
43
- - lib/chef_fs/file_system/not_found_exception.rb
45
+ - lib/chef_fs/file_system/not_found_error.rb
44
46
  - lib/chef_fs/file_system/rest_list_dir.rb
45
47
  - lib/chef_fs/file_system/rest_list_entry.rb
46
48
  - lib/chef_fs/file_system.rb
@@ -50,6 +52,9 @@ files:
50
52
  - lib/chef_fs.rb
51
53
  - spec/chef_fs/diff_spec.rb
52
54
  - spec/chef_fs/file_pattern_spec.rb
55
+ - spec/chef_fs/file_system/chef_server_root_dir_spec.rb
56
+ - spec/chef_fs/file_system/cookbooks_dir_spec.rb
57
+ - spec/chef_fs/file_system/data_bags_dir_spec.rb
53
58
  - spec/chef_fs/file_system_spec.rb
54
59
  - spec/support/file_system_support.rb
55
60
  homepage: http://www.opscode.com
@@ -1,12 +0,0 @@
1
- module ChefFS
2
- module FileSystem
3
- class NotFoundException < Exception
4
- def initialize(other_exception)
5
- super(other_exception.respond_to?(:message) ? other_exception.message : message)
6
- @exception = other_exception
7
- end
8
-
9
- attr_reader :exception
10
- end
11
- end
12
- end