summaryrefslogtreecommitdiff
path: root/spec/unit/chef_fs
diff options
context:
space:
mode:
authorHo-Sheng Hsiao <hosh@opscode.com>2013-02-12 17:39:28 -0800
committerJohn Keiser <jkeiser@opscode.com>2013-06-07 13:12:26 -0700
commit49495b1974cd6c7eb0d258e605b5111b2b2a730b (patch)
tree1a01d9502a748369ce7a80bac21d1abc47ce9aa1 /spec/unit/chef_fs
parentc9d895a63226044729e801b097548c3ae1d3da65 (diff)
downloadchef-49495b1974cd6c7eb0d258e605b5111b2b2a730b.tar.gz
[SPEC] Added more versioned cookbooks tests
Diffstat (limited to 'spec/unit/chef_fs')
-rw-r--r--spec/unit/chef_fs/file_system/cookbook_dir_spec.rb35
-rw-r--r--spec/unit/chef_fs/file_system/cookbooks_dir_spec.rb43
2 files changed, 70 insertions, 8 deletions
diff --git a/spec/unit/chef_fs/file_system/cookbook_dir_spec.rb b/spec/unit/chef_fs/file_system/cookbook_dir_spec.rb
index a23b60b610..e10d198a2f 100644
--- a/spec/unit/chef_fs/file_system/cookbook_dir_spec.rb
+++ b/spec/unit/chef_fs/file_system/cookbook_dir_spec.rb
@@ -544,4 +544,39 @@ describe Chef::ChefFS::FileSystem::CookbookDir do
expect { nonexistent_child.read }.to raise_error(Chef::ChefFS::FileSystem::NotFoundError)
end
end
+
+ describe 'VALID_VERSIONED_COOKBOOK_NAME' do
+ subject { valid_versioned_cookbook_name.match(cookbook_name) }
+ let(:valid_versioned_cookbook_name) { Chef::ChefFS::FileSystem::CookbookDir::VALID_VERSIONED_COOKBOOK_NAME }
+
+ def self.should_accept(_cookbook_name)
+ context "with a cookbook name of '#{_cookbook_name}'" do
+ let(:cookbook_name) { _cookbook_name }
+ it 'should accept' do
+ should_not be_nil
+ end
+ end
+ end
+
+ def self.should_reject(_cookbook_name)
+ context "with a cookbook name of '#{_cookbook_name}'" do
+ let(:cookbook_name) { _cookbook_name }
+ it 'should reject' do
+ should be_nil
+ end
+ end
+ end
+
+ should_accept 'apt-1.8.4'
+ should_accept 'APT-1.8.4'
+ should_accept 'apt-100.83.4'
+ should_accept 'apt-2.0.0-1.8.4'
+ should_accept 'apt---1.8.4'
+
+ should_reject 'apt'
+ should_reject 'apt-1'
+ should_reject 'apt-1.2'
+ should_reject 'apt-1.2.x'
+
+ end
end
diff --git a/spec/unit/chef_fs/file_system/cookbooks_dir_spec.rb b/spec/unit/chef_fs/file_system/cookbooks_dir_spec.rb
index c689cd6983..7b60fe704c 100644
--- a/spec/unit/chef_fs/file_system/cookbooks_dir_spec.rb
+++ b/spec/unit/chef_fs/file_system/cookbooks_dir_spec.rb
@@ -52,6 +52,13 @@ describe Chef::ChefFS::FileSystem::CookbooksDir do
let(:rest) { double 'rest' }
before(:each) { Chef::REST.stub(:new).with('url','username','key') { rest } }
+ def self.with_versioned_cookbooks
+ before(:each) { Chef::Config[:versioned_cookbooks] = true }
+ after(:each) { Chef::Config[:versioned_cookbooks] = false }
+
+ let(:api_url) { 'cookbooks/?num_versions=all' }
+ end
+
it 'has / as parent' do
cookbooks_dir.parent.should == root_dir
end
@@ -82,11 +89,34 @@ describe Chef::ChefFS::FileSystem::CookbooksDir do
end
describe '#can_have_child?' do
- it 'can have directories as children' do
- cookbooks_dir.can_have_child?('blah', true).should be_true
+ subject { cookbooks_dir.can_have_child? cookbook_name, is_dir? }
+
+ let(:cookbook_name) { 'blah' }
+ let(:is_dir?) { true }
+
+ # /cookbooks should contain only directories
+ context 'when child is a directory' do
+ let(:is_dir?) { true }
+ it { should be_true }
+ end
+
+ context 'when child is a file' do
+ let(:is_dir?) { false }
+ it { should be_false }
end
- it 'cannot have files as children' do
- cookbooks_dir.can_have_child?('blah', false).should be_false
+
+ context 'with versioned cookbooks' do
+ with_versioned_cookbooks
+
+ context 'when name conforms to <cookbook_name>-<verson>' do
+ let(:cookbook_name) { 'apt-1.8.4' }
+ it { should be_true }
+ end
+
+ context 'when name does not conform to <cookbook_name>-<version>' do
+ let(:cookbook_name) { 'apt' }
+ it { should be_false }
+ end
end
end
@@ -99,10 +129,7 @@ describe Chef::ChefFS::FileSystem::CookbooksDir do
let(:versions) { subject.map(&:version) }
context 'with versioned cookbooks' do
- before(:each) { Chef::Config[:versioned_cookbooks] = true }
- after(:each) { Chef::Config[:versioned_cookbooks] = false }
-
- let(:api_url) { 'cookbooks/?num_versions=all' }
+ with_versioned_cookbooks
it 'should return all versions of cookbooks in <cookbook_name>-<version> format' do
entity_names.should include('achild-2.0.0')